dprint / dprint-plugin-markdown

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

Escaping a pipe in markdown table returns different result since 0.17.3 #117

Closed kachick closed 3 months ago

kachick commented 3 months ago

Description

Since dprint-plugin-markdown-0.17.3, escaping a pipe in a markdown table returns a different result. Additionally, it will also generate different reports between check and fmt.

Is this an intentional change?

Expected behavior

  1. fmt keeps same rendering result in GFM
  2. Even though changing the behaviors, I expect dprint fmt to return the same result as dprint check reports.

Logs

Tested with dprint 0.45.1 and 0.47.2. And markdown-0.17.2, markdown-0.17.3, markdown-0.17.4

> dprint --version
dprint 0.45.1

Target markdown file

| f\|oo  |
| ------ |
| b `\|` az |
| b **\|** im |
| `command \| filter` |

It interprets as below in GitHub

f\ oo
b \| az
b | im
command \| filter

0.17.2 fmt result does not affect rendering result

f\ oo
b \| az
b | im
command \| filter

0.17.3 fmt changes the rendering result

f\ oo
b `
b | im
`command

Appendix

Reproduction Script for 0.17.2 ```bash cd "$(mktemp --directory)" cat <<'JSON' > ./dprint.json { "markdown": {}, "plugins": [ "https://plugins.dprint.dev/markdown-0.17.2.wasm" ] } JSON mdtable="$(mktemp --suffix=.md --tmpdir="$PWD")" cat <<'MARKDOWN' > "$mdtable" | f\|oo | | ------ | | b `\|` az | | b **\|** im | | `command \| filter` | MARKDOWN dprint check dprint fmt cat "$mdtable" ``` check result ```console > dprint check from /tmp/tmp.sT0fsTwBE7/tmp.E2tDbfiEg5.md: 1|-|·f\|oo··| 2|-|·------·| 3|-|·b·`\|`·az·| 4|-|·b·**\|**·im·| 1 |+|·f\|oo···············| 2 |+|·-------------------·| 3 |+|·b·`\|`·az···········| 4 |+|·b·**\|**·im·········| 5 5| |·`command·\|·filter`·| -- Found 1 not formatted file. ``` fmt result ```console > dprint fmt Formatted 1 file. > cat "$mdtable" | f\|oo | | ------------------- | | b `\|` az | | b **\|** im | | `command \| filter` | ```
Reproduction Script for 0.17.3 ```bash cd "$(mktemp --directory)" cat <<'JSON' > ./dprint.json { "markdown": {}, "plugins": [ "https://plugins.dprint.dev/markdown-0.17.3.wasm" ] } JSON mdtable="$(mktemp --suffix=.md --tmpdir="$PWD")" cat <<'MARKDOWN' > "$mdtable" | f\|oo | | ------ | | b `\|` az | | b **\|** im | | `command \| filter` | MARKDOWN dprint check dprint fmt cat "$mdtable" ``` check result ```console > dprint check from /tmp/tmp.talxYkpfIp/tmp.zDeiKDP0rM.md: 1|-|·f\|oo··| 2|-|·------·| 3|-|·b·`\|`·az·| 4|-|·b·**\|**·im·| 5|-|·`command·\|·filter`·| 1 |+|·f\|oo··············| 2 |+|·------------------·| 3 |+|·b·`|`·az···········| 4 |+|·b·**\|**·im········| 5 |+|·`command·|·filter`·| -- Found 1 not formatted file. ``` fmt result ```console > dprint fmt Formatted 1 file. > cat tmp.zDeiKDP0rM.md | f\|oo | | ----------- | | b ` | | b **\|** im | | `command | ```

Links

kachick commented 3 months ago

Thank you! :zap:

dsherret commented 3 months ago

And thanks for reporting! I upgraded the markdown parser so there was some change in behaviour I didn't notice.