Please see this issue for the context surrounding this discussion.
I believe it should be possible to syntax highlight indented code. Presently, this does not appear to be possible.
Ideally, somehow, it would be possible to have raw code blocks (indented by tabs or 2+ spaces) and also specify which language should be used for syntax highlighting.
Can you elaborate on what your use case is? I’ve looked back through the linked issue, but I’m not sure what you’re trying to accomplish that you can’t already. Is there some reason you can’t use backticks? Or is there some other reason?
You can still indent fenced code and use as many backticks or tildes as you like, as long as it’s more than 3 and the ending fence has at least as many as the starting one.
Anyhow, markdown processors and their code highlighting modules should support heuristics to guess code languages or settings for the default language outside of the markdown document itself. This should cover most cases and the rest can just use the existing fenced syntax.
One could also adopt the convention to reuse the info-string from fences, but put it into a comment in the first line of the code, using a comment syntax supported by the highlighted language.
I don’t know if I agree with this – the way we do it, indented blocks are for “code” that you don’t want syntax highlighted, and fenced code blocks are for code that does need syntax highlighting.
So it’s a feature from my perspective.
We used to syntax highlight everything by default on Stack Overflow (we still might actually) and that was acceptable since it was a site for programmers. But I doubt it is a good idea at all for a general audience.
Pandoc has a command-line option that allows you to set a default class for all indented code blocks. And I have nothing against implementations adding something like this, but it doesn’t seem like something that should be part of the spec. (Ditto for the initial comment suggestion.)
Surely using a fenced code block without specifying a language should be the proper way to say “I don’t want syntax highlighting”? Anyway, it would be nice to have the ability to enable syntax highlighting for indented code blocks. Perhaps something like this:
Here the language name is indented by 3 spaces and a single backtick, while the code is indented by 4 spaces.
(Maybe highlighting could even be enabled for inline code spans using this syntax: `code`(language), which is quite similar to the link syntax: [text](link).)
In the meantime, there is a workaround for enabling syntax highlighting of indented code. Simply add the backticks and indent by three spaces instead of 4. For example,
Not exactly; sometimes you just want monospace font and it has zip to do with any programming language.
Remember GitHub, a programming source control site essentially invented the 3 backticks. Guess why they invented it?
Anyway I propose this as a helpful rule of thumb, not an ironclad law that must be adhered to under penalty of death, or encoded into the spec, or anything.
@ioquatix, this seems somewhat like a case of the undermentioned:
Fenced code blocks are an improvement in syntax highlighting capability, and I’m surprised that you solely ever encounter a need to indent when using code blocks. You should use fences.
However, note that Stack Exchange has implemented syntax for this: