Tab space in Markdown

2020-02-28 18:15发布

问题:

I want to use one/multiple Tab space in Markdown. I used, "    &nbsp", which is working. But if i want to use multiple Tab space, then MarkDown Document will not look good.

I wanted to use like this below,

Main Topic
*Tabspace* Subtopic1
*Tabspace**Tabspace* Some Points for subtopic1
*Tabspace* Subtopic2
*Tabspace**Tabspace* Some Points for subtopic2 

Actual look should be

Main Topic
    Subtopic1
        Some Points for subtopic1
     Subtopic2
        Some Points for subtopic2

Any other alternative for &nbsp

回答1:

Use non-breaking spaces

In Markdown, as any markup languages, the tab space collapses to a single space. Also, several consecutive horizontal whitespace (e.g. spaces, tabs) collapse to a single space or they are removed from the beginning of a paragraph.

Instead of a tab space you must use several non-breaking spaces:
"a space character that prevents consecutive whitespace characters from collapsing into a single space, and also prevents an automatic line break at its position".

Example

   This line uses     non-breaking     spaces in many places; they    are not   collapsed.
This line uses many consecutive spaces in many places; they are all collapsed.

The beauty of this solution is that you don't need to use any code in your Markdown document (in HTML you must use  ).

How to introduce a non-breaking space?

  • In macOS, you need to press ⌥ Opt+Space
  • In Windows, sometimes work Alt+0+1+6+0 or Alt+2+5+5
  • In many commercial software Ctrl+Space

Solution to the question example

Main Topic

    Subtopic1
        Some Points for subtopic1
        Some Points for subtopic1
        Some Points for subtopic1

    Subtopic2

    Subtopic3
        Some Points for subtopic3
        Some Points for subtopic3
        Some Points for subtopic3

Warning
Copy and paste the previous example could not work because sometimes the system change non-breaking spaces to normal spaces in a copy-paste operation :‑(.



回答2:

In short, no, unless nested in a list.

In Markdown, code blocks are designated by indentation. Markdown provides no way to enable/disable that feature. Therefore, by design, you cannot have your (non-code-block) content indented.

Of course, there is one exception. Nested list items need to be indented. So, if your content is in a list and at least the first level is not indented, then, yes, this is possible:

* Main Topic
    * Subtopic1

        Some Points for subtopic1

    * Subtopic2

        Some Points for subtopic2

First, notice that the first line is a list item (* Main Topic). Then all the nested items are indented at least one level. The final level are not list items (although they could be) as a list item can contain paragraphs. However, all other levels must be list items as only list items can contain other nested levels.

The above will render as follows:

  • Main Topic

    • Subtopic1

      Some Points for subtopic1

    • Subtopic2

      Some Points for subtopic2