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

Uploaded Source

Built Distribution

mdslicer-0.1.8-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mdslicer-0.1.8.tar.gz
Algorithm Hash digest
SHA256 9733b2a2b1db8674b34d7763ab89651731ccf29c9e67df6dd83444ebaaa38b12
MD5 5b11c43639f12ba7499a3529f78970d4
BLAKE2b-256 092ed0d5fd22bd3f2dc8899518d93797914d6664aacb0d278dc7045d5d57fdbf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mdslicer-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 dcb38876787d2920b2028de78ab68219b22412e289ee12448a86a260b5549736
MD5 7ce4f47ed6471823581dd81a9bc79efb
BLAKE2b-256 686e94dfe39b27bd3d3dfefcdd32ae6f35bbfe131185f0f12789971120753b67

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