Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

break long lines in markdown code

Tags:

markdown

I'm using the original-flavored markdown as described here.

I'm wondering if it's possible to break a long line in markdown code while resulting in no syntactic effect. (In other languages, for instance shell scripts and C, \ would be used to continue onto the next line.) I'm asking this because newlines sometimes break the syntax, as in

[StackOverflow] (http://stackoverflow.com) 

This would end up as "[StackOverflow] (http://stackoverflow.com)" in the actual html rather than a hyperlink, since newline is interpreted as whitespace, and whitespace is not allowed between ] and ( in the [text](url) syntax for links.

like image 934
4ae1e1 Avatar asked Nov 14 '13 18:11

4ae1e1


People also ask

How do you break a line in Markdown?

To create a line break or new line ( <br> ), end a line with two or more spaces, and then type return. This is the first line.

How do you insert multiple line breaks in Markdown?

First way, using <br> html tag inside markdown content. Second way, use two spaces with entering or enter keystroke in markdown content adds link break. The third way, use a hyphen( - ) in markdown content.

How do I leave a blank line in Markdown?

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

How do you insert a line in Markdown?

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


2 Answers

If you'd like to have line breaks in the code, then, as comments tell, use the line breaks inside either the text part, or inside the url part: you can actually do this

[StackOverflow]( http://stackoverflow.com) 

And while the result would have the extra whitespace inside the href, it would still work, so no worries. This works also for spreading long links over multiple lines

[StackOverflow interesting discussion](     http://stackoverflow.com/this/discussion/has/a/very/ very/very/very/long/long/long/title/title/title 

Be sure to not let any leading whitespace on lines that start within the URL (here the last line). (only the first line break works with GitHub-flavored markdown, because GitHub treats the line breaks as whitespace).

However, if the goal is to make links more readable, I would recommend to use the link references, so you could place the actual hrefs anywhere in your document and have short and readable link titles in the text:

[StackOverflow][]  [StackOverflow]: http://stackoverflow.com 

or

[StackOverflow][1]  [1]: http://stackoverflow.com 

Note that you can place the reference anywhere: it is often rather readable and easy to maintain when all the references are placed at the bottom of the readme.

Also, this method would allow you to add title attribute to links, if you'd need them:

[StackOverflow][]  [StackOverflow]: http://stackoverflow.com (Here is this link's title!) 
like image 200
kizu Avatar answered Oct 21 '22 12:10

kizu


Adding on to @kizu's answer, another type of link is a "shortcut reference link", which is even fewer characters, and in my opinion, looks nicer.

They look like this:

Here's a link to [Stack Overflow]. You should be able to find an answer there. If not, let me know.  [Stack Overflow]: https://stackoverflow.com  For additional information, check out [this answer].  [this answer]: https://stackoverflow.com/a/59956334/384954 

renders as follows

Here's a link to Stack Overflow. You should be able to find an answer there. If not, let me know.

For additional information, check out this answer.

like image 40
OregonTrail Avatar answered Oct 21 '22 13:10

OregonTrail