Add first-class AsciiDoc support to Hexo. The renderer piggybacks on asciidoctor.js 3.x, swaps Asciidoctor’s code blocks with Hexo’s static highlighter, and escapes template delimiters so the resulting HTML can flow back through Hexo safely.
- The renderer runs Asciidoctor in
safe: 'server'mode, which blocks shelling out and limits file access to the site root. - Output HTML is not sanitized beyond encoding
{/}; treat your AsciiDoc sources as trusted or run Hexo through an additional sanitizer (DOMPurify, OWASP Java HTML Sanitizer, etc.) before publishing user-generated content. - Code blocks are re-highlighted via
hexo-utilso they inherit whatever theme/config you enable in_config.yml.
| Dependency | Minimum version |
|---|---|
| Node.js | 20.19.0 |
| Hexo | 8.0.0 |
Install from npm (choose the package manager that matches your Hexo project):
npm install hexo-renderer-asciidoc --save
# or
pnpm add hexo-renderer-asciidocOnce installed, Hexo automatically pipes .ad, .adoc, and .asciidoc files through this renderer, no extra glue code is required.
AsciiDoc posts reuse Hexo’s regular highlighting settings. A typical _config.yml looks like this:
highlight:
enable: true
line_number: false
wrap: falseKeep highlight.enable turned on even if you never write Markdown; the renderer calls the same helper under the hood to keep code blocks consistent with the theme.
A self-contained demo lives at examples/hexo-site. It links to the local workspace via link:../.., so every change you make to the renderer is reflected instantly.
cd examples/hexo-site
pnpm install
pnpm devNote
The sample site is intentionally outside the root pnpm workspace. Always run pnpm commands from inside examples/hexo-site so Hexo’s dependencies stay isolated. Its pnpm-workspace.yaml and lockfile must remain in that folder when you copy the demo elsewhere.
Browse examples/hexo-site/source/ for end-to-end samples of admonitions, callouts, audio/video embeds, and other constructs covered by the test suite.
- AsciiDoc parity. Snapshot-style doctests (
test/doctest/*.test.ts) mirror sections from the Asciidoctor user manual so features such as admonitions, description lists, colists, inline UI macros, and complex tables stay stable between releases. - Zero-config Hexo integration.
src/hexo/register.tswires the renderer for.ad,.adoc, and.asciidocextensions with synchronous semantics so Hexo’s asset pipeline can stream results as soon as they are available. - Static highlighting bridge.
src/core/highlight.tswalks every<pre class="highlight">block produced by Asciidoctor and re-renders it withhexo-util.highlight, ensuring your Hexo theme powers the final markup (including languages not known to Asciidoctor’s built-in highlighters). - Template safety.
src/core/sanitize.tsencodes{/}characters before returning control to Hexo so they are not interpreted as Nunjucks placeholders. - Tested in Hexo.
test/hexo.integration.test.tsspins up a real Hexo instance to guarantee the renderer continues to work with Hexo’s official API.
The default export is the pure renderer function. You can reuse it in custom build scripts or other static-site setups:
import renderer from 'hexo-renderer-asciidoc';
const html = renderer({ text: '== Custom pipeline ==' });Hexo users rarely need this, but it is handy for local testing or for wiring the renderer into other tools.
mise install # Install pinned versions of Node, pnpm, hk, etc.
pnpm install # Install workspace dependencies
hk install # Register git hooks (lint, format, tests)| Command | Purpose |
|---|---|
pnpm lint |
Run Biome for JS/TS/JSON and Markdownlint/Prettier for docs. |
pnpm format |
Apply the same formatters with --write. |
pnpm typecheck |
Run tsc --noEmit for strict type safety. |
pnpm test |
Execute the entire Vitest suite (including doctests + integration). |
pnpm test:watch |
Rerun the impacted tests in watch mode. |
pnpm test-cov |
Generate text + LCOV coverage via V8. |
pnpm build |
Bundle src/ with tsdown into the publishable dist/. |
hk check |
Execute every hook (lint, format, typos, tests) exactly like CI. |
src/core/– Asciidoctor bootstrap, syntax highlighting bridge, and HTML safety helpers.src/hexo/– The Hexo adapter that registers the renderer for.ad/.adoc/.asciidocfiles.examples/hexo-site/– Real Hexo project wired to the local package for smoke testing and documentation screenshots.scripts/npm-readme.cjs– SwapsREADME.mdwithREADME.npm.mdduringnpm packso the npm landing page gets the end-user guide without disturbing this contributor-focused README.
- Doctests live under
test/doctest/and load fixture snippets fromtest/doctest/examples/asciidoc/*.adocbefore snapshotting the rendered HTML. test/highlight.test.tsensures the static highlighter decodes entities before passing code to Hexo.test/hexo.integration.test.tsboots Hexo and exercises the renderer viahexo.render.render.
Run all doctests while iterating on Asciidoctor upgrades:
pnpm test --filter Doctestpnpm typecheck && pnpm test– add/adjust fixtures if coverage drops.pnpm build– refreshdist/viatsdown.- Update
ChangeLog.mdand bump the semver inpackage.json. pnpm publish– theprepublishOnlyhook rebuilds automatically, andscripts/npm-readme.cjsswaps the npm README before the tarball is packed.
.github/workflows/ci.ymlruns linting, type checks, Vitest, and the production build on Node 20.19 / 20.x / 22.x / 24.x..github/workflows/codeql.ymlkeeps CodeQL scanning the TypeScript sources on every push and a weekly schedule.
Licensed under LGPL-3.0-or-later WITH LGPL-3.0-linking-exception. See COPYING, COPYING.LESSER, and LICENSES/ for the full texts. Commercial redistribution requires compliance with the linking exception.