textile / php-textile

Textile markup language parser for PHP
https://textile-lang.com
Other
216 stars 44 forks source link

Allow indication of language for code blocks (esp. inline) #96

Closed netcarver closed 5 years ago

netcarver commented 11 years ago

It would be useful to allow some kind of language markup on code blocks to better support syntax highlighting.

bc. and bc.. 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...

bc(php). echo ...

...into textile would lead to...

<pre class="php"><code>echo...

...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?

gocom commented 11 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.

netcarver commented 11 years ago

@gocom Your comment and linked example triggers various thoughts...

netcarver commented 11 years ago

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.

netcarver commented 11 years ago

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.

philwareham commented 8 years ago

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>
netcarver commented 8 years ago

@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.

philwareham commented 8 years ago

@netcarver works great for me, thanks!

netcarver commented 8 years ago

@philwareham Thanks for testing. Do you anticipate any call for this on inline code elements?

philwareham commented 8 years ago

I guess it's always good to have the option available for inline too, if it's not too much trouble to implement.

netcarver commented 8 years ago

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.

philwareham commented 8 years ago

No worries. It's edge case stuff really.

netcarver commented 8 years ago

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.