1

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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">&lt;SFML/Graphics/RenderTarget.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/Graphics/RenderTexture.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/Graphics/RenderWindow.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/System/Vector2.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/Window/ContextSettings.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/Window/Event.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/Window/Keyboard.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/Window/VideoMode.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;SFML/Window/WindowStyle.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;box2d/b2_math.h&gt;</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.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.