asciidoc-to-djot
v0.1.1
Published
Convert NIP-54 wiki articles from Asciidoc to Djot format
Maintainers
Readme
asciidoc-to-djot
Convert NIP-54 wiki articles from Asciidoc to Djot format.
Install
npm install asciidoc-to-djotCLI usage
# From file
asciidoc-to-djot article.adoc
# From stdin
echo '== Title' | asciidoc-to-djot
# Write to file
asciidoc-to-djot article.adoc -o article.djot
# Skip validation
asciidoc-to-djot --no-validate article.adocProgrammatic usage
import { convert } from "asciidoc-to-djot";
const asciidoc = `== Bitcoin
Bitcoin is a [[cryptocurrency]] invented by nostr:npub1satoshi123abc.
A https://bitcoin.org/bitcoin.pdf[whitepaper] was published in 2008.
`;
const { djot, warnings } = convert(asciidoc);
console.log(djot);Output:
## Bitcoin
Bitcoin is a [cryptocurrency][] invented by [nostr:npub1satoshi123abc](nostr:npub1satoshi123abc).
A [whitepaper](https://bitcoin.org/bitcoin.pdf) was published in 2008.What it converts
| Asciidoc | Djot |
|---|---|
| == Heading | ## Heading |
| *bold* | *bold* |
| _italic_ | _italic_ |
| `code` | `code` |
| ^super^ | ^super^ |
| ~sub~ | ~sub~ |
| [[Target]] | [Target][] |
| [[target\|display]] | [display][target] |
| https://url[text] | [text](https://url) |
| nostr:npub1... | [nostr:npub1...](nostr:npub1...) |
| image::file.png[alt] |  |
| Ordered/unordered/definition lists | Djot equivalents |
| Source blocks | Fenced code blocks |
| Tables | Pipe tables |
| Admonitions, quotes, sidebars | Djot divs with classes |
Architecture
The tool uses an AST-based pipeline:
- Pre-process — replace
[[wikilinks]]andnostr:URIs with placeholders (these are NIP-54 extensions that Asciidoctor doesn't handle natively) - Parse —
@asciidoctor/corebuilds an AST from the Asciidoc source - Convert — a custom
DjotConverterwalks the AST and emits Djot for each node type - Post-process — restore placeholders as Djot reference-style and inline links, normalize blank lines
- Validate —
@djot/djotparses the output to verify it's valid Djot
Development
npm install
npm run build
npm test