NoBodyButMe / google-code-prettify

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

C include with <> become invisible #278

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When prettifying C code containing include statements like so:

#include <math.h>

The <math.h> is made invisible.

To solve this, I currently replace all <xxx.h> in the input text with the 
HTML/XML equivalent (-gt, --lt or whatever it is, I can't remember exactly) so 
that the < and > are interpreted as text and not as start and end of a tag.

Can this be fixed in prettify or is it a feature?

Original issue reported on code.google.com by oscarmo...@gmail.com on 13 Apr 2013 at 9:25

GoogleCodeExporter commented 8 years ago
What does your HTML look like?

  <pre>#include <math.h></pre>

is a <pre> with the text "#include " followed by a malformed <math> tag 
regardless of whether prettify is used.

If that was your problem, you can use entities thus

   <pre>#include <math.h></pre>

or use an element whose content is unformatted text

    <xmp>#include <math.h></xmp>

Original comment by mikesamuel@gmail.com on 15 Apr 2013 at 11:12

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Ignore my previous comment.
<xmp> solved it. 
I was using the < > solution before but that is more complicated since you have 
to find the tags and ignore them in comments etc.

Is there a reason this (<xmp>) is not done by default by prettify?

Original comment by oscarmo...@gmail.com on 16 Apr 2013 at 8:39

GoogleCodeExporter commented 8 years ago
xmp is deprecated apparently. I should have mentioned I'm using html5.

Original comment by oscarmo...@gmail.com on 16 Apr 2013 at 8:52

GoogleCodeExporter commented 8 years ago
Prettify takes code in HTML as input and makes it prettier.  There's no real 
way for prettify to find code that hasn't been escaped since the HTML parser 
sees it first, and there's no single way to reverse the DOM that the HTML 
parser will produce from plain text code like the python

    HTML_DOUBLE_QUOTE_ENTITY = """

since prettify will only see a text node like

    HTML_DOUBLE_QUOTE_ENTITY = """

which looks like the beginning of a multi-line string.

It is also a goal for prettify to preserve links and inline formatting elements 
within code.

Since you're using HTML 5, I'm sure you're aware that <math> is a tag that 
starts a foreign MathML sub-tree, so even doing a best effort with your 
particular code would be problematic -- what if someone want's to embed 
equations in code.

Original comment by mikesamuel@gmail.com on 16 Apr 2013 at 6:21