This is a command-line tool for processing Markdown files and BibTeX bibliographies. It corrects the Markdown (based on Streamdown.ai) which is useful for collaboration through loro.dev, loro-extended or with AI, it finds citation keys in the Markdown file, and appends a formatted bibliography at the end.
The tool takes a Markdown file, a BibTeX file, a CSL (Citation Style Language) file, and a locale file as input. It parses the Markdown file to find citation keys in the format [@LastnamefirstauthorLasttwodigitsofyearOptionalletterfromatoz]. The last letter is optional (no letter same as 'a'), with the order determined by the year and then the alphabetic order of the titles corresponding to the same Lastnamefirstauthor (exact name without approximations) and Lasttwodigitsofyear.
The author's last name only needs to be approximately correct (useful for dealing with foreign characters) It then uses the BibTeX file to find the corresponding bibliographic entries. Finally, it formats the bibliography according to the CSL style and appends it to the Markdown file.
To use the tool, you need to provide the paths to the four input files:
cargo run -- --markdown <path/to/markdown.md> --bibtex <path/to/bib.bib> --csl <path/to/style.csl> --locale <path/to/locale.xml>This will print the processed Markdown to standard output.
To build the project, you need to have the Rust toolchain installed. You can then build it using Cargo:
cargo build --releaseThe executable will be in target/release/markdown_bib_processor.
This project can also be compiled to a WebAssembly target.
To build for the wasm32-wasip1 target, run:
cargo build --target=wasm32-wasip1After building, you can run the Wasm module using a Wasm runtime like wasmer:
wasmer run markdown_bib_processor.wasm --mapdir /:. -- --markdown md.md --bibtex bib.bib --csl chicago.csl --locale locales-en-US.xmlThis makes the tool portable and capable of running in various environments that support WebAssembly.
This project uses the following Rust crates:
clap: For parsing command-line arguments.hayagriva: For formatting the bibliography.nom-bibtex: For parsing the BibTeX file.regex: For finding citation keys in the Markdown file.levenshtein: For finding the closest match for a citation key.linked-hash-map: To preserve the order of the bibliographic entries.serde: For serialization.once_cell: For one-time initialization of static values.