I spent a little bit of time trolling around trying to figure out how to use a pretty print-type add-in in RoboHelp. I had a lot of trouble with this, primarily because RoboHelp would de-register the baggage or totally ignore the second style sheet (and delete references to it from topics!
After a lot of playing around during a recent custom responsive layout build, I finally found a product and setup that works. It does require a bit of finessing, but if you’re savvy, you should be able to get it to work!

My environment

I haven’t tested this setup in every version of RoboHelp or in any other scenarios. That said, it should work in other versions. If your setup is different, post your results in the comments and let me know how it worked for you!

This is my current authoring setup:


  1. Visit highlight.js.
  2. Click the Get version 9.12.0 button (new versions will change this button name, please just click the button no matter the number!).
  3. On the¬†Getting highlight.js screen, scroll down to the Custom package section. Click to select or de-select the code types you need to pretty-print. Be liberal, if you think you might need it in the future, click it. The package isn’t huge. ūüôā
  4. Click Download.
  5. Locate the downloaded file hightlight.zip and extract the contents.
  6. Open the extracted highlight file.
  7. Copy the highlight.pack.js file to your clipboard.
  8. In your RoboHelp project, create a folder called js in Project Files.
  9. Right-click your new¬†js file and select¬†Explore….
  10. In the js folder in Windows explorer, paste the previously copied highlight.pack.js file.
  11. Back in RoboHelp, right-click the js folder, select Import Baggage, then click File.
  12. Double-click the highlight.pack.js file.
  13. Return to the highlight.js web site.
  14. Browse through the different languages and styles (click the links under the code block) until you find a style that you like, making note of the style name.
  15. Return to the opened highlight folder and double-click the styles folder.
  16. Locate the .css file that corresponds to the name of the style that you want to use and open it in Notepad or Notepad++ (or your own preferred text editor).
  17. Copy the entire contents of the file to your clipboard.
  18. Back in RoboHelp again, locate your project style sheet (generally¬†default.css, but yours may be named differently). Check out the file, if necessary, and open it in your text editor (right-click>Explore, double-click or double-click if your file associations are set in RoboHelp. DO NOT¬†edit it with RoboHelp’s stylesheet editor).
  19. Go to the end of your default.css and paste the contents of the highlight.js stylesheet in your style sheet.
  20. Save your changes.

Whew! Now you have highlight.js installed, how do you actually use it in topics?

You will need two blocks of code, inserted in the html of your topics, to make a code sample pretty:

This first block of code you will paste in your topic head, just before the </head> tag :

<script src=”../js/highlight.pack.js” type=”text/javascript”></script>
<script type=”text/javascript”>//<![CDATA[

IMPORTANT: Make sure that the path to the package,¬†../js/highlight.pack.js, matches the path to the default.css file in respect to the path. Your topic may be several layers deep relative to the css and js files, the path should reflect that. For example, if the topic’s path to the stylesheet is¬†../../../default.css, then the path to the js file should be¬†../../../js/highlight.pack.js. In other words, make sure that the number of ../ sequences before the¬†js/highlight.pack.js is the same number of ../ sequences before the¬†default.css.

The second block is pasted in the html in the position that you want to insert your code sample:


Paste the code after the <code> tag and before the </code> tag!

Here’s what your code will look like, these two code blocks are highlighted in yellow:

HTML representation of the code blocks mentioned in the article.
Topic HTML

Templates (.htt files)

You can add the first code block to a topic template, but it only works if the template is used on topic creation. If you add the code block to the .htt file, it will only work on new files created from that template. You will still have to place the script in the html heading manually for topics that have already been created.

Code sample prep

Before you paste your code sample inside of the second set of tags, you need to do a little bit of prep work so that it actually works properly when you paste it in. I find that Notepad++ is the best tool for doing this. It’s free, and the tasks listed use steps from that program.

  1. Open Notepad++ and paste your code sample in a new file.
  2. On your keyboard type CTRL + F.
  3. Switch to the Replace tab.
  4. In the Find what:  field, type > 
  5. In the Replace with: field, type &gt; 
  6. Click Replace All in All Opened Documents.
  7. In the Find what:  field, type < 
  8. In the Replace with: field, type &lt; 
  9. Click Replace All in All Opened Documents.
  10. On the Edit menu, select Blank Operations, then click TAB to Space.
  11. Copy the code sample and paste it in your RoboHelp topic between the <pre><code> and </code></pre> tags.

The screenshot above shows what your pasted code looks like after inserting it.

But wait!

There are a few things you need to know about when working with topics.

Final product

This is what your code sample will look like, or what mine does based on my selected style (blurs added to protect privacy):

The same code that is in the screenshot above, but in the published topic.
Code block in a topic

Did I miss anything? Have you been able to get a different prettyprint package to work with RoboHelp? Please let me know in the comments!

Leave a Reply

Your email address will not be published. Required fields are marked *