A command-line utility written in Rust that converts Rocq files (.v) to Markdown (.md).
rocq2md converts Rocq files to Markdown by transforming block comments to text and Rocq code to Markdown code blocks.
- Rust 1.86.0 or later.
- Cargo (comes with Rust).
git clone https://github.com/matematiflo/rocq2md.git
cd rocq2md
cargo buildThe program can be run directly after cloning (no build necessary) or as a local or global executable.
The program can be run directly using cargo run -- <arguments>. A test file sample.v is provided.
cargo run -- test_files/sample.vAfter building an executable, you can run it as follows. Use either
cargo build
./target/debug/rocq2md <arguments> or (for an optimized executable)
cargo build --release
./target/release/rocq2md <arguments>If you want to add rocq2md to your Rust environment, install the package globally as follows.
cargo install --path .Check installation:
rocq2md --versionCheck location (should be ~/.cargo/bin):
which rocq2mdAlternatively, you can use cargo to install the package directly from crates.io.
rocq2md can convert single files or all Rocq files in a specified source directory (including its subfolders). For single files, you can specify the target (location and name). For directories, you can specify the target directory (which is created automatically if not already present).
rocq2md <file.v> # converts <file.v> to <file.md>
rocq2md <src_dir> # converts all Rocq files in <src_dir> to Markdown files
rocq2md <file.v> <new_name.md> # converts <file.v> to <new_name.md> (subfolders allowed)
rocq2md <src_dir> <tgt_dir> # converts all Rocq files from <src_dir>; puts them in <tgt_dir>Examples you can run in this repo:
rocq2md test_files/sample.v
rocq2md test_files/sample.v converted_files/sample.md
rocq2md test_files
rocq2md test_files converted_files- Converts top-level Rocq comments
(* ... *)to Markdown text. - Puts Rocq code inside
```rocqcode fences. - Preserves directory structure from source to target.
- Nested folders are also processed.
- Any text enclosed between
--#--symbols is removed from the generated markdown file. - A
(* ... *)comment is converted to Markdown only if the(*appears strictly at the beginning of a line (column 0) and the comment is not contained inside a proof environment. - In nested comments
(* (* ... *) ... *), only the outermost delimiters are stripped. - Comments that are not converted generate a warning during conversion. The reason for the warning is logged into the
rocq2md.logfile (in the absence of any warning, no log file is created). - Comments contained in a proof (are not converted and) do not generate a warning. The total number of warnings is printed to the console after conversion.
The test file sample.v
(* # Factorial
Let us introduce the factorial function. --#-- side comment, removed from comversion ---#-- It is defined recursively. *)
Fixpoint fact (n : nat) := (* not converted: inline trailing comment *)
match n with
| 0 => 1
| S n' => n * fact n' (* note the role of `n'` here --#-- extra note: this comment should be removed --#-- *)
end.
(* not converted: does not start at columnn 0 *)
Compute fact 5.
Lemma fact_succ (n' : nat) : fact (S n') = S n' * fact n'.
Proof.
reflexivity.
(* the proof holds by reflexivity --#-- this comment is inside a proof and is not converted to text --#-- *)
Qed.is converted to
# Factorial
Let us introduce the factorial function. It is defined recursively.
```rocq
Fixpoint fact (n : nat) := (* not converted: inline trailing comment *)
match n with
| 0 => 1
| S n' => n * fact n' (* note the role of `n'` here *)
end.
(* not converted: does not start at columnn 0 *)
Compute fact 5.
Lemma fact_succ (n' : nat) : fact (S n') = S n' * fact n'.
Proof.
reflexivity.
(* the proof holds by reflexivity *)
Qed.
```and produces the following message.
Converting test_files/sample.v to test_files/sample.md
3 warning(s): 3 unconverted comment(s) and 0 unclosed comment(s); see rocq2md.log for details.
Note: 3 block(s) ignored due to --#-- markers.Text placed between two --#-- markers inside a converted comment block is removed from the Markdown output, along with the markers themselves. This works both inline (on a single line) and as a block spanning multiple lines:
(* Keep this. --#-- Remove this internal note. --#-- Keep this too.
--#--
This whole paragraph is removed as well.
--#--
Kept again. *)src/rocq2md_core.rs: Parsing and converting rules.src/lib.rs: Library interface that exports public functions.src/main.rs: Command-line interface.
You can install rocq2md from crates.io:
cargo install rocq2mdThis will install the package in your ~/.cargo/bin directory, making it available in your PATH.
Alternatively, you can install your locally built version:
cargo install --path .Unit tests are located in src/rocq2md_core.rs and cover comment conversion, column-0 detection, proof-environment detection, nested comments, and the --#-- marker.
# Run all tests
cargo test- arthurpaulino/lean2md, the original Lean to Markdown conversion tool, written in Python.
- Seasawher/mdgen, based on
lean2mdand written in Lean (to generate documentation directly inside a Lean project). - fosterfarrell9/lean2md, based on
mdgenand written in Rust.
This software is published under an MIT License.
To contribute, open an issue or submit a pull request.