8000 GitHub - cxz/weavon: Drop-in Pandoc 3.13 replacement in safe Rust. 129 formats, Lua 5.4, citeproc, embedded PDF 1.7, RAG chunker, semantic diff, lint, and WebAssembly. · GitHub
[go: up one dir, main page]

Skip to content
cxzPublic
forked from weavon/weavon

About

Drop-in Pandoc 3.13 replacement in safe Rust. 129 formats, Lua 5.4, citeproc, embedded PDF 1.7, RAG chunker, semantic diff, lint, and WebAssembly.

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Weavon panda, a minimalist black and white panda head

Weavon

Fast Rust drop-in replacement for Pandoc 3.13.
15.3x to 49.7x the speed of Pandoc 3.13 on 1 MB inputs. One 9.26 MB stripped ARM64 binary.

Website · Playground · Benchmarks · Compatibility · Install · Integrations · Docs

Release v0.2.0 Pandoc 3.13 parity 99.93% Licence MIT or Apache-2.0

Weavon converts Markdown, HTML, Word, LaTeX, and other document formats. Run it as pandoc to use your existing scripts and filters in Pandoc 3.13 compatibility mode. Weavon matches 65,891 of 65,937 baseline test units (99.93%). The known differences list the limits. Weavon is an independent project under the MIT or Apache 2.0 licence.

New in v0.2.0

  • Write PDF with --pdf-engine=embedded. The Rust engine renders text, math, and SVG without TeX. It embeds font subsets and writes PDF tags.
  • Keep original Word and PowerPoint package parts in native same-format conversions. Unchanged documents can make a lossless round trip.
  • Run sandboxed WebAssembly filters with --filter FILE.wasm. The engine accepts Weavon reactor modules and WASI Preview 1 command modules.
  • Use the PyO3 and Node-API bindings to parse, transform, and render document trees in Python and Node.js. Build the native modules from source.
  • Connect tools through the Model Context Protocol with weavon mcp. Use weavon lsp for editor diagnostics and weavon preview for live prev 8000 iew.
  • Extract text or chunks with weavon extract. Use weavon redact to remove selected sensitive data and weavon git-setup to configure Git text diffs.
  • Build a book for PDF, EPUB, DOCX, and HTML from one project file. Include tables from CSV, TSV, Excel, or JSON. Start a project with weavon init --template book or choose paper, resume, slides, invoice, or report.

Quick install

On macOS and Linux, one line installs the weavon program into ~/.local/bin.

curl -fsSL https://weavon.org/install.sh | sh

Add --as-pandoc to use Weavon as Pandoc right away. The installer then also makes ~/.local/bin/pandoc a link to Weavon, so each pandoc command runs Weavon in Pandoc 3.13 mode.

curl -fsSL https://weavon.org/install.sh | sh -s -- --as-pandoc

On Windows, run the installer in PowerShell with the first line. Use the second line in its place to also add a pandoc command.

irm https://weavon.org/install.ps1 | iex
& ([scriptblock]::Create((irm https://weavon.org/install.ps1))) -AsPandoc

The installers download the prebuilt program of the latest release from the release page and check its SHA-256 checksum before they install it. Prebuilt programs are available for macOS (arm64 and x86_64), Linux (x86_64 and arm64) and Windows (x86_64).

Homebrew installs from the Weavon tap on macOS and Linux, together with the shell completions for bash, zsh and fish.

brew install weavon/tap/weavon

Scoop installs from the Weavon bucket on Windows.

scoop bucket add weavon https://github.com/weavon/scoop-bucket
scoop install weavon/weavon

Cargo users can download the same release archive with cargo binstall, or build the program from the Git repository with cargo install.

cargo binstall --git https://github.com/weavon/weavon weavon-cli
cargo install --locked --git https://github.com/weavon/weavon weavon-cli

In GitHub Actions, one step installs Weavon on Linux, macOS and Windows runners. With as-pandoc: true, your existing Pandoc, Quarto and Make steps use Weavon with no other change.

- uses: weavon/weavon@v0.2.0
  with:
    as-pandoc: true

The container image ghcr.io/weavon/weavon has no shell and no TeX, and it still writes PDF with the built-in engine.

docker run --rm --user "$(id -u):$(id -g)" -v "$PWD:/data" ghcr.io/weavon/weavon notes.md -o notes.html

Use Weavon as pandoc

After a Homebrew, Scoop or Cargo install, or after you unpack a release archive, one command turns on drop-in mode.

weavon setup --as-pandoc

The command makes a pandoc link to weavon in the folder of the weavon program. When that folder is not writable, it makes the link in ~/.local/bin instead (on Windows, in the folder that install.ps1 uses), and --dir PATH picks another folder. An unrelated pandoc program stays in place unless you add --force. weavon setup --unlink removes the link, but only when the link points to Weavon. Plain weavon setup prints the drop-in status and the commands for drop-in mode and shell completions.

Build from source and install shell completions

A source build needs Rust 1.99 or later and a C compiler.

git clone https://github.com/weavon/weavon
cd weavon
cargo build --release -p weavon-cli

Weavon writes completion scripts for zsh, bash, fish and PowerShell.

weavon completions zsh > "${fpath[1]}/_weavon"
weavon completions bash > ~/.local/share/bash-completion/completions/weavon
weavon completions fish > ~/.config/fish/completions/weavon.fish
weavon completions powershell >> $PROFILE

Quick start

Weavon takes the same arguments as Pandoc, so the commands you already know work as they are.

# Convert Markdown to HTML.
weavon notes.md -o notes.html

# Write a PDF with no TeX installation.
weavon notes.md -o notes.pdf --pdf-engine=embedded

# Write a starter weavon.yaml with the profiles web, pdf and llm.
weavon init

# Convert a whole folder in parallel with the web profile.
weavon build docs/ --output-dir site/ --profile web

# Compare two versions as Word tracked changes.
weavon diff contract-v1.docx contract-v2.docx -o redline.docx

weavon init does not overwrite an existing weavon.yaml unless you add --force, and --dir PATH writes the file into another folder. weavon build needs an output folder in --output-dir DIR, and the output folder mirrors the input tree.

Drop-in Pandoc

Start Weavon with the name pandoc and it runs in compat mode, which behaves as Pandoc 3.13. The first line of pandoc --version is then pandoc 3.13, and the second line names Weavon. Compat mode reads no configuration file and makes no network request that Pandoc does not make. Under any other name, the option --compat=pandoc-3.13 turns on the same mode.

We compare Weavon with Pandoc 3.13. The conformance row gives the v0.2.0 baseline result. The remaining rows describe the recorded test suites.

Test Result Evidence
Conformance harness (Weavon test cases with Pandoc results) 65,891 of 65,937 units pass (99.93%, 65,776 byte-identical). 46 units differ on purpose. spec/baseline.json
Input formats 50 of 52 pass, 2 partial, 0 fail spec/capabilities.json
Output formats 75 of 77 pass, 1 partial, 0 fail (pdf has no oracle comparison) spec/capabilities.json
Extensions 90 of 90 pass spec/capabilities.json
Options 99 of 109 pass, 9 partial, 0 fail spec/capabilities.json
Pandoc 3.13 test suite (run outside this repository) 2,228 of 2,231 pass. The 3 failures are the shell completion tests, because Pandoc's scripts are GPL text. spec/pandoc-testsuite.json
Real documents (230 open-licence documents, 3 output formats) 690 of 690 equal spec/corpus.json
Server mode over HTTP and CGI (full matrix) 67,813 of 67,828 units equal (99.98%). 15 units differ on purpose. 25 of 25 parity groups equal over both transports (50 of 50 checks). tools/server/
Lua 5.4 API names 468 of 468 equal (100%) PROGRESS.md

A unit is equal when its output, its warnings and its exit code are equal to those of Pandoc. The section Differences from Pandoc lists each difference that a user can see.

Performance

Median wall time in milliseconds on Apple Silicon ARM64 with macOS, on a quiet system. Text workloads use 1 MB inputs and docx-json uses a 106 KB compressed DOCX corpus. The suffix -nohl means syntax highlighting is off. N/A indicates that the comparison has no result.

Workload Weavon v0.2.0 Weavon v0.1.0 Carta 0.0.16 ferrodoc 1.0.1 Pandoc 3.13 Speedup vs Pandoc
cm-json 28.51 49.37 50.32 44.59 762.98 26.8x
html-json 19.53 20.17 25.17 N/A 807.27 41.3x
json-json 7.87 7.49 9.71 12.36 129.86 16.5x
json-html 13.95 11.55 10.93 33.43 247.40 17.7x
json-html-nohl 9.52 9.21 10.79 29.56 202.81 21.3x
json-latex 14.41 13.96 13.21 16.60 220.34 15.3x
json-latex-nohl 9.89 11.78 14.20 16.12 182.80 18.5x
md-html 62.61 55.75 62.97 N/A 2300.01 36.7x
md-html-nohl 44.82 47.09 63.91 N/A 2227.26 49.7x
latex-json 26.06 24.47 41.28 N/A 574.36 22.0x
docx-json 54.65 53.83 95.48 N/A 1805.26 33.0x

The stripped ARM64 dist binary is 9,256,784 bytes (9.26 MB, 8.83 MiB). It is 120,736 bytes smaller than the v0.1.0 binary in this comparison. On macOS it links only to /usr/lib/libSystem.B.dylib. See the full benchmark tables for peak memory and binary sizes.

Plugins and integrations

Weavon fits into the editors, build tools and pipelines you already use. Most of them need no change at all, because Weavon answers to the name pandoc. The integrations guide gives the full setup for each one.

  • VS Code. The extension in plugins/vscode converts the open document, exports a PDF with no TeX, shows lint findings in the Problems panel, formats Markdown and writes a redline against an older file.
  • Neovim. The plugin in plugins/weavon.nvim loads with lazy.nvim. It adds :WeavonConvert, :WeavonPdf, :WeavonLint, :WeavonFmt and :WeavonDiff, and it shows lint findings as native diagnostics.
  • pre-commit. The hooks weavon-lint, weavon-fmt and weavon-fmt-write run the weavon program on your PATH, so pre-commit installs no Python or Node environment for them.
  • Python and pypandoc. Install with pip install weavon (prebuilt wheels bundle libweavon_c for macOS, Linux, and Windows). Change one import line to from weavon import compat as pypandoc and the calls stay the same. The package workflow ships the C library and loads it through ctypes. You can also build the PyO3 extension in bindings/python.
  • Vite, Rollup and Node.js. Install with npm install weavon on Node.js 22 or later. The weavon/vite plugin turns each Markdown or HTML file that you import into an ES module with the HTML, the front matter and the source text. The package in bindings/node bundles the WebAssembly module in the process with no npm dependency and no subprocess, and it has TypeScript types. Build the optional Node-API addon from bindings/node/native.
  • WebAssembly. The weavon-wasm crate builds a browser module with an ESM wrapper (crates/weavon-wasm/js/weavon.mjs). It converts, diffs, chunks and checks documents in a sandbox. Build with the pdf feature to read and write PDF in the browser.
  • Quarto, R Markdown and Make. These tools run a program named pandoc. Make finds the drop-in link on the PATH, and Quarto and R Markdown find it through an environment variable that the integrations guide names.

The Python and Node.js packages both give a typed Pandoc AST and a walk function, so you can write filters in the host language.

Pandoc features

Weavon supports these features of Pandoc 3.13.

  • Lua 5.4 filters, custom readers and custom writers (--lua-filter, -f FILE.lua, -t FILE.lua, pandoc lua), with LPeg 1.1.0.
  • JSON filters (--filter).
  • Citations (--citeproc) with CSL 1.0.2 styles. Weavon includes its own default style and locales, so --citeproc works without --csl.
  • PDF output through the 15 engines of --pdf-engine. Native mode adds a built-in engine (--pdf-engine=embedded) that needs no TeX installation.
  • Syntax highlighting for all 194 Pandoc 3.13 built-in languages, using 62 KDE language definitions (plus the shared Alerts helper) and 132 Rust definitions written for Weavon embedded in clean-syntaxes.zlib, with 0 differences across 13,986 replay cases.
  • A server mode that is compatible with pandoc-server. Start it with weavon server, or run the program as pandoc-server or pandoc-server.cgi.

Beyond Pandoc

Weavon has two modes. Compat mode is the drop-in Pandoc 3.13 that the section above describes, and the native features of this section are off in it. Native mode starts when you run the program as weavon. It accepts the same command line and adds the workflows below.

Each native-only extension has the prefix x_, and Pandoc has no extension with this prefix. ADR 34 gives the design.

  • Zero-glue command line. Weavon finds weavon.yaml in the input folder or in a parent folder, and named profiles select a target (--profile NAME). --print-config prints each effective value and its origin. Keys that run programs or write files apply only from a trusted file (--trust-config). The x_include extension includes other files, and it stays inside the project root and stops at cycles and at a size budget. weavon build and --output-dir convert many files in parallel (-j N), and the workers share file bytes and parsed bibliographies. weavon watch converts again when a file that the conversion reads changes. With --sandbox, it watches only the input files and weavon.yaml. Standard input with no -f gets its format from its content. An unknown option, format or extension gets a "did you mean?" hint, and --diagnostics=human|json|sarif selects the diagnostic output (SARIF 2.1.0).
  • LLM and RAG ingestion. --main-content keeps only the main article of an HTML page, --clean removes raw HTML, attributes and wrappers, and --base-url resolves relative links. -t llm-markdown applies these settings in one step. weavon chunk writes JSON Lines chunks with heading breadcrumbs and token estimates for retrieval-augmented generation (RAG). --emit-llms-txt writes llms.txt and llms-full.txt for a batch.
  • Semantic diff and Word redlines. weavon diff OLD NEW compares two documents block by block and word by word. It writes Word tracked changes (native <w:ins> and <w:del> in DOCX), CriticMarkup, HTML with <ins> and <del>, Markdown or JSON.
  • Obsidian and static site dialects. -f obsidian turns on x_callouts, x_alerts, x_embeds, x_block_refs and x_tags, and callouts become canonical HTML5 and DOCX callouts. Five writers produce static site Markdown. They are docusaurus-mdx (with x_mdx_safe), mkdocs-md, hugo-md, starlight-md and myst-md.
  • Authoring and CI quality. x_crossref numbers figures, tables, equations, listings and sections before --citeproc runs. x_diagrams draws Mermaid flowcharts and sequence diagrams, Graphviz DOT and D2 as SVG in pure Rust, with no browser and no Graphviz program. --resolve-citations=lockfile resolves doi:, arxiv:, pmid: and isbn: keys from weavon-citations.lock.json with no network request. weavon lint checks 10 accessibility and DocOps rules in each input format and writes SARIF 2.1.0. weavon fmt formats Markdown and refuses output whose document tree differs from the input. weavon inspect prints the format, the extensions and the tree, and weavon doctor checks the environment. --preserve-yaml-types keeps 3.10 as 3.10. With SOURCE_DATE_EPOCH set, DOCX, EPUB, ODT and PPTX output is byte-identical on each run.
  • Embedded PDF engine. --pdf-engine=embedded writes PDF 1.7 directly from the document tree, in pure Rust with no unsafe code. It needs no TeX Live and runs no external program, so it works with --sandbox and with an empty PATH. The PDF has bookmarks (/Outlines), links, tables, code blocks, callouts and footnotes, and with SOURCE_DATE_EPOCH set, the PDF bytes are the same on each run. The engine embeds JPEG and PNG images, and it adds accessibility tags with alt text for figures. It embeds Unicode font subsets. Use a font pack or supply a font file for glyphs outside the bundled fonts. The engine supports a subset of raw LaTeX. Use an external engine such as lualatex for constructs suc 9E8D h as TikZ.
  • Native server. weavon server and weavon-server add native routes on the same address and port. GET /healthz gives the health state, and GET /metrics gives Prometheus counters. POST /v1/convert, /v1/diff, /v1/chunk and /v1/lint take the raw input bytes and give the raw output bytes, with no JSON wrapper and no Base64. With to=pdf, the server writes PDF in the process. A request deadline or a server stop cancels the conversion job. --compat=pandoc-3.13 turns off the native routes, and pandoc-server always behaves as Pandoc 3.13. See docs/SERVER.md for routes, limits, and production build profiles.
  • Embedding. The weavon-c crate gives a C ABI (include/weavon.h) for conversion, diff, chunks and lint, and conversion includes PDF through the embedded engine. Each call runs in a sandbox with no files, no network and no processes, and with input and output limits of 64 MiB. The weavon library has one Cargo feature for each group of formats (for example format-markdown), so an embedder can build only the formats that it needs. PolicyHost limits the files, URL hosts and programs that a conversion can use.
  • SVG math. --math-svg converts TeX math to SVG during HTML conversion, so the page needs no MathJax. The server takes math=svg.
  • PDF input. The opt-in Cargo feature reader-pdf reads born-digital PDF in native mode. A tagged PDF gives its blocks from the structure tree, and an untagged page gives headings, paragraphs, lists and tables from the layout. The reader does no OCR (optical character recognition). A page with images and no text goes to a PdfPageFallback hook, or gives the warning W_PDF_SCANNED_PAGE_NEEDS_OCR.

These commands show the native workflows.

# Convert a folder in parallel with the "web" profile of weavon.yaml.
weavon build docs/ --output-dir site/ -j 8 --profile web

# Convert again each time that the input or a file that it reads changes.
weavon watch notes.md -o notes.html

# Turn a web page into clean Markdown, then into chunks for a vector store.
weavon page.html --main-content -t llm-markdown -o page.md
weavon chunk page.md --max-tokens 512 -o chunks.jsonl

# Write a Word document with tracked changes between two versions.
weavon diff contract-v1.docx contract-v2.docx --author "Legal" -o redline.docx

# Write a PDF with no TeX installation, and a PDF redline.
weavon paper.md --pdf-engine=embedded -o paper.pdf
weavon diff old.md new.md -o redline.pdf

# Serve the native routes, then convert raw bytes to PDF over HTTP.
weavon server --port 3030
curl --data-binary @paper.md "http://localhost:3030/v1/convert?to=pdf" -o paper.pdf

# Draw diagrams, number cross-references, and resolve citations offline.
weavon -f markdown+x_diagrams+x_crossref paper.md --citeproc \
  --resolve-citations=lockfile -o paper.html

# Check documents in CI and format Markdown in place.
weavon lint docs/*.md --diagnostics=sarif > lint.sarif
weavon fmt --check docs/*.md

Differences from Pandoc

Some data files of Pandoc have a licence that does not permit their distribution with Weavon, and some features are not complete yet. The table gives each difference that a user can see, and docs/ISSUES.md gives all known differences.

Area Difference What to do
Default citation style The built-in style and locales are Weavon's own work. Some citations can differ from Pandoc's default.csl. Use --csl with the style that you need.
DOCX, ODT, FODT, and PPTX styles Weavon writes its own default styles, because the reference documents of Pandoc are GPL. The output bytes differ. Use --reference-doc with your reference document.
EPUB stylesheet Weavon uses its own default stylesheet. Use --css.
Translated labels Weavon has its own labels (for example "Abstract") for 107 language tags. Some labels differ from Pandoc. Put translation files in DATADIR/translations/.
Syntax highlighting Weavon highlights all 194 built-in Pandoc 3.13 languages using 62 KDE language definitions (plus the shared Alerts helper) and 132 Rust definitions written for Weavon, with 0 differences across 13,986 replay cases. Use --syntax-definition FILE.xml to add custom languages.
--print-default-data-file Templates and some built-in data are available. Pandoc translation files are not. Get other files from the Pandoc distribution.
Shell completion Weavon makes its own completion scripts. None.
Limits Weavon stops with an error at limits for nesting depth, input size, table size, and archive size. Pandoc can use all memory or run without end on such input. None for normal documents.
Error messages Weavon does not print the Haskell call stack lines of Pandoc. Some JSON and YAML error texts differ. None.
Native Office round trips Same-format conversion can preserve unchanged package parts. Edited content can require regeneration. Cross-format conversion can lose Office-specific features. Check the output after a conversion that changes the document.
Embedded PDF and PDF input The embedded engine supports a subset of LaTeX. The PDF reader needs an external optical character recognition (OCR) command for scanned pages. Use lualatex for unsupported LaTeX or weavon extract --ocr CMD for scans.

Safety

Weavon treats each input as untrusted. Its readers stop at limits instead of stopping the program with a panic. The Rust code forbids unsafe code outside two crates. The weavon-lua crate permits two audited calls to the Lua C interface, and the unchanged C sources of Lua 5.4.8 and LPeg 1.1.0 are compiled into the program. The C ABI crate, weavon-c, permits audited unsafe code only where it reads and writes C pointers.

--sandbox restricts file and network access, as in Pandoc. The HTML writer is not a sanitizer, so raw HTML in the input goes to the output, as in Pandoc. SECURITY.md tells you how to report a vulnerability.

Implementation and provenance

Weavon was built with heavy use of AI coding tools, so we do not describe it as a strict clean-room implementation.

In practice, the repository contains no Pandoc Haskell source code and no Pandoc test files, and project rules forbid reading Pandoc's Haskell source. Behavior is developed against the Pandoc manual, documented interfaces, and Pandoc 3.13 run as a black-box test oracle. Pandoc runs only in the test tools, and the weavon binary never calls it.

Several companion libraries that Pandoc uses have permissive licences, and Weavon ports parts of them, including pandoc-types, doclayout, doctemplates, commonmark-hs, citeproc, skylighting-core, tagsoup, hslua, and Pandoc's BSD-3-Clause default templates. THIRD_PARTY_NOTICES.md lists each item and its licence. GPL-licensed Pandoc assets, such as reference Office documents and shell completion scripts, are excluded.

Build and test

cargo build --release -p weavon-cli
scripts/gate.sh

docs/CONTRIBUTING.md gives the rules and the test tools. docs/README.md is the index of the documentation and the repository, and docs/ARCHITECTURE.md describes the workspace crates.

Licence

Weavon is available under the MIT licence or the Apache License 2.0, at your option. Third-party material keeps its own licence, and THIRD_PARTY_NOTICES.md lists each item.

About

Drop-in Pandoc 3.13 replacement in safe Rust. 129 formats, Lua 5.4, citeproc, embedded PDF 1.7, RAG chunker, semantic diff, lint, and WebAssembly.

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0