Installation

Link the CSS in <head>, jQuery, and the plugin before </body>.

HTML
<link rel="stylesheet" href="css/syntax.css">
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="js/syntax.js"></script>
Basic Usage

Call .syntax() on <pre><code> blocks. The plugin reads the raw text content and wraps tokens in <span> elements.

HTML
<pre><code class="language-js">
function greet(name) {
    return `Hello, ${name}!`;
}
</code></pre>
JavaScript
$('pre code').syntax();

Specify a language explicitly with the language option or via data-lang:

JavaScript
<!-- Per-element override -->
<pre><code data-lang="bash">
npm install && npm run build
</code></pre>

<!-- Global override -->
$('pre code').syntax({ language: 'js' });
Auto-Detection

If no language is specified, the plugin guesses from class names, content patterns, or data-lang.

Detection methodExample
class="language-js"Uses language-* or lang-* on the <code> or <pre>
data-lang="bash"Explicit data-lang attribute
JSONStarts with { or [
BashStarts with #! or common shell commands
HTMLContains <tag patterns
JavaScriptContains function, var, =>, etc.
CSSContains selectors, properties, @rules
Line Numbers

Enable with lineNumbers: true. Line numbers are rendered as .arx-syn-ln spans with user-select: none — they are visible but excluded from copy-paste. The gutter width auto-sizes to fit the widest line number.

JavaScript
$('pre code').syntax({ lineNumbers: true });
Supported Languages
LanguageKeyTokens highlighted
HTMLhtmlTags, attributes, values, comments, entities, doctype
CSScssSelectors, properties, values, units, at-rules, pseudo-classes, colors, var()
JavaScriptjsKeywords, built-ins, strings (all quote types), numbers, regex, comments
JSONjsonStrings, numbers, booleans, null, punctuation
BashbashCommands, keywords, flags, variables, strings, comments

List available languages at runtime:

JavaScript
ArxSyntax.languages();
// ["html", "css", "js", "json", "bash"]
Options

Pass an object to .syntax(options).

OptionTypeDefaultDescription
languagestringnullForce language (html, css, js, json, bash). null = auto-detect.
lineNumbersbooleanfalseShow line numbers. Uses user-select: none — excluded from copy-paste.
showLangbooleanfalseAdd data-lang attribute to highlighted blocks.
copyButtonbooleanfalseAdd a Copy button to the top-right of the code block. Uses navigator.clipboard.writeText.
API

The global ArxSyntax object provides direct access.

MethodDescription
ArxSyntax.highlight(el, lang)Highlight a single element with an explicit language.
ArxSyntax.languages()Returns array of available language keys.
Styling

The wrapper gets class .arx-syntax (uses arx CSS variables for theming). Token spans use .arx-syn-* classes. Override after importing syntax.css.

ClassToken type
.arx-syntaxWrapper on highlighted code block
.arx-syntax-lnVariant wrapper when line numbers are enabled
.arx-syn-lnLine number gutter span (unselectable)
.arx-syn-keywordKeywords (function, return, if)
.arx-syn-builtinBuilt-in objects (console, Math)
.arx-syn-stringString literals
.arx-syn-numberNumeric literals
.arx-syn-commentComments (line and block)
.arx-syn-booleanBooleans, null, undefined
.arx-syn-tagHTML tags
.arx-syn-attrHTML attributes
.arx-syn-entityHTML entities (&amp;)
.arx-syn-doctypeDOCTYPE declarations
.arx-syn-selectorCSS selectors (.class, #id)
.arx-syn-propertyCSS properties
.arx-syn-pseudoCSS pseudo-classes / elements
.arx-syn-punctPunctuation ({}, ;)
.arx-syn-atruleCSS at-rules (@media)
.arx-syn-regexRegular expression literals
.arx-syn-variableBash variables ($PATH)
.arx-syn-flagBash flags (--verbose)
Download

Download individual plugin files or grab the full package as a ZIP from the Library page.

FileDescription
README.md Installation, usage, language reference Download
css/syntax.css Code block and token color styles Download
js/syntax.js jQuery plugin — tokenizer and highlight engine Download