最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why markdown syntax requires two spaces before n to make a paragraph out of it? - Stack Overflow

programmeradmin2浏览0评论

I use this library to create markdown text editor in a webapp.

All formatting is intuitive, but the line breaks. I don't get, why i have to add double space and then \n to create line break? Is there other markdown => html js parser, which doesn't require this?

I use this library to create markdown text editor in a webapp.

All formatting is intuitive, but the line breaks. I don't get, why i have to add double space and then \n to create line break? Is there other markdown => html js parser, which doesn't require this?

Share Improve this question asked Feb 3, 2016 at 12:34 stkvtflwstkvtflw 13.6k29 gold badges90 silver badges174 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 10

It doesn't require two spaces before a newline to make paragraphs. Paragraphs in Markdown are defined by two consecutive newlines (i.e. there must be a blank line in between the paragraphs). The "two spaces" syntax is for line breaks, i.e. <br> tags.

The reason for the two space rule for line breaks is shown in the documentation (bold mine):

A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line — a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.

The implication of the "one or more consecutive lines of text" rule is that Markdown supports "hard-wrapped" text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type’s "Convert Line Breaks" option) which translate every line break character in a paragraph into a <br /> tag.

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

Yes, this takes a tad more effort to create a <br />, but a simplistic "every line break is a <br />" rule wouldn’t work for Markdown. Markdown’s email-style blockquoting and multi-paragraph list items work best — and look better — when you format them with hard breaks.

发布评论

评论列表(0)

  1. 暂无评论