QuantumJS
Edit Page
quantum-code-highlight
A module for providing code highlighting
About
This module provides the entity transforms for @code and @@codeblock entities. The code and codeblock entities render highlighted code blocks.
Examples
Inline code
Example Markup
Quantum
Some @code[inline()] code
Example Result
Some inline() code
Code block
Example Markup
Quantum
@@codeblock css
  .class {
    background: #FFF;
}
Example Result
.class {
  background: #FFF;
}
Entities
The below entities are provided by the entityTransforms function.
Entities
@codeblockadded
Creates an inline code section with highlighting using highlight.js
Example Markup
Quantum
@@codeblock
  // Syntax Guessing
  some.code = 3

@@codeblock js
  // Set the language to JS
  var a = true

@@codeblock nohighlight
  // Don't apply highlighting
  some code without highlighting
Example Result
// Syntax Guessing
some.code = 3
// Set the language to JS
var a = true
// Don't apply highlighting
some code without highlighting
codeadded
Creates an inline code section without code highlighting
Example Code:
Example Markup
Quantum
@code[some.code = 3] @code[var a = true]
Example Result
some.code = 3 var a = true
Api
Below are all the properties of the object returned from require('quantum-code-highlight'). For information about different versions, see the Changelog
Functions
entityTransformsoptionsObjectObject[EntityTransform]added
A function that returns a set of EntityTransform functions for use in quantum-html
Arguments
options
The options to use when creating the set of entity transforms.
Returns
The entity transforms to use in quantum-html to define the entities that can be rendered.
highlightCodecodeStringlanguageStringStringadded
A function that takes a chunk of code and applies highlight.js highlighting, returining the html with highlight classes applied.
This function is used in the @@codeblock entity but can be used within custom entity transforms if required.
If using this directly, you must add the stylesheetAsset in the transform or the highlight colours will not be applied.
Arguments
codeString
The code to highlight
languageString
The language to use for the highlighting.
If this is not defined, it uses the automatic highlighting and attempts to guess the language.
If highlight.js does not know the language, it does not apply highlighting and returns the code it was passed.
Returns
The HTML string with highlighting applied