lit2md
v0.1.0
published 6 days ago
1 stars
0 forks
0 watchers
Apache License 2.0
public
1 assets
18 downloads
25 KB
Maintained byFilip Filmar
v0.1.0
September 19, 2025
[expand for release notes]

lit2md: a literate program converter from code to Markdown

Test status Publish on Bazel Central Registry status Publish to my Bazel registry status

lit2md is a simplistic literate programming (LP) converter. It takes a source code file annotated with special "literate" programming comments, and outputs a markdown file in which the literate programming comments are converted into markdown text, and code is converted into code blocks.

Example

For example, consider the simplistic hello.cc

//] # An example Hello World program.
//]
//] Don't forget headers!
#include <iostream>

//] And now, the rest of the code here:
int main() {
		std::cout << "Hello world" << std::endl;
		exit(0);
}

Running:

lit2md --input=hello.cc --output=hello.cc.md  # enclosed

produces this output.

To see a minimal usage example, check out the self-referential integration repo.

It could be argued that such a converter could be useful in preparing explanatory documents about existing code. Now, a Markdown file is not extremely useful in itself, but in combination with other typesetting software could prove to be interesting for preparing documents with a fancier layout than shown here.

Finally, the program itself, and its test, can be viewed in their literate programming forms.

Purpose

LP can be done to various levels of sophistication. lit2md does the very basic massaging of source text.

It is not intended to be used as a stand-alone program. Rather it is intended to be used as a front-end to a more sophisticated documentation processor, such as pandoc. An example of use of a similar program is the instructive website for programmable digital logic designers, https://fpgacpu.ca.

Prerequisites

  • bazel to build.

Everything else is downloaded automatically.

Build

bazel build //...

Test

bazel test //...

Run

bazel run //cmd/lit2md -- --help

Q&A

Why not reuse the v2h.py script from https://fpgacpu.ca/fpga/v2h.py?

  • It works with python only,
  • It works with Verilog only,
  • It outputs HTML only.

I wanted a tad bit more freedom of choice (since I rarely code straight-up Verilog).

Why not use doxygen?

Doxygen is great, but its purpose is to provide user documentation. Literate programs are intended to explain the code instead.

References

  • https://fpgacpu.ca/fpga/v2h.py: direct inspiration for this program. I rewrote it in go, because it is then easy to distribute as a small self-contained binary.