syntax-tree / mdast-util-mdx-jsx

mdast extension to parse and serialize MDX JSX
https://unifiedjs.com
MIT License
24 stars 5 forks source link

Extraneous indent for mdxJsxTextElements during stringify #9

Closed tonywu6 closed 1 year ago

tonywu6 commented 1 year ago

Initial checklist

Affected packages and versions

mdast-util-mdx-jsx@2.1.3, remark-mdx@2.3.0, remark-parse@10.0.2, remark-stringify@10.0.3

Link to runnable example

https://codesandbox.io/p/sandbox/nostalgic-cloud-fdvyzk

Steps to reproduce

Maybe introduced here?

https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/10a502c81764206f031edd71d9799a4da7e3f3d2/lib/index.js#L529

With default options, parse and then stringify a MDX document containing a mdxJsxTextElement nested inside a mdxJsxFlowElement, for example:

<div>
    Lorem ipsum <span>dolor</span> sit amet
</div>

Expected behavior

Input and output should be the same

Actual behavior

Inline elements have extra whitespace in front of them

<div>
    Lorem ipsum   <span>dolor</span> sit amet
</div>

Affected runtime and version

node@16.20

Affected package manager and version

pnpm@8.5.0

Affected OS and version

macOS Ventura 13.1

Build and bundle tools

No response

wooorm commented 1 year ago

inferDepth only handles flow elements, not texts: https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/10a502c81764206f031edd71d9799a4da7e3f3d2/lib/index.js#L732.

wooorm commented 1 year ago

Can repro in this project, thanks!

wooorm commented 1 year ago

Thanks for the report, released!