https://github.com/asottile/markdown-code-blocks
Generate html from markdown with code-block highlighting
https://github.com/asottile/markdown-code-blocks
Last synced: 2 months ago
JSON representation
Generate html from markdown with code-block highlighting
- Host: GitHub
- URL: https://github.com/asottile/markdown-code-blocks
- Owner: asottile
- License: mit
- Created: 2017-03-14T04:21:23.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-03-31T21:00:17.000Z (3 months ago)
- Last Synced: 2025-05-03T13:42:27.808Z (2 months ago)
- Language: Python
- Size: 232 KB
- Stars: 4
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/asottile/markdown-code-blocks/actions/workflows/main.yml)
[](https://results.pre-commit.ci/latest/github/asottile/markdown-code-blocks/main)markdown-code-blocks
====================A stupid simple bit of code which combines [mistune][mistune] and
[pygments][pygments] to convert markdown into html. Very similar to github
markdown, but for python.## Installation
```bash
pip install markdown-code-blocks
```## Usage
The library provides a single function `highlight` which takes in a markdown
string and returns html.You can also use the cli `markdown-code-blocks-highlight`. It optionally
takes a single filename (defaulting to stdin) and writes to stdout.For example:
`markdown-code-blocks-highlight f.md > f.htm`
## pygments css
I'd suggest grabbing a theme file from [pygments-css][pygments-css]
(or any other provider of pygments themes -- if you google there's a bunch of
them).This library will use the class `.highlight` so be sure to change out whatever
class the theme uses with that.Most themes (for whatever reason) don't add styles for diff display. I
usually do something like this:```css
.highlight .gi { color: #070; }
.highlight .gd { color: #911; }
```[mistune]: https://github.com/lepture/mistune
[pygments]: http://pygments.org/
[pygments-css]: https://github.com/richleland/pygments-css