@deepthinking/highlightjs-zig
v1.0.0
Published
Zig language definition for highlight.js
Maintainers
Readme
highlightjs-zig
A comprehensive highlight.js language definition for Zig — a general-purpose programming language designed for robustness, optimality, and maintainability.
Features
- Full Zig syntax support: Keywords, built-in functions, types, and operators
- Built-in functions:
@import,@panic,@TypeOf,@sizeOf,@embedFile, and 50+ more - All Zig types:
i8-i128,u8-u128,usize,f16-f64,bool,void,anytype, and more - String handling: Multi-line strings, escape sequences, and C-string literals
- Numeric literals: Decimal, hexadecimal (
0x), binary (0b), octal (0o), and underscores - Documentation comments: Both
///(top-level doc) and//!(inner doc) comments - Attributes: Full support for Zig's
@[...]attribute syntax - Pointer syntax:
*T,[*]T,?*T, and more - TypeScript definitions: Full type declarations included
Installation
npm
npm install highlightjs-zigyarn
yarn add highlightjs-zigpnpm
pnpm add highlightjs-zigUsage
CommonJS
const hljs = require('highlight.js');
const zig = require('highlightjs-zig');
hljs.registerLanguage('zig', zig);ESM / ES6
import hljs from 'highlight.js';
import zig from 'highlightjs-zig';
hljs.registerLanguage('zig', zig);With auto-detection
import hljs from 'highlight.js';
import zig from 'highlightjs-zig';
hljs.registerLanguage('zig', zig);
document.querySelectorAll('pre code').forEach((block) => {
hljs.highlightElement(block);
});Using with rehype-highlight (React / Markdown)
If you're using rehype-highlight in a React application or Markdown processor:
import rehypeHighlight from 'rehype-highlight';
import zig from 'highlightjs-zig';
// Register the Zig language
rehypeHighlight.languages.zig = zig;Using with highlight.js auto-loader
If you use the highlight.js auto-loader script:
<script type="module">
import hljs from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/dist/es/highlight.min.js';
import zig from 'highlightjs-zig';
hljs.registerLanguage('zig', zig);
hljs.highlightAll();
</script>API
registerLanguage('zig', zig)
Register the Zig language with highlight.js.
import hljs from 'highlight.js';
import zig from 'highlightjs-zig';
hljs.registerLanguage('zig', zig);TypeScript
This package includes TypeScript definitions. No additional @types package needed:
import type { LanguageFn } from 'highlight.js';
import zig from 'highlightjs-zig';
const zigLanguage: LanguageFn = zig;Supported Highlight.js Versions
- highlight.js v11.x
- highlight.js v10.x (via legacy import)
Example
const std = @import("std");
pub fn main() void {
const stdout = std.io.getStdOut().writer();
// Print Fibonacci numbers
var a: u32 = 0;
var b: u32 = 1;
while (a < 100) {
stdout.print("{} ", .{a}) catch return;
const next = a + b;
a = b;
b = next;
}
stdout.print("\n", .{}) catch return;
}
/// A simple Fibonacci sequence generator
fn fibonacci(n: u32) u32 {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}Keywords & Syntax Covered
Control Flow
fn, if, else, while, for, return, break, continue, switch, case, defer, errdefer, try, catch, async, await, suspend, resume
Declarations
const, var, struct, enum, union, opaque, type, error, test
Modifiers
pub, export, extern, inline, noinline, volatile, allowzero, packed, comptime, noskip, align, section, usingnamespace, asm, mod
Built-in Types
| Type | Description |
|------|-------------|
| i8 - i128 | Signed integers |
| u8 - u128 | Unsigned integers |
| isize, usize | Platform-specific pointer sizes |
| f16, f32, f64 | Floating-point numbers |
| void | No value |
| bool | Boolean (true/false) |
| noreturn | Control flow that never returns |
| anyopaque | Opaque pointer type |
| anytype | Any type |
| comptime_int | Compile-time integer |
| comptime_float | Compile-time float |
Built-in Functions
@import, @compileLog, @panic, @assert, @field, @offsetOf, @TypeOf, @sizeOf, @embedFile, @panic, @trap, @inlineCall, @sqrt, @sin, @cos, @exp, @log, @pow, @floor, @ceil, @trunc, @round, @abs, @memcpy, @memset, @intCast, @floatCast, and 30+ more.
License
BSD 3-Clause License
Copyright (c) 2026, Jonathan Conway All rights reserved.
See LICENSE for full terms.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Support
If you encounter any issues or have questions:
- Open an issue on GitHub
- View the Zig documentation
- View the highlight.js documentation
