Asciidoctor: Load grammar for additional source languages as defined by highlightjs-languages

Created on 28 Jan 2019  路  5Comments  路  Source: asciidoctor/asciidoctor

highlight.js only bundles support for the most "common" set of languages by default. When using the CDN, additional languages must be loaded using separate script tags. For example, to include support for YAML, you'd use:

<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/yaml.min.js"></script>

Currently, Asciidoctor (specifically the built-in HTML converter) doesn't provide a hook for loading additional languages.

This issue proposes adding additional script tags for any language listed in the value of the highlightjs-languages attribute. This attribute would accept a space-separated list of languages. (Asciidoctor would assume these languages do not overlap with the common languages bundled with highlight.js).

NOTE: If you're using a custom installation of highlight.js (meaning you've set the highlightjsdir attribute), then you most likely want to disable this attribute at the same time if you plan to bundle all the languages you need.

enhancement

All 5 comments

Dear Dan @mojavelinux Thanks for your kind support and hard work maintaining these awesome projects. To understand your comment here, the syntax highlighting on the live preview window relies on highlight.js. I was wondering if you could be kind to:

  • help me understand why the syntax highlighting on the live preview window works fine on Atom but not FireFox addon and VSCode. The language I'm using is Scilab.
  • How this issue could be resolved.

My apology if I do not understand how these things work exactly and my language is too primitive on this matter.

@Foadsf to summarize:

  • VSCode does not use highlight.js but an internal source highlighter which support Scilab language.
  • Firefox addon uses highlight.js with the most "common" set of languages by default (which does not include Scilab)

How this issue could be resolved.

For a proper solution, you will have to wait until this issue is fixed and we will also need to implement this feature in the browser extension (ie. Firefox addon).
I've found a workaround, see https://github.com/asciidoctor/asciidoctor-browser-extension/issues/276

I'll also add that it's fine if Atom bundles more languages for highlight.js than what's used by Asciidoctor Ruby. The reason we're limited in that environment is because we have to use what the CDN provides, and the CDN version only bundles a handful of languages (the common set). Just something to think about.

Sweeeet :heart:

I'll also add that it's fine if Atom bundles more languages for highlight.js than what's used by Asciidoctor Ruby. The reason we're limited in that environment is because we have to use what the CDN provides, and the CDN version only bundles a handful of languages (the common set). Just something to think about.

I think I should bundle all the languages into the browser extension (not sure if all the languages should be enabled by default though).
I don't want to rely on a CDN because the browser extension is designed to work offline.

I don't want to rely on a CDN because the browser extension is designed to work offline.

Indeed.

I think I should bundle all the languages into the browser extension (not sure if all the languages should be enabled by default though).

It's up to you how to structure it. If you do bundle all the languages in the pack, be sure to force disable highlightjs-languages so no attempt is made to load additional languages. If you choose to keep them in separate files, then just be sure they are located in the correct file hierarchy.

Was this page helpful?
0 / 5 - 0 ratings