Generates ('tangles') source code from Markdown documents
Project description
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 easily be utilized by adding md-tangle
to your PATH
, or by installing the package with pip
.
See the package on pypi.org, or just install with pip install md-tangle
.
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.
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-s
/--separator
: Separator for tangle destinations (default=',')
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;
}
~~~~
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
Documentation
The documentation for md-tangle
is of course written in Markdown, and tangles to the source
code.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file md_tangle-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: md_tangle-1.3.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9039fad0888d7a331d41fb11d0c648d7aa005ba82eb31663d8aab2824ba802d6 |
|
MD5 | 0a7b40443ed77a4619eabe59c7508d9a |
|
BLAKE2b-256 | 3601285181f9bf6e6d056d4c636d7075d8ae034a701285992bee3f2068820a17 |
File details
Details for the file md_tangle-1.3.1-py2-none-any.whl
.
File metadata
- Download URL: md_tangle-1.3.1-py2-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 758af1f214689398a3cbb4cf38c3d17e0929a86bd64e14e5f5bd3f24dd417105 |
|
MD5 | 22ed381550d104421b83c9336356ae55 |
|
BLAKE2b-256 | 09ad09f3d8fe954eb44db170220e07f1d495404b5e246bcda359df547d688e4c |