syntax-tree / mdast-util-to-markdown

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

Figure out a way to support tab-size / aligning columns #51

Open wooorm opened 2 years ago

wooorm commented 2 years ago

Initial checklist

Problem

Other programming languages allow using different “tab stops”, e.g., columns of 2, 3, 4, 8 spaces.


Tab stops of 8 don’t work, as everything turns into code:

Paragraph[^fn].

> unindented block quote.

***

>       indented block quotes (💥 turns into code, w/ spaces)

*       indented unordered list (💥 turns into code, w/ spaces)

1.      indented ordered list (💥 turns into code, w/ spaces)
11.     indented ordered list (💥 turns into code)
111.    indented ordered list (fine)

        code 1? (💥 spaces show up)

<section>
        <article>
                HTML.
        </article>
</section>

[^fn]:
        Footnote (💥 turns into code)

Tab stops of 4 work perfectly (although indenting block quotes doesn‘t work):

Paragraph[^fn].

> unindented block quote.

***

>   indented block quotes (⚠️ fine, but becomes complex when adding indented code blocks in block quotes)

*   indented unordered list

1.  indented ordered list
11. indented ordered list
111.    indented ordered list
1111.   indented ordered list
11111.  indented ordered list

    code?

<section>
    <article>
        HTML.
    </article>
</section>

[^fn]:
    Footnote.

Tab stops of 3 don’t work well due to indented code and the locked sizes of footnotes and block quotes.

Paragraph[^fn1][^fn2].

> unindented block quote.

***

>  indented block quotes (⚠️ fine, but becomes complex when adding indented code blocks in block quotes)

*  indented unordered list

1. indented ordered list
11.   indented ordered list
111.  indented ordered list
1111. indented ordered list
11111.   indented ordered list

   code 1? (💥 not enough)

      code 2? (💥 too much, spaces show up)

<section>
   <article>
      HTML.
   </article>
</section>

[^fn1]:
   Footnote 1 (💥 not enough)

[^fn2]:
      Footnote 2 (⚠️ fine, but becomes complex when adding indented code blocks in block quotes)

Finally, tab stops of 2 work really well, assuming you use 4 spaces for footnotes and indented code:

Paragraph[^fn1][^fn2].

> unindented block quote.

* indented unordered list

1.  indented ordered list
11. indented ordered list
111.  indented ordered list
1111. indented ordered list
11111.  indented ordered list

  code 1? (💥 not enough)

    code 2

<section>
  <article>
    HTML.
  </article>
</section>

[^fn1]:
  Footnote.

[^fn2]:
    Footnote.

To summarize, considering constructs:

Concluding, we can drop 8, as it won‘t work. Leaving us with 2, 3, and 4. Given that lists don’t matter and we can ignore HTML, now left with:

3 isn’t great to align things in monospace it seems. And well, it isn’t popular either. So let’s ditch that too. Leaving us with 2 and 4, which both do align as a nice grid.

There is another problem with lists: when they start with indented code. As we’re assuming here that a tab key is used which expands to an X amount of spaces to align, as follows:

*␉asd (one tab indent after the bullet to start the paragraph)
*␉␉qwe (another one to make code)

This actually renders:

(note the included spaces, “part” of the code).

Perhaps lists should, like block quotes, not be indented with a tab either? But just one space? This is quite a change. And a bit related to https://github.com/syntax-tree/mdast-util-to-markdown/issues/48.

Solution

I’m leaning to think that:

Alternatives

-