Metadata-Version: 2.1
Name: codeblocks
Version: 0.1.1.post1
Summary: Extract and process code blocks from markdown files.
License: Apache-2.0
Author: Alexey Shamrin
Author-email: shamrin@gmail.com
Requires-Python: >=3.7,<4.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Description-Content-Type: text/markdown

# 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

```python
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 with `await` in them
* [ ] support other languages
* [ ] use proper markdown parser
* [ ] support multiple files

# Related

* https://github.com/nschloe/excode
* https://github.com/jonschlinkert/gfm-code-blocks
* [blacken-docs][] ([does not support `black --check`][blacken-check])
* [prettier works out of the box for supported languages][prettier] ([PR][prettier-pr])

[blacken-docs]: https://github.com/asottile/blacken-docs
[blacken-check]: https://github.com/asottile/blacken-docs/issues/42
[prettier]: https://prettier.io/blog/2017/11/07/1.8.0.html#markdown-support
[prettier-pr]: https://github.com/prettier/prettier/pull/2943

