mdformat icon indicating copy to clipboard operation
mdformat copied to clipboard

image path is falsely patched with `<>` if URL includes `()`, breaks render

Open Borda opened this issue 1 year ago • 6 comments

Describe the bug

context Formating status badges from Azure, just copy paste the provided code by Azure devops

expectation keep it as it is: [![Build Status](https://dev.azure.com/Lightning-AI/lightning/_apis/build/status%2Fpytorch-lightning%20(GPUs)?branchName=master)](https://dev.azure.com/Lightning-AI/lightning/_build/latest?definitionId=24&branchName=master)

bug with added <> it is not rendered as image

[![Build Status](<https://dev.azure.com/Lightning-AI/lightning/_apis/build/status%2Fpytorch-lightning%20(GPUs)?branchName=master>)](https://dev.azure.com/Lightning-AI/lightning/_build/latest?definitionId=24&branchName=master)

Reproduce the bug

using pre-commit hook:

  - repo: https://github.com/executablebooks/mdformat
    rev: 0.7.17
    hooks:
      - id: mdformat

List your environment

No response

Borda avatar Oct 13 '23 00:10 Borda

seems the problem is () in url which is a valid character, based on https://www.w3schools.com/tags/ref_urlencode.ASP but also could be replaced with %28 and %29 and properly recognised for rendering

Borda avatar Oct 13 '23 00:10 Borda

Thanks for the issue!

with added <> it is not rendered as image

This seems to me like a renderer issue. Which renderer do you use? If I copy the link (with angle brackets) to e.g. GitHub's or Gitlab's comment field and press the "Preview" button, both correctly render the image.

The angle brackets should be allowed here.

hukkin avatar Feb 02 '24 11:02 hukkin

This seems to me like a renderer issue. Which renderer do you use?

GitHub preview I guess and maybe PyPI...

Borda avatar Feb 02 '24 12:02 Borda

Link with brackets: render1

Rendered: render2

Works fine on GitHub. If not on PyPI, then that should be a PyPI bug I think.

hukkin avatar Feb 02 '24 12:02 hukkin

I can confirm the issue with the latest version:

$ mdformat --version
mdformat 0.7.17 (mdformat_web: 0.1.0)

$ cat ./edge-case.md
# Edge case

[Split screen](https://en.wikipedia.org/wiki/Split_screen_(video_production))
$ mdformat ./edge-case.md
$ cat ./edge-case.md
# Edge case

[Split screen](<https://en.wikipedia.org/wiki/Split_screen_(video_production)>)

Instead, I would expect mdformat to let the link as-is, or URL-encode the parenthesis as @Borda suggested:

# Edge case

[Split screen](https://en.wikipedia.org/wiki/Split_screen_%28video_production%29)

kdeldycke avatar Apr 21 '24 08:04 kdeldycke