Respec: markdown expects tabs instead of spaces for nested lists

Created on 4 Dec 2019  ·  10Comments  ·  Source: w3c/respec

Using respec with markdown, it seems like nested lists don't work if they aren't using tabs.

* this
  - is
    + a nested list :)
  • this

    • is

    • a nested list :)

bug

Most helpful comment

Yes... so this is where it starts to be confusing:

ReSpec will do its best to correctly format the markdown.

This part is a total mess and no one understands what it really does. We should ultimately remove this, please don't depend on it. Sorry 🙇‍♀️

Please remember that markdown is supposed to be placed flush against the left margin - but we do support padded sections.

The "support for padded markdown" infers the base indentation from the very first line of markdown - which is <section> in your example (as markdown includes some HTML support). It then tries its best to remove the base indentation everywhere, which is why the list goes wrong.

So the answer is: If you indent something, please indent everything.

All 10 comments

Yeah, that's odd... we might need to look into that.

@mimoo, can you provide us with the exact markdown you are using?

Here's an example:

<!DOCTYPE html>
<html>

<head>
  <meta charset='utf-8'>
  <title>nopeBFT Specification</title>
  <script src='https://www.w3.org/Tools/respec/respec-w3c-common' class='remove'></script>
  <script class='remove'>
    var respecConfig = {
      specStatus: "base",
      editors: [{
        name: "nope",
        url: "https://www.nope.com",
      }],
      github: "https://github.com/nope/nope",
      shortName: "nope",
      format: "markdown",
    };
  </script>
</head>

<body>
  <section id="abstract">
      Things
  </section>

* Things
  * thing2
    * thing3

another:

* Things
  - Things
    + things

</body>

</html>

maybe the problem comes from this function removing the padding: https://github.com/w3c/respec/blob/develop/src/core/markdown.js#L148

tracking the initial commit, the message doesn't seem to really indicate why this was added: https://github.com/w3c/respec/commit/3e88cd7ccb55fcef7bfed355aaf3162a2f1a821b

indeed, converting all spaces with tabs fix the issue. In the mean time this script might be useful to people encountering the same issue:

import sys
f = open(sys.argv[1])
toWrite = ""
for line in f.readlines():
    # two spaces -> four spaces
    number_space = len(line) - len(line.lstrip(" "))
    line = "\t" * (number_space//2) + line[number_space:]
print(toWrite)

some editors probably do this too :p

Here's an example:

The indentation is wrong there. It starts with 2-space indented section and then zero-indented markdown. Adding indentation fixes the issue.

this is what the doc says:

ReSpec will do its best to correctly format the markdown. Please remember that markdown is supposed to be placed flush against the left margin - but we do support padded sections.

Yes... so this is where it starts to be confusing:

ReSpec will do its best to correctly format the markdown.

This part is a total mess and no one understands what it really does. We should ultimately remove this, please don't depend on it. Sorry 🙇‍♀️

Please remember that markdown is supposed to be placed flush against the left margin - but we do support padded sections.

The "support for padded markdown" infers the base indentation from the very first line of markdown - which is <section> in your example (as markdown includes some HTML support). It then tries its best to remove the base indentation everywhere, which is why the list goes wrong.

So the answer is: If you indent something, please indent everything.

Agree... if you use markdown, please treat the whole document as markdown. Mixing and matching is on per section will confuse the markdown parser... most of the time, we literally just take the body element's content and give it to marked.js, and just print whatever comes out. We can't really do any special handling apart from that.

closing as "won't fix" given the above discussion.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrea-perego picture andrea-perego  ·  3Comments

xfq picture xfq  ·  4Comments

marcoscaceres picture marcoscaceres  ·  3Comments

deniak picture deniak  ·  5Comments

saschanaz picture saschanaz  ·  3Comments