A port of Asciidoctor (AsciiDoc processor) to MoonBit
Dependencies
///|
test "convert a string" {
let html = @asciidoctor.convert("A paragraph with *strong* and _emphasis_.")
inspect(
html,
content=(
#|<div class="paragraph">
#|<p>A paragraph with <strong>strong</strong> and <em>emphasis</em>.</p>
#|</div>
),
)
}///|
test "options" {
let options = @core.Options::new(backend="docbook5", attributes=[
("product", Str("MoonBit")),
])
inspect(
@asciidoctor.convert("Hello from {product}.", options~),
content=(
#|<simpara>Hello from MoonBit.</simpara>
),
)
}///|
test "load and inspect" {
let doc = @asciidoctor.load(
(
#|= Document Title
#|
#|== First Section
#|
#|content
),
)
inspect(doc.doctitle().unwrap(), content="Document Title")
let section = doc.blocks[0]
inspect(section.context.name(), content="section")
inspect(section.title().unwrap(), content="First Section")
inspect(section.id.unwrap(), content="_first_section")
}///|
test "inline macro extension" {
let exts = @core.Extensions::new()
exts.inline_macro("man", (parent, target, attrs) => {
let label = "\{target}(\{attrs.pos_str(1).unwrap_or("")})"
Some(
InlineNode(
@core.create_anchor(
parent,
Some(label),
"link",
target="\{target}.html",
),
),
)
})
let html = @asciidoctor.convert(
"See man:git[1].",
options=@core.Options::new(extensions=exts),
)
inspect(
html,
content=(
#|<div class="paragraph">
#|<p>See <a href="git.html">git(1)</a>.</p>
#|</div>
),
)
}moonx bobzhang/asciidoctor/cmd/asciidoctor@latest -b html5 -a toc doc.adoc
moon run --target native cmd/asciidoctor -- -b html5 -a toc doc.adoc| name | kind | provided by |
|---|---|---|
| highlight.js (highlightjs), prettify, html-pipeline | client-side | core |
| pygments | server-side, with the MoonBit port of Pygments | highlighter/pygments (optional) |
| rouge, coderay | not ported: they behave as in Ruby when their gems are missing | core |
///|
fn main {
@pygments.register() // bobzhang/asciidoctor/highlighter/pygments
let options = @core.Options::new(attributes=[
("source-highlighter", Str("pygments")),
])
println(
@asciidoctor.convert("[source,ruby]\n----\nputs 'hi'\n----", options~),
)
}| passing | |
|---|---|
| AST snapshots | 2593 / 2704 |
| converted outputs (HTML5, DocBook5, manpage) | 1763 / 1885 |
| log messages (severity, text, source location) | 2626 / 2702 |
| unexpected failures | 0 |
| path | contents |
|---|---|
| regex/ | backtracking regex engine with Ruby (Onigmo) semantics over UTF-16 |
| internal/rb/ | Ruby-compatible string and number helpers (strip, split, succ, Float#to_s, Unicode case mapping) |
| core/ | document model, reader/preprocessor, parser, substitutions, extensions API, converter interface |
| converter/html5, converter/docbook5, converter/manpage | converters |
| highlighter/pygments | server-side syntax highlighting with Pygments (optional, links bobzhang/pygments) |
| io/ | async file-system integration (load_file, convert_file, convert_source) |
| cmd/asciidoctor | CLI |
| cmd/golden, scripts/ | golden harvesting/replay, regex oracle, corpus comparison |
moon run --target native scripts/check.mbtx # check/test on all targets + golden parity
moon run --target native scripts/check.mbtx -- --corpus # also compare the corpora with Ruby
moon run --target native scripts/corpus.mbtx -- -v # corpus comparison only
moon run --target native scripts/corpus.mbtx -- -b html5 --pygments --standalone # with Pygments
moon run --target native scripts/cli_parity.mbtx -- -v # CLI vs Ruby: exit code, stdout, stderr, files
moon run --target native scripts/harvest.mbtx # regenerate goldens (needs Ruby + nokogiri, python3)
moon run --target native cmd/golden -- -v -n 20 # golden replay with failure details
moon run --target native cmd/golden -- --prune-known # drop fixed entries from known_failures.txttest {
let html = @asciidoctor.convert("Hello, *World*!")
inspect(
html,
content=(
#|<div class="paragraph">
#|<p>Hello, <strong>World</strong>!</p>
#|</div>
),
)
}Install
Download zipA port of Asciidoctor (AsciiDoc processor) to MoonBit
Dependencies