Closed netcarver closed 5 years ago
Unless the code block is in different language? But, yep, that would look fine.
The issue with the raw class isn't typing, but the fact that you can't use it in strict mode. So there should be something like this.
In TXP.com forum code we extended Textile and used the first line for the language identifier GitHub style, but if we can get an actual attribute to Textile that can handle that, then more the merrier.
The language attribute should be fine, I believe. Altho, it will remove the ability to use language for code blocks.
@gocom Your comment and linked example triggers various thoughts...
bc(prettyprint)[php]. echo...
but it isn't very pretty. So...public function setCodeClass($class)
that automatically applies a common class to all code blocks OR ...Ah, strict mode. Ok that kills combination with classes anyway so we'd have to allow a very limited [lang]
marker into strict mode if we did go with this idea.
I got my example above slightly wrong. The W3 spec says it is to go on the code
element while I showed it on the pre
element. So...
bc[php]. echo "Hello world!";
...would give...
<pre><code class="language-php">echo...
...if we follow the spec (which is merely a suggestion anyway.) Doing it like this isn't going to be compatible with every syntax highlighter so we should either reserve it in Textile's syntax but hand the implementation off to a plugin subsystem or close the issue.
It would be really handy to revisit this issue and allow for classnames to be applied to the inner code
tag. Basically using Textile with a highlighter such as Prism is not possible right now.
Don't hardcode it to use any predefined language-*
prefix either - let the user decide this.
So, as an example, using:
bc(line-numbers)[language-markup]. some code
Would render:
<pre class="line-numbers"><code class="language-markup">some code</code></pre>
@philwareham Just pushed a test branch that has this feature in it. Please try out the issue-96 branch and let me know if it does what you need.
@netcarver works great for me, thanks!
@philwareham Thanks for testing. Do you anticipate any call for this on inline code elements?
I guess it's always good to have the option available for inline too, if it's not too much trouble to implement.
Looking at the source for handling the inline code spans - I'm inclined to leave it to a later version unless there is demand for it.
No worries. It's edge case stuff really.
I've added the "Breaks backwards compatibility" label as this change will cause a small variation in the generated output if anyone happens to be using the language attributes on a block code element.
It would be useful to allow some kind of language markup on code blocks to better support syntax highlighting.
bc.
andbc..
already support class, id, style and language attributes but inline code@...@
has no support for any of these. In addition, the W3 spec suggest the use of classes named after the programming language but prefixed with "language-" be used on the<code>
elements.Currently typing...
...into textile would lead to...
...which doesn't follow this suggestion. In keeping with textile's aim of trying to reduce keystrokes, perhaps we need a new convention for 'language tagging' of code blocks.
Should we override the use of the existing language attribute marker for code blocks or do something different again? Ideas anyone?