Skip to main content

A library to slice a markdown file into HTML sections.

Project description

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)

Project details


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.2.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

mdslicer-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file mdslicer-0.2.0.tar.gz.

File metadata

  • Download URL: mdslicer-0.2.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for mdslicer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b6ed4060f2126d8ae3388489809a19dc53cb692c1a2b4b01954ff261f040839b
MD5 d9d3d56b3e332d843d30e4bbbbcda9d7
BLAKE2b-256 8a87d783d13fba668400d28e1b129fd6f1153c840d5041a9f20dc5db2bffd650

See more details on using hashes here.

File details

Details for the file mdslicer-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mdslicer-0.2.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

Hashes for mdslicer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a32df65e9bec3365843c3ac29a558b3ef09882a9cb6047cf3e31f601e8ec44d6
MD5 3aa23f913a83f24f0697b69922a326f1
BLAKE2b-256 5c9554726d2a3397f88dda531d37b77b500661e981c5b79ae33832f78effaee7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page