Skip to main content

app-badge Version License Format PyVer Downloads

md-tangle

This project is a result of wanting config and setup files to be part of a document explaining my setup. I originally used Org-mode and org-babel-tangle in Emacs to achieve this. I really like Org-mode and Emacs, but I'm not fond of being dependent on one editor. This is the reason I wanted a CLI, and a more widely used document markup language.

This way of programming is called literate programming. This programming paradigm was introduced by Donald Knuth. The idea is to write a program as an explanation of the program logic in a natural language interspersed with snippets of traditional source code. The source code can then be generated ("tangled") by using some tool.

As Markdown is used by most programmers, I saw that language fit for the task. Markdown is a plaintext-ish format popular with programmers. It's simple, easy and already has support for embedding code blocks using ``` or ~~~~, mostly for the purposes of syntax highlighting in documentation.

Installing

This CLI tool can be installed from PyPI using pip.

pip install md-tangle

For local development, you can install it in editable mode:

pip install -e .

[!TIP] Also exists as Neovim plugin, see md-tangle.nvim.

Command

By adding the keyword tangle:<path/filename>, this tool will tangle tagged code blocks to given file. Supports ~ for home directory.

One can tangle the code block to multiple files by separating the files with chosen separator (default: ,).

If the file already exists, the user will be prompted with the option to overwrite, unless the -f/--force flag is added.

Tags

By adding the keyword tags:<tag> to a tangled code block, it will NOT be included in the resulting files if not included with the -i/--include flag.

Flags

  • -h/--help: Show help message and exit
  • --version: Show installed version
  • -f/--force: Force overwrite of files if the already exists
  • -v/--verbose: Show output
  • -d/--destination: Overwrite output destination
  • -i/--include: Include tagged code blocks (separator=',')
  • -s/--separator: Separator for tangle destinations (default=',')
  • -p/--block-padding: Add N newlines between code blocks when writing to file (default=0)

Usage

Take the following example:

HelloWorld.md

# Some title
Describing the following code... bla bla.

~~~~javascript tangle:helloWorld.js
console.log("Hello, ");
console.log("world");
~~~~

## Styling
Adding header for my css files:

~~~~css tangle:styles/button.css,styles/input.css
/* Styling for mye awesome app */
~~~~

By adding some css ... 

~~~~css tangle:styles/button.css
#button1 {
    border: none;
}
~~~~

~~~~css tangle:styles/input.css
#button1 {
    border: none;
}
~~~~

~~~~css tangle:styles/theme.css tags:theme
#button1 {
    border-color: red;
}
~~~~

By installing md-tangle with pip, one could simply produce files from this file by executing:

$ md-tangle -v HelloWorld.md 
helloWorld.js                                      2 lines
styles/button.css                                  4 lines
styles/input.css                                   4 lines
$ ls 
helloWorld.js HelloWorld.md styles

If you also want to include tagged code blocks, you can run

$ md-tangle -v -i theme HelloWorld.md
helloWorld.js                                      2 lines
styles/button.css                                  4 lines
styles/input.css                                   4 lines
styles/theme.css                                   3 lines
$ ls
helloWorld.js HelloWorld.md styles

Copying files

There is also support for copying files. This can be used for e.g. copying some assets to your project/dotfiles.

<!-- TANGLE_CP:../assets/background.png tangle:~/.config/wezterm/background.png -->

Documentation

The documentation for md-tangle is of course written in Markdown, and tangles to the source code.

Metadata

Release files for md-tangle 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for md-tangle 2.1.2
File Size Uploaded
md_tangle-2.1.2.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for md-tangle 2.1.2
File Interpreter ABI Platform
md_tangle-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / md_tangle-2.1.2.tar.gz

Download URL md_tangle-2.1.2.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7407f272d49d6242694cc7d640fd41ab77bbfede5b938f62e685089e1f4af170
BLAKE2b-256 checksum
How to use checksums
121abedad067fc924f0078efcf8b6d63c4588f69555c09de95045148e77e4d88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / md_tangle-2.1.2-py3-none-any.whl

Download URL md_tangle-2.1.2-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f9b0a026a115bbcbbfd8ce5eb723c97ecf4e1c4eecc2846dba9c765b4a1c511
BLAKE2b-256 checksum
How to use checksums
a48a182d28631f3920981ab5da803f5636d1fbfab63211754929e6e5c9a0d313
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page