Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mimic a newline in Markdown

I have an HTML text input <input type="text" /> that users enter a string into. Because it is a text input and not a text area, users can not enter newlines.

Users can enter Markdown elements in the text input for formatting the data when it is re-displayed later. Their options are limited, however, because they can not enter newline characters (ex. headers, lists).

Lastly, users are not allowed to enter HTML elements in the field (for protecting against XSS attacks), so they can not enter <br/> elements into the text input.

I wanted to know if there is a way in Markdown to mimic a newline in a single-line text input field that, when re-displayed as formatted text later, will display as a newline or line break.


Example (assume @cr represents this desired newline tag in Markdown):

Input: #A Header @cr ##A Subheader @cr Some text

Output:

A Header

A Subheader

Some Text

like image 474
CalMlynarczyk Avatar asked Mar 04 '13 22:03

CalMlynarczyk


People also ask

How do I force a newline in Markdown?

According to the Markdown Guide, in order to force a new line, you need to add 2 spaces at the end of the line, followed by the return key.

How do you insert a new line in a Markdown table?

davidsneighbour: A newline in Markdown is created by “2 spaces at the end of the line and a single newline”.

How do you insert multiple line breaks in Markdown?

For an empty line in Markdown, escape a space ( \ ), and then add a new line. Remember: escape a space and escape a new line.

How do I make a horizontal line in Markdown?

You can create a horizontal rule ( <hr /> ) by placing 3 or more hyphens, asterisks, or underscores on a single line by themselves.


1 Answers

Per the Markdown documentation:

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

One  \nTwo  \nThree  \nFour 

Will then render into four separate lines.

Note that between each entry and newline, there are two spaces.

like image 111
aratno Avatar answered Sep 22 '22 22:09

aratno