Formatting program source code

Navigation:  Basic Working Procedures > Text Formatting and Styles >

Formatting program source code

Previous pageReturn to chapter overviewNext page

Show/Hide Hidden Text

Examples of program source code are much easier to read if reserved words, comments, identifiers and so on are highlighted as they are in a modern programming editor. Help & Manual's Syntax Highlighting function does this for you. It understands the syntax of a total of 53 different code languages, so yours is almost certainly among them. You can also define up to three different custom formatting sets.

The highlighter is pre-configured with standard formatting for all these languages, but you can change the formatting yourself for every element type in every language to suit your own preferences. (Note that you must do this before applying your formatting – changing highlighting settings does not change the formatting of code that has already been highlighted.)

Click to expand/collapseHow to format program code

1.Paste your program code into your topic and select it.

2.Select the btn_syntax Syntax Highlighter tool in Write > Font (click on the arrow to the right of the icon to display the menu) then select the language parser you want to use from the list displayed.

Arrow_rIf the code language you are using is not displayed select Customize... to add it to the menu.

Once you have chosen a language parser it is set as the default until you select a different language. You can then select it directly by clicking on the main C:\ icon of the Syntax Highlighter tool in the Ribbon.

Click to expand/collapseEditing the syntax highlighting style

The syntax highlighter uses a standard style called Code Example for the font and paragraph attributes. By default this style is set to Courier New, 8 points, no word wrap and keep paragraph lines together.

You cannot delete or rename this style but you can edit it. Just position the cursor in a piece of text formatted with the syntax highlighter and select Styles > Edit Styles in the Write tab to open the style editing dialog with the Code Example style selected. See Editing styles for details.

Click to expand/collapseIndenting with leading spaces/blanks

Program code is often automatically indented with leading spaces. To get this to display correctly you just need to turn word wrap off in the paragraph settings of your code examples, either manually or with a style (this is already set correctly in the standard Code Example style used for syntax highlighting). Then all the spaces will be converted to   hard space entities which will render correctly in all browsers. Paragraphs will not wrap, but you don't want paragraphs to wrap in program code.

In paragraphs with word wrap turned on Help & Manual converts multiple spaces to alternating soft and hard space characters otherwise browsers would interpret multiple spaces as a single space. However, this will often not render quite right because different browsers interpret the width of these hard/soft space combinations in different ways.

Click to expand/collapseCustomizing the syntax highlighter

Click on the drop-down arrow next to btn_syntax in Write > Font, then select Customize....

DLG_HighlighterCustomize

Syntax highlighter settings are not styles!

Note that changing highlighting settings does not change the formatting of code that has already been highlighted. If you change your settings you must select the code again and re-apply the highlighting. Unlike styles, the syntax highlighter only applies inline formatting to selected text.

Font color and style:

You can define the font style and color for the supported elements for each highlighter language. To change the standard syntax highlighting font face click on Edit Style and edit the Code Example style that is used automatically by the syntax highlighter (see above).

Restoring the default settings:

Clicking on Reset Defaults restores all the syntax highlighter's settings for the current language to Help & Manual's default values, including the list of reserved words.

Format code samples with soft line breaks:

Uses soft line breaks instead of full paragraph breaks. Use this when you are using background color and border settings for your code samples, then line breaks will not interrupt the background and borders between lines.

Click to expand/collapseUser-defined highlighters

The last three code languages in the list are user-defined. You can use these to describe your own customized highlighting languages, including a list of reserved words that you can load from an external file.

See also:

Editing styles