I'm making this a feature-request to implement a solution to the problem described in this question: Why are inline code spans across multiple lines allowed?
From time to time, I see some code formatted using inline code spans like this:
<html>
<head>
<meta charset="utf-8">
<title>I don't know how to format code properly</title>
</head>
<body>
<p>I'm not able to make my code look properly.</p>
<p>Can someone help me? Thanks.</p>
</body>
</html>
As far as I'm aware, there is no valid reason why one should have line breaks inside inline code spans. If your code is more than one line long or not within a sentence, it should be inside code blocks (indent all lines with four spaces):
<html>
<head>
<meta charset="utf-8">
<title>How to format code properly</title>
</head>
<body>
<p>You can format your code by indenting all lines of your code with four spaces.</p>
<p>Select all your code, then click the {} button above the text box.</p>
</body>
</html>
The issue still exists (recent example) and continues to be an annoyance. This is something an automated replacement could easily solve without having to waste people's time to edit these out* (which someone just did for the linked example).
Deduplicator makes the following argument in a comment:
[...] there is a valid use for them: Formatting error messages, which may get more line-breaks, but must keep their original linebreaks and should not be interpreted as formatting...
I don't agree with this, because a code block actually does a better job at preserving line breaks. In fact, a code span does not do its job at all if there are concurrent line breaks:
`This is a line break
2 breaks above`
`This is a line
break
2 breaks above`
Another possible argument for using code spans is that they do not unnecessarily prettify (color-code) parts of the text (e.g. numbers, words starting with an Uppercase letter) when it's not necessarily code, but in those cases <!-- language: none -->
is sufficient to prevent this from happening.
While new users may not know this, a code block with incorrect syntax highlighting is still better than a multi-line code span if the contents span multiple lines. Sometimes the highlighting actually does a good job, especially with stack traces:
Exception in thread "main" java.lang.NullPointerException
at com.example.myproject.Book.getTitle(Book.java:16)
at com.example.myproject.Author.getBookTitles(Author.java:25)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)
Exception in thread "main" java.lang.NullPointerException
at com.example.myproject.Book.getTitle(Book.java:16)
at com.example.myproject.Author.getBookTitles(Author.java:25)
at com.example.myproject.Bootstrap.main(Bootstrap.java:14)
* Assuming the rest of the post is still worth keeping and the author just doesn't know how to format code blocks. The competence of people who can't format code blocks properly is a completely different argument.
<!-- language: none -->
trick is something new users won't know. Even if they by some miracle read the help, they have to click the question mark -> click advanced help -> scroll down the page to Syntax Code Highlighting -> click show more -> scroll to the bottom of the expanded section -> on the last line there it is.Ctrl
K
or press the{}
icon to automatically indent the code you've selected", but I think that's a pretty weak argument against implementing a feature most of us developers are used to on many other platforms. I'd love to see that implemented as well, but I strongly feel the developers that be don't really want to mess with the Markdown parser for whatever reason.<kbb>
to make links look like buttons. In both cases the feature is not being used for its intended purpose.<pre>
tag in the rendered output).<!-- language: none -->
thing, and also somehow help the user indent the code.