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
frontmatterlibrary to extract metadata from the header, - the
markdownlibrary to parse the markdown into html and build a table of contents, - the
beautifulsouplibrary 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)
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.1.tar.gz
(6.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdslicer-0.3.1.tar.gz.
File metadata
- Download URL: mdslicer-0.3.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
356f11dcee38a3c0e281faf4b9c7ec92c1e86574857673fd192912dba9ca8a09
|
|
| MD5 |
f3f2de79ddd3b8730661936493e8c1ab
|
|
| BLAKE2b-256 |
a851feb092f7c1eabeb1c744b9cff8fda16cee46deb9680ba64e77b827becb73
|
File details
Details for the file mdslicer-0.3.1-py3-none-any.whl.
File metadata
- Download URL: mdslicer-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
095b0247ad3f10c7912a6d627d56e32a17faa44fc5ad60c008330cedcf466824
|
|
| MD5 |
f3d693d66aa3dd33b39acd1470b3cc81
|
|
| BLAKE2b-256 |
7548e824502529367e16ee50970d3f33ecb9d588c438dc234c5350a0249a5bcf
|