Code Highlighting


AutoNOTE 2 uses a Rouge highlighter to provide effective code formatting. There are two distinct versions of code highlighting:

  1. Inline code or keywords.
  2. Code snippets.

The AutoNOTE highlighter has some additional features and options, detailed in the document below.

Inline Keywords

You can highlight keywords in a body of text using the tick symbol, for example this sentence was generated using:

You can `highlight` keywords in a body of text.
Code snippet

Code snippets

Code snippets are generated using the highlight command. For example:

{% highlight python %}
# Start with a comment.
def HelloWorld():
  message = 'Hello World'
  print(message) # Prints the message 'Hello World' to the terminal
  return 0
{% endhighlight %}
Code snippet

As shown in this example, the programming language (python) is provided as an argument to ensure that the syntax highlighting is processed correctly. This yields the following result:

# Start with a comment.
def HelloWorld():
  message = 'Hello World'
  print(message) # Prints the message 'Hello World' to the terminal
  return 0
Code snippet

You should be able to see it in . This should show as undefined

Optional arguments

linenos - Line numbering

startline - Numbering start count

enddots

noselect

{% highlight python linenos startline=3 enddots noselect %}
# Start with a comment.
def HelloWorld():
  message = 'Hello World'
  print(message) # Prints the message 'Hello World' to the terminal
  return 0
{% endhighlight %}
Code snippet
Selection Disabled
...
3
4
5
6
7
# Start with a comment.
def HelloWorld():
  message = 'Hello World'
  print(message) # Prints the message 'Hello World' to the terminal
  return 0
...
Code snippet

Referencing and Captioning Code Snippets

Like with images, you can reference a code snippet using their unique ID.

This will produce a link with the number automatically populated by AutoNOTE. For example, . Clicking on these links will scroll the page to the referenced image.

First, the code snippet must include an ID and caption argument, as follows:

{% highlight python id="code_ref_demo" caption="The code to implement a HelloWorld() function in Python." %}
# Start with a comment.
def HelloWorld():
  message = 'Hello World'
  print(message) # Prints the message 'Hello World' to the terminal
  return 0
{% endhighlight %}
Code snippet
# Start with a comment.
def HelloWorld():
  message = 'Hello World'
  print(message) # Prints the message 'Hello World' to the terminal
  return 0
The code to implement a 'HelloWorld()' function in Python.

You may then reference the code snippet in the text using the reference include. This is achieved using the following command, simply replace the id in the arguments with the id of the image you wish to reference:

{% include ref id="code_ref_demo" %}
Code snippet

The reference will then appear on page like this:

Coming soon

  • Filename argument
print('hello World') # Comment
Code snippet

Todo: Explore custom include folder.