Open source syntax syntax?

I am looking for an open source tool, a cross platform (at least for Windows and Linux) to take some code (C ++, but several languages ​​would be nice) and get the correct XHTML representation of this code, with syntax highlighting.

Ideally, XHTML should just wrap the code with tags <span>and <div>different classes so that I can provide CSS code and change the color, but this is not necessary.

Does anyone know about such an application?

+3
source share
8 answers

I can recommend Pygments . It works easily and supports many languages. He does what you need, i.e. It wraps the code in tags <span>:

from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter

code = 'print "Hello World"'
print highlight(code, PythonLexer(), HtmlFormatter())

gives

<div class="highlight">
<pre><span class="k">print</span> <span class="s">&quot;Hello World&quot;</span></pre>
</div>

, .

pygmentize script. script -: HTML, LaTeX, ANSI.

+8

Vim , , "" HTML ( ). GNU hightlight. .

+4

, GeSHi , , . , HTML/XHTML, ( X) .

+2

Enscript , :

  • HTML ( PS RTF) ascii
  • " " ( ) .
+1

, , doxygen , , , , -. , .

0

ruby, coderay.

0

I will add my own list to the list , it is C # color, but can be adapted for C, C ++ and Java. It creates inline styles by default and a preliminary tag.

The source is in C #, you need to grab mono / monodevelop and compile it as a console application so that it does not shrink in this regard.

0
source

Source: https://habr.com/ru/post/1697194/


All Articles