Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

break long lines in markdown code

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.

question from:https://stackoverflow.com/questions/19985235/break-long-lines-in-markdown-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 places at the bottom of the readme.

Also, this metgod 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!)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...