Code Monkey home page Code Monkey logo

highlightjs-saxon-extension's Introduction

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>

highlightjs-saxon-extension's People

Contributors

cmarchand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

highlightjs-saxon-extension's Issues

typo in repository name?

A very cool project!

The repository name, highligtJS-saxon-extension, appears to contain a typo: it's ligt instead of light (missing 2nd h).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.