How to use syntax highlighting with Blogger

Here is a development-themed blog, so I need a way to show you code fragments. The solution I would to test is code-prettify.

Before you modify the blogger's template, go to the template tab and download a complete backup of the current one. Modify the HTML code and add this line just before the </head> tag.

You have to choose options before inserting loader code, because you'll have to change the URL. The base URL is then, if you want to change the skin you have tp append ?skin=sons-of-obsidian to the URL. Please read official documentation for more informations and examples.

<script src='<final URL with options>'></script>

Now, for each code sample you want to add, you need to add the following HTML code and to escape HTML characters (this online tool can help you)  :

<pre  class='prettyprint'>
  Your code here

You can also choose to add line numbers and this highlighter supports many programming languages. As a complete example, here is some C++ code from the RainbruRPG's logger:

#include <string>

struct LogHeader
    string program_name;    //!< The program's name
    string program_version; //!< The program's version
    std::string compil_date;     //!< The compilation date
    std::string compil_time;     //!< The compilation time
    std::string exec_date;       //!< The execution date
    std::string exec_time;       //!< The execution time

class LoggerOutput
    /// Opens the logger, for example open the stream or the file
    virtual void open()=0;  
    /// Closes the logger
    virtual void close()=0;
    /** Start to log a line
      * \param vLoglevel  The logging level of the line
      * \param vLogdomain The log domain
      * \param vFilename  The source filename
      * \param vLine      The source line number
    virtual void startLog(LogLevel vLoglevel,
                          const std::string& vLogdomain, 
            const std::string& vFilename, 
                          const std::string& vLine)=0;

You now have a great syntax highlighter.


Popular posts from this blog

How to make a map of variant in C++