Skip to main content

MDSlicer

pipeline status cov Latest Release Doc

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)

Metadata

Release files for mdslicer 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdslicer 0.3.1
File Size Uploaded Provenance Actions
mdslicer-0.3.1.tar.gz 6.4 kB Without provenance Details for mdslicer-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mdslicer 0.3.1
File Interpreter ABI Platform Actions
mdslicer-0.3.1-py3-none-any.whl Python 3 none any Details for mdslicer-0.3.1-py3-none-any.whl

Total release size: 11.5 kB

Release files / mdslicer-0.3.1.tar.gz

Download URL mdslicer-0.3.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
356f11dcee38a3c0e281faf4b9c7ec92c1e86574857673fd192912dba9ca8a09
BLAKE2b-256 checksum
How to use checksums
a851feb092f7c1eabeb1c744b9cff8fda16cee46deb9680ba64e77b827becb73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / mdslicer-0.3.1-py3-none-any.whl

Download URL mdslicer-0.3.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
095b0247ad3f10c7912a6d627d56e32a17faa44fc5ad60c008330cedcf466824
BLAKE2b-256 checksum
How to use checksums
7548e824502529367e16ee50970d3f33ecb9d588c438dc234c5350a0249a5bcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Security for mdslicer 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page