CalMlynarczyk
CalMlynarczyk

Reputation: 705

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

Upvotes: 29

Views: 47272

Answers (4)

aratno
aratno

Reputation: 626

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.

Upvotes: 51

ubz8a
ubz8a

Reputation: 7

Add an empty code block




Depending on how mark up is rendered you can see it but it definitely has no text

Upvotes: -5

nd34567s32e
nd34567s32e

Reputation: 176

In some markdown flavors, you may end the line with two or more spaces which will produce a newline.

Upvotes: 15

Bart Kiers
Bart Kiers

Reputation: 170148

I wanted to know if there is a way in Markdown to mimic a newline in a single-line text input field ...

AFAIK, no.

There are various flavors of Markdown, of course, but there's no such feature in the original Markdown syntax.

Upvotes: 4

Related Questions