justinmeiners / srcweave

A literate programming system for any language.
https://www.jmeiners.com/literate-programming/
GNU General Public License v2.0
85 stars 4 forks source link
common-lisp documentation-generator documentation-tool hacktoberfest knuth literate-programming markdown

srcweave

srcweave is a literate programming system for ANY programming language. srcweave helps you write code to be read by humans, not machines.

Features:

.lit file examples

The best part about .lit is you learn it by just reading the code! Here are a few basic examples to get started with:

For more in-depth examples, see my article:

Getting started

Requirements

Install

Clone the project and run the following:

make
make install

Usage

  1. Create an index.lit file. For example:

    # Test
    
    Test console output:
    
    --- hello.js
    console.log("Hello, World!");
    ---
  2. Run srcweave --tangle . index.lit to generate source files (hello.js).

  3. Run srcweave --weave doc/ index.lit to generate documentation (index.html).

Both --tangle and --weave can be included in the same invocation. Multiple lit files can be specified, and the order they are listed in will determine the order of chapters and sections across files.

Styling

Included in the installation is a tool called srcweave-html-styler which converts default HTML into beautiful documents. To use just add the --style srcweave-html-styler to any weave command. For example:

srcweave --weave doc/ --styler srcweave-html-styler index.lit

Once for every project, you will also need to run:

srcweave-html-styler-init docs/

This downloads all the necessary JavaScript and CSS dependencies.

Math typesetting

Include the -m flag on srcweave-html-styler-init to download KaTex. See the examples for how to use TeX in .lit.

Custom styles

An easy way to customize the style is to edit the CSS file created by srcweave-html-styler-init. If that's insufficient, you are encouraged to create your own styler program. Stylers are just programs that take raw HTML in stdin and format it to stdout. You can start from scratch, or you can modify a copy of srcweave-html-styler.

Comparison with Literate

srcweave is inspired by Zach Yedidia's Literate. I like his program, have used it for several years, and am grateful for his contribution. However, I have since developed my own preferences and ideas for improvement:

The vim plugin should be compatible.

Known incompatibilities:

You can migrate files from Literate with only minor changes. Here are the important differences:

Acknowledgments

We are very grateful to all our contributors:

License

GPL 2