syntax-tree / mdast-util-to-markdown

mdast utility to serialize markdown
http://unifiedjs.com
MIT License
100 stars 20 forks source link

Roundtripping three empty lists results in a thematic break #6

Closed wooorm closed 3 years ago

wooorm commented 4 years ago

Subject of the issue

Your environment

n/a

Steps to reproduce

The following uncommon markdown is three empty lists/list items in each other.

+ * -

Expected behavior

🤷‍♂️

Actual behavior

Given that bullet is set to a value that can also be used for a thematic break (- or *), from-markdown will serialize as * * * or - - -, which is then parsed again as a thematic break.

benwoodward commented 4 years ago

What I just experienced is that --- is serialized as ***.

Code:

const mdSyntaxTree = markdownToMdAst(markdown);
console.log(toMarkdown(mdSyntaxTree));

function markdownToMdAst(markdown) {
  const mdAstTree = unified()
    .use(remarkParse)
    .parse(markdown)
  return mdAstTree;
}

Input:

one

---

two

Output:

image

ChristianMurphy commented 4 years ago

@benwoodward what you're describing is different, unrelated, and expected behavior. Both are thematic breaks https://astexplorer.net/#/gist/526a859153287c044491fa011ed08a14/c4ae05f5e409472ddf66386f216bf29a0681be4d

MDAST is an AST, not a CST. Meaning it will preserve structure, it was a thematic break before, it still is a thematic break, but it may not preserve the exact formatting as before (which a CST would).

ChristianMurphy commented 3 years ago

Another example related to this, lists with a thematic break inside also collapse into just a thematic break

- * **
ChristianMurphy commented 3 years ago

Another variation of this

-    -

-
    -    -

compiles to

*   *

*   *   *

which appears to trigger the issue again, even in latest

wooorm commented 3 years ago

Could you make this reproducible? Or is it literally this way in this projects tests? I’m hoping that this was already fixed, because the tests seem to indicate it: https://github.com/syntax-tree/mdast-util-to-markdown/commit/0148aa6e0318116cf5d2102cd8be28486be9d737.

ChristianMurphy commented 3 years ago

https://stackblitz.com/edit/node-dsbc65?file=index.js

wooorm commented 3 years ago

thanks! released too!