Skip to main content
katew27494769
Inspiring
March 14, 2017
Question

Adding line numbers and syntax highlighting to code samples in HTML5 output

  • March 14, 2017
  • 1 reply
  • 2962 views

Greetings RoboHelp and HTML experts!

Does anyone have a good way to add line numbers to code examples in RoboHelp output? Outside RoboHelp, I've used CSS styles (<pre> and <code>), but you have to apply the <code> tags to every line -- a pain, especially when you have to update code samples -- and I haven't gotten it to work in RoboHelp. When I attempted to add the tags to topics in the HTML view, RoboHelp added dozens and dozens of extra <code> and </code> tags when I switched back to Design view. It made a real mess. Anyone know why?

I'm also looking for a way to highlight syntax in code samples. Any suggestions?

My current configuration:

Windows 7, TechComm Suite 2015

FrameMaker source, RoboHelp project for Multiscreen HTML5 generation

Here's the CSS I tried (worked outside of Robohelp):

pre {

  counter-reset: line;

  display: block;

    white-space: pre;

    margin: 1em 0;

  font-family: "Courier New";

  font-size: 10pt;

  background-color: #ededed;

  margin-right: 5pt;

  margin-left: 5pt;

  margin-top: 5pt;

  margin-bottom: 5pt;

}

code {

    counter-increment: line;

}

code:before{

    content: counter(line);

  font-family: "Courier New";

  color: gray;

  padding-right: 10pt;

  -webkit-user-select: none;

}

Thank you!

-Kate

This topic has been closed for replies.

1 reply

Peter Grainge
Community Expert
Community Expert
March 14, 2017

See if Item 15 at Snippets - Miscellaneous helps.


See www.grainge.org for RoboHelp and Authoring information

@petergrainge

Use the menu (bottom right) to mark the Best Answer or Highlight particularly useful replies. Found the answer elsewhere? Share it here.
Jeff_Coatsworth
Community Expert
Community Expert
March 14, 2017

I don't think that's the correct reference Peter - that one talks about a .book folder being created...

Peter Grainge
Community Expert
Community Expert
March 14, 2017

Quick & Dirty screen shots of the code samples & a link to download the text file?


I have only glanced at the later posts but if the objective is for people

to copy the code, they won't want the line numbering, their tools will give

them that together with the highlighting.

There's an example of how code can be copied at

http://grainge.org/pages/authoring/word/word_macros.htm. See the third fourth item.

Use the menu (bottom right) to mark the Best Answer or Highlight particularly useful replies. Found the answer elsewhere? Share it here.