Embed text and data into Markdown files
Project description
docsub
Embed text and data into Markdown files
[!WARNING]
- With
docsub, every documentation file may become executable.- Never use
docsubto process files from untrusted sources.- This project is in research stage, syntax and functionality may change significantly.
- If still want to try it, use pinned package version
docsub==0.5.0
Features
- Insert static files and dynamic results
- Invisible markup inside comment blocks
- Idempotent substitutions
- Configurable
- Plays nicely with other markups
[!NOTE] This file uses docsub itself. Dig into raw markup if interested.
Missing features
- Backups
- Dependency discovery
- Extensibility by end user
- Detailed logging
Use cases
- Synchronized docs for multiple targets: GitHub README, PyPI README, Sphinx docs, etc.
- Embed dynamically generated data as tables
- CLI usage examples
Non-use cases
- Not a documentation engine like Sphinx or MkDocs.
- Not a templating engine like Jinja.
- Not a replacement for Bump My Version
Installation
uv tool install docsub==0.5.0
Basic usage
$ uvx docsub -i README.md
BeforeREADME.md# Title
<!-- docsub: begin -->
<!-- docsub: include info.md -->
<!-- docsub: include features.md -->
...
<!-- docsub: end -->
## Table
<!-- docsub: begin -->
<!-- docsub: include data.md -->
<!-- docsub: lines after 2 -->
| Col 1 | Col 2 |
|-------|-------|
...
<!-- docsub: end -->
## Code
<!-- docsub: begin #code -->
<!-- docsub: include func.py -->
<!-- docsub: lines after 1 upto -1 -->
```python
...
```
<!-- docsub: end #code -->
info.md> Long description.
features.md* Feature 1
* Feature 2
* Feature 3
data.md| Key 1 | value 1 |
| Key 2 | value 2 |
| Key 3 | value 3 |
func.pydef func():
pass
|
AfterREADME.md# Title
<!-- docsub: begin -->
<!-- docsub: include info.md -->
<!-- docsub: include features.md -->
> Long description.
* Feature 1
* Feature 2
* Feature 3
<!-- docsub: end -->
## Table
<!-- docsub: begin -->
<!-- docsub: include data.md -->
<!-- docsub: lines after 2 -->
| Col 1 | Col 2 |
|-------|-------|
| Key 1 | value 1 |
| Key 2 | value 2 |
| Key 3 | value 3 |
<!-- docsub: end -->
## Code
<!-- docsub: begin #code -->
<!-- docsub: include func.py -->
<!-- docsub: lines after 1 upto -1 -->
```python
def func():
pass
```
<!-- docsub: end #code -->
|
Substitution block
<!-- docsub: begin -->
<!-- docsub: help docsub -->
<!-- docsub: include CHANGELOG.md -->
Inner text will be replaced.
<!-- docsub: this whole line is treated as plain text -->
This text will be replaced too.
<!-- docsub: end -->
Each block starts with begin and ends with end. One or many commands come at the top of the block, otherwise they are treated as plain text. Blocks without producing commands are not allowed. Block's inner text will be replaced upon substitution, unless modifier command lines is used.
If docsub substitution block leis inside markdown fenced Code block, it is not substituted (examples: fenced code blocks right above and below). To put dynamic content int fenced code block, place begin and end around it and use lines after 1 upto -1 (example: Basic usage section).
For nested blocks, only top level substitution is performed. Use block #identifier to distinguish nesting levels.
<!-- docsub: begin #top -->
<!-- docsub: include part.md -->
<!-- docsub: begin -->
<!-- docsub: include nested.md -->
<!-- docsub: end -->
<!-- docsub: end #top -->
Commands
- Block delimiters:
begin,end - Producing commands:
exec,help,include - Modifying commands:
lines,strip
begin
begin [#identifier]
Open substitution target block. To distinguish with nested blocks, use #identifier starting with #.
end
end [#identifier]
Close substitution target block.
exec
exec arbitrary commands
Execute arbitrary commands with sh -c and substitute stdout. Allows pipes and other shell functionality. If possible, avoid using this command.
Config options:
workdir— shell working directory, default'.'env— additional environment variables dict, default{}
help
help command [subcommand...]
help python -m command [subcommand...]
Display help for CLI utility or Python module. Use this command to document CLI instead of exec. Runs command args --help or python -m command args --help respectively. command [subcommands...] can only be a space-separated sequence of [-._a-zA-Z0-9] characters.
Config options:
env— additional environment variables dict, default{}
include
include path/to/file
Literally include file specified by path relative to workdir config option.
Config options:
basedir— base directory for relative paths
lines
lines [after N] [upto -M]
Upon substitution, keep original target block lines: first N and/or last M. Only one lines command is allowed inside the block.
strip
strip
Strip trailing whitespaces on every line of substitution result; strip initial and trailing blank lines of substitution result.
Configuration
Configuration resolution order
- environment variables (to be documented)
.docsub.tomlconfig file in current working directorypyproject.toml, section[tool.docsub](to be implemented)- default config values
Structure
All config keys are optional.
[command.exec]
env = {} # default
workdir = "." # default
[command.help]
env = { COLUMNS = "60" }
[command.include]
basedir = "." # default
[logging]
# level = "DEBUG" # default: missing value
[!WARNING] In future releases config keys will be moved under
[tool.docsub]root, this will be a breaking change.
Environment variables
(to be documented)
Logging
Docsub uses loguru for logging. Logging is disabled by default. To enable logging, set config option log_level to one of logging levels supported by loguru.
(logging is rudimentary at the moment)
CLI Reference
$ docsub --help
Usage: python -m docsub [OPTIONS] [FILE]...
Update documentation files with external content.
╭─ Options ────────────────────────────────────────────────╮
│ --in-place -i Overwrite source files. │
│ --version Show the version and exit. │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────╯
History
This project appeared to maintain docs for multipython project. You may check it up for usage examples.
Authors
License
Changelog
Check repository CHANGELOG.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docsub-0.5.0.tar.gz.
File metadata
- Download URL: docsub-0.5.0.tar.gz
- Upload date:
- Size: 53.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e6cec7e7e4eb37fd58a76f5a8cb7ae5c27d0d3acf8f9dde5c8178519fc8537b
|
|
| MD5 |
4c42b35855afded67f975d4ab0e8e227
|
|
| BLAKE2b-256 |
abe963b25561faf1f4feab96f044c516ba0084fbc6c0ad216b2fad907355e2d9
|
File details
Details for the file docsub-0.5.0-py3-none-any.whl.
File metadata
- Download URL: docsub-0.5.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d972f4f53653281db67e48c946ec8e258665985b6af43c32717788cc955074f
|
|
| MD5 |
987ef7adbbe63aff1ed83e4340e076cb
|
|
| BLAKE2b-256 |
a5dfbd20617b679f54a561136d8bf9db2e8081a2d4fd89860b2b8fc91e7fb06b
|