szogroup / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

Code in <Style>-Tags is not highlighted as XML when using lang-xml #280

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Steps to reproduce:
1. Style the code as XML (using lang-xml)
2. Use a <Style>-tag containing other XML code

Expected output:
The code inside the <Style> tag is rendered as XML

Current output:
The code inside the <Style> tag is rendered as CSS

See 
http://meta.stackoverflow.com/questions/71649/style-xml-element-in-code-block-me
sses-up-syntax-highlighting-coloring for details.

This behavior is desired when highlighting HTML, but not generally when 
highlighting XML code.

Original issue reported on code.google.com by markus.r...@googlemail.com on 17 Apr 2013 at 1:27

GoogleCodeExporter commented 8 years ago
The reason is that both HTML and XML are parsed using the same lexer:

http://code.google.com/p/google-code-prettify/source/browse/trunk/src/prettify.j
s#1294

which detects <style> and <script> tags inside the markup

Original comment by amroamro...@gmail.com on 22 May 2013 at 12:33

GoogleCodeExporter commented 8 years ago
This becomes a bigger problem when the language is XAML because <Style> tags 
are an important part of this language (and always contain XML). There are many 
posts on Stack Overflow which are not formatted correctly due to this 
behaviour. (And people use this code outside SO too, of course!)

Would it be a good idea to modify prettify.js so that:
  a) lang-xaml is understood as a case for XML parsing
  b) Special tag processing is removed in this case (<Script> is currently not part of the XAML lexicon, but keeping it in too seems anachronistic)?

Alternatively, I'm not sure that keeping this special processing for lang-XML 
in the general case is desirable; perhaps just for lang-html, lang-xhtml, etc.?

Original comment by m.j.wind...@gmail.com on 2 Jul 2015 at 10:36