Reputation: 11
I am using Pygments as a source highlighter for documenting a C++ project. Both Python 2.7.x and Pygments are their latest versions. I am having trouble getting a highlighted html output for my source code when I run pygments using command line:
pygmentize -f html -o a.html test1.cpp
The result is a colorless html output. Curiously, running the same command with Rich Text File format results in a colored rtf file:
pygmentize -f rtf -o a.rtf test1.cpp
I tried a simpler C code and the html output was highlighted correctly. Any ideas why this is happening? The sample code I am having trouble with is here
Upvotes: 1
Views: 1827
Reputation: 1
pygmentize does not output any css in that html file, it only adds classes to html elements. For example:
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Graphics/RenderTarget.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Graphics/RenderTexture.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Graphics/RenderWindow.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/System/Vector2.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Window/ContextSettings.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Window/Event.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Window/Keyboard.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Window/VideoMode.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><SFML/Window/WindowStyle.hpp></span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf"><box2d/b2_math.h></span><span class="cp"></span>
As you can see, you can write a simple css that looks like this:
.cp {
color: green;
}
And all preprocessor calls will be green. Repeat this for all the class values you will see (maybe use italics for comments etc.)
Upvotes: 0
Reputation: 198
I've noticed the same thing with C++. Since you know what language to highlight ahead of time, try this:
pygmentize -N test1.CPP
This will tell you which lexer pygmentize will use. It should be CppLexer but if not then tell pygmentize to use the CppLexer lexer:
pygmentize -f html -o a.html -l CppLexer test1.cpp
I know this was asked awhile ago and not surprising the sample code you posted is now gone therefore I can't test it.
Upvotes: 1