dprint / dprint-plugin-markdown

Markdown code formatting plugin for dprint.
MIT License
29 stars 9 forks source link

Issue formatting Rust Links #72

Closed rachfop closed 1 year ago

rachfop commented 1 year ago

Describe the bug When using a Rust link as a footnote (described below), the formatter believes that it is formatted incorrectly. I believe it has to do with the [T] – but that is a valid URL.

dprint-plugin-markdown version: x.x.x

Input Code

[1]: https://doc.rust-lang.org/std/vec/struct.Vec.html
[2]: https://doc.rust-lang.org/std/vec/struct.Vec.html#deref-methods-[T]

Expected Output

[1]: https://doc.rust-lang.org/std/vec/struct.Vec.html
[2]: https://doc.rust-lang.org/std/vec/struct.Vec.html#deref-methods-[T]

Actual Output

: Line 25, column 70: Unexpected open bracket parsing link reference definition link.

  .html#deref-methods-[T]
mgeisler commented 1 year ago

Hey @rachfop, funny, I just ran into this myself today while trying to format https://github.com/google/comprehensive-rust :smile:

dsherret commented 1 year ago

Yeah, it's the [T].

mgeisler commented 1 year ago

Hey @dsherret,

I tried to read (eh, skim) of the CommonMark spec and it only mentions percent-encoding briefly:

Note that not every feature of the HTML samples is mandated by the spec. For example, the spec says what counts as a link destination, but it doesn’t mandate that non-ASCII characters in the URL be percent-encoded. To use the automatic tests, implementers will need to provide a renderer that conforms to the expectations of the spec examples (percent-encoding non-ASCII characters in URLs). But a conforming implementation can use a different renderer and may choose not to percent-encode non-ASCII characters in URLs.

I think this says files with both encoded and non-encoded URLs are okay in the sense that they're valid CommonMark files (and further, a "renderer" should probably percent-encode things like [T] in a URL so that it's useful for people).

Based on this, I think it would be great if the plugin could accept and pretty-print URLs that are not percent-encoded.

dsherret commented 1 year ago

I had a condition that would error when the link reference definition had a [ in it in order to notify me about unexpected scenarios. I just removed it in #73.

dsherret commented 1 year ago

This is fixed now in 0.15.2. I also opened a downstream PR in Deno with this fix https://github.com/denoland/deno/pull/17352

rachfop commented 1 year ago

Thank you!

mgeisler commented 1 year ago

Wow, that was fast!