Extract and process code blocks from markdown files.
Project description
codeblocks
Extract and process code blocks from markdown files.
Examples
Extract Python code blocks:
codeblocks --python README.md
Check formatting of Python code blocks with black:
codeblocks --python README.md | black --check -
Reformat Python code blocks with black, in place:
codeblocks --python README.md -- black -
Type check Python code blocks with mypy:
mypy somemodule anothermodule <(codeblocks --python README.md)
Full type checking example
def plus(x: int, y: int) -> int:
return x + y
plus(1, '2')
$ mypy --pretty --strict <(codeblocks --python README.md)
/dev/fd/63:5: error: Argument 2 to "plus" has incompatible type "str"; expected "int"
plus(1, '2')
^
Found 1 error in 1 file (checked 1 source file)
TODO
- protect against empty (and weird?) in-place modifications
- use same regex for both modes
- example for pytest
- automatically add
async
for functions withawait
in them - support other languages
- use proper markdown parser
- support multiple files
Related
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
codeblocks-0.1.1.post1.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for codeblocks-0.1.1.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a67e5047d4932c0fcb522a3cd4a45c9ed6107e162b4199864f917d6ae5eb5a71 |
|
MD5 | 38c7f85b1ad78d70a4f156007f5046a2 |
|
BLAKE2b-256 | 91eb11e60a5afee849bde58a6a094f24115a4aa250f93fab01546d5714d48c3e |