Highlight JS Extension Function

A Saxon extension function that convert source code to an hilighted html view of this source code. It uses highlight.js behind the scene. https://highlightjs.org/ It requires Java 11 at least. It requires Saxon 10 at least.

License

License

Categories

Categories

Axon Application Layer Libs Distributed Applications
GroupId

GroupId

top.marchand.xml.saxon.extension
ArtifactId

ArtifactId

highlight
Last Version

Last Version

1.01.00
Release Date

Release Date

Type

Type

jar
Description

Description

Highlight JS Extension Function
A Saxon extension function that convert source code to an hilighted html view of this source code. It uses highlight.js behind the scene. https://highlightjs.org/ It requires Java 11 at least. It requires Saxon 10 at least.
Project URL

Project URL

https://github.com/cmarchand/highligtJS-saxon-extension
Source Code Management

Source Code Management

https://github.com/cmarchand/highligtJS-saxon-extension

Download highlight

How to add to project

<!-- https://jarcasting.com/artifacts/top.marchand.xml.saxon.extension/highlight/ -->
<dependency>
    <groupId>top.marchand.xml.saxon.extension</groupId>
    <artifactId>highlight</artifactId>
    <version>1.01.00</version>
</dependency>
// https://jarcasting.com/artifacts/top.marchand.xml.saxon.extension/highlight/
implementation 'top.marchand.xml.saxon.extension:highlight:1.01.00'
// https://jarcasting.com/artifacts/top.marchand.xml.saxon.extension/highlight/
implementation ("top.marchand.xml.saxon.extension:highlight:1.01.00")
'top.marchand.xml.saxon.extension:highlight:jar:1.01.00'
<dependency org="top.marchand.xml.saxon.extension" name="highlight" rev="1.01.00">
  <artifact name="highlight" type="jar" />
</dependency>
@Grapes(
@Grab(group='top.marchand.xml.saxon.extension', module='highlight', version='1.01.00')
)
libraryDependencies += "top.marchand.xml.saxon.extension" % "highlight" % "1.01.00"
[top.marchand.xml.saxon.extension/highlight "1.01.00"]

Dependencies

compile (1)

Group / Artifact Type Version
org.graalvm.sdk : graal-sdk jar 20.1.0

runtime (1)

Group / Artifact Type Version
org.graalvm.js : js jar 20.1.0

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.6.2

Project Modules

There are no modules declared in this project.

HighLight JS Saxon extension

This library is a Saxon XPath extension function that transform source code to highlighted HTML, as highlight.js does, but without any JavaScript embeded in HTML.

To use this library, declare it as dependency :

  <dependency>
    <groupId>top.marchand.xml.saxon.extension</groupId>
    <artifactId>highlight</artifactId>
    <version>1.00.01</version>
  </dependency>

Then, declare this extension when creating Processor :

  Configuration configuration = Configuration.newConfiguration();
  Processor proc = new Processor(configuration);
  proc.registerExtensionFunction(
      new top.marchand.xml.saxon.extension.highlight.HighlightExtension());

Function's namespace is top:marchand:xml:extfunctions. You may use any prefix, but chm is commonly adopted.

Then in XPath, function is available :

  chm:highlight(language as xs:string, sourceCode as xs:string)
  chm:highlight(
      language as xs:string,
      sourceCode as xs:string,
      config as map(xs:string,xs:string)
  )

First form, with two parameters, generates an item()* sequence of span elements and text(), in http://www.w3.org/1999/xhtml namespace. If you need a different namespace, use the second form with a map as third argument. The only supported map-entry is 'result-ns', and its value is the required target namespace.

  chm:highlight('xml','<test>value</test>')

Produces

  <span xmlns="http://www.w3.org/1999/xhtml" class="hljs-tag">&lt;<span class="hljs-name">test</span>&gt;</span>value<span xmlns="http://www.w3.org/1999/xhtml" class="hljs-tag">&lt;/<span class="hljs-name">test</span>&gt;</span>
  chm:highlight('xml','<test>value</test>',map{'result-ns':''})

Produces

  <span class="hljs-tag">&lt;<span class="hljs-name">test</span>&gt;</span>value<span class="hljs-tag">&lt;/<span class="hljs-name">test</span>&gt;</span>

Versions

Version
1.01.00
1.00.01