2

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?

0

1 Answer 1

6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.