Skip to main content

Extract and process code blocks from markdown files.

Project description


Extract and process code blocks from markdown files.


Extract Python code blocks:

codeblocks --python

Check formatting of Python code blocks with black:

codeblocks --python | black --check -

Reformat Python code blocks with black, in place:

codeblocks --python -- black -

Type check Python code blocks with mypy:

mypy somemodule anothermodule <(codeblocks --python

Full type checking example

def plus(x: int, y: int) -> int:
    return x + y

plus(1, '2')
$ mypy --pretty --strict <(codeblocks --python
/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)


  • <input type="checkbox" disabled="" /> protect against empty (and weird?) in-place modifications
  • <input type="checkbox" disabled="" /> use same regex for both modes
  • <input type="checkbox" disabled="" /> example for pytest
  • <input type="checkbox" disabled="" /> automatically add async for functions with await in them
  • <input type="checkbox" disabled="" /> support other languages
  • <input type="checkbox" disabled="" /> use proper markdown parser
  • <input type="checkbox" disabled="" /> support multiple files


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for codeblocks, version 0.1.1.post1
Filename, size File type Python version Upload date Hashes
Filename, size codeblocks-0.1.1.post1-py3-none-any.whl (7.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size codeblocks-0.1.1.post1.tar.gz (6.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page