elliotxx / mdfmt

💡 A Markdown formatter that follow the CommonMark. Like gofmt, but for Markdown.
https://pkg.go.dev/github.com/elliotxx/mdfmt/pkg/md
MIT License
24 stars 4 forks source link

Inline math in tables renders incorrectly #17

Open burgerdev opened 1 year ago

burgerdev commented 1 year ago

Hi @elliotxx,

I'm seeing some unexpected behaviour with Github's inline math inside tables. A minimal example would be

mdfmt << 'EOF'
# Test

The table below should not be mangled.

|         Left | Right |
| -----------: | :---- |
|        short | `foo` |
|        $K_b$ | `bar` |
| longest term | `0`   |
EOF

Output:

# Test

The table below should not be mangled.

|         Left | Right |
| -----------: | :---- |
|        short | `foo` |
|          $K_b$ | `bar` |
| longest term | `0`   |

Note the misalignment in line 4 of the table. Expected output would be the unchanged input (cells still aligned).

This is v0.4.2:

releaseVersion: v0.4.2
gitInfo:
    latestTag: v0.4.2
    commit: 8a49dd084164207a76aac977b9e456a165e71fd4
    treeState: clean
buildInfo:
    goVersion: go1.17.7
    GOOS: linux
    GOARCH: amd64
    numCPU: 2
    compiler: gc
    buildTime: "2022-03-02 07:08:44"

Cheers, Markus