Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Formats poetry in Markdown

Project description

## Install

pip install mdx_poetic

## Usage

import markdown
from mdx_poetic import PoeticExtension

md = """
This is just some normal text that is prose. It might have some _markdown_.


this is a
line of a poem

and this is _another_
stanza of a poem that has a really long line which will wrap
and more **markdown** in it


And then this is some **more** markdown that follows.

print(markdown.markdown(md, extensions=[PoeticExtension()]))

Running that will give you an output like this:

<p>This is just some normal text that is prose. It might have some <em>markdown</em>.</p>
<p><blockquote class="mdx-poem"><p class="mdx-peom--stanza">
<span class="mdx-poem--line">this is a<br></span>
<span class="mdx-poem--line">line of a poem<br></span>
</p><p class="mdx-poem--stanza">
<span class="mdx-poem--line">and this is <em>another</em><br></span>
<span class="mdx-poem--line">stanza of a poem that has a really long line which will wrap<br></span>
<span class="mdx-poem--line">and more <strong>markdown</strong> in it<br></span>
<p>And then this is some <strong>more</strong> markdown that follows.</p>

But that won't be too useful without the help of some CSS:

.mdx-poem {
margin-top: 1rem;

.mdx-poem--stanza {
margin-top: 1rem;

.mdx-poem .mdx-poem--line {
margin: 0 0 0 40px;
text-indent: -20px;
padding: 0;
display: block;

This will give you a nice clean result where `<blockquote class="mdx-poem">` will be indented slightly, you get a line in between stanzas, and any wrapped lines will be indented under the beginning of the line:


Using `<blockquote>` and `<p>` tags with `<span><br></span>` was chosen intentionally to properly format in console RSS readers like [`newsboat`]( Further testing might be necessary for visual compatibility with other readers as well the above is most accurate syntactically to the intended output.

### Developent

For pushlishing to PyPi:

python3 sdist bdist_wheel
twine upload dist/*

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mdx-poetic, version 0.8
Filename, size File type Python version Upload date Hashes
Filename, size mdx_poetic-0.8-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mdx_poetic-0.8.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page