A library to slice a markdown file into HTML sections.
Project description
MDSlicer
A library to slice a markdown file into HTML sections.
Installation
pip install mdslicer
Usage
A common usage when converting a markdown file to HTML is to extract a YAML header and split the markdown content into sections delimited by h2 titles. This library uses:
- the
frontmatter
library to extract metadata from the header, - the
markdown
library to parse the markdown into html and build a table of contents, - the
beautifulsoup
library to split the html into sections
Sections can then be used to generate an HTML file with a table of contents, for example using jinja2 templates:
from mdslicer import MDSlicer
from jinja2 import Template
slicer = MDSlicer(extensions=['fenced_code'])
header, sections = slicer.slice_file("README.md")
template = Template(
"""
<h1>MDSlicer</h1>
<h2>Table of contents</h2>
<ul>
{% for section in sections[1:] %}
<li><a href="#{{ section.id }}">{{ section.title }}</a></li>
{% endfor %}
</ul>
{% for section in sections %}
<section id="{{ section.id }}">
<h2>{{ section.title }}</h2>
{{ section.content }}
</section>
{% endfor %}
"""
)
html = template.render(sections=sections)
print(html)
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
mdslicer-0.3.0.tar.gz
(6.4 kB
view details)
Built Distribution
File details
Details for the file mdslicer-0.3.0.tar.gz
.
File metadata
- Download URL: mdslicer-0.3.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aac343b0f68b5c81fec35dd0acea62315abd524c06915e5f1c25c9aea943d537 |
|
MD5 | c7c83ec4efb7c1c5f584306d430e0fa3 |
|
BLAKE2b-256 | 7f260e1b3e74d015bfb6e5bdb63ed69028b1aeab3c45e083dc8f0e7fa3d83147 |
File details
Details for the file mdslicer-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: mdslicer-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32f59196adc9843e227b8e6c74979099dd7cd4021472ed362af7d1395183a562 |
|
MD5 | 6b0c8cf2143a4a3658b60024cc035cc9 |
|
BLAKE2b-256 | 0df8e205303d7941b82a541e963b0b755f0481cabecdffefb8f7e78d2bf7114b |