Skip to main content

Formats poetry in Markdown

Project description

## Install

```
pip install mdx_poetic
```

## Usage

````python
import markdown
from mdx_poetic import PoeticExtension

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

```poem

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:

```html
<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></blockquote></p>
<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:

```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:


![example](https://github.com/nickwynja/mdx_poetic/raw/master/example.png)

Using `<blockquote>` and `<p>` tags with `<span><br></span>` was chosen intentionally to properly format in console RSS readers like [`newsboat`](https://newsboat.org/). 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 setup.py 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.

Source Distribution

mdx_poetic-0.8.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

mdx_poetic-0.8-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file mdx_poetic-0.8.tar.gz.

File metadata

  • Download URL: mdx_poetic-0.8.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for mdx_poetic-0.8.tar.gz
Algorithm Hash digest
SHA256 6c8bf5f06a3389478546ea130997a22d507f4877ec8b7ab47ab1b7144f3dec38
MD5 8a103609ec981a93996fa2ae78f31b6f
BLAKE2b-256 4525ba4906f4dce1fde3ea685f29a8a8f48d875eb3abbc4962210be25d51d424

See more details on using hashes here.

File details

Details for the file mdx_poetic-0.8-py3-none-any.whl.

File metadata

  • Download URL: mdx_poetic-0.8-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for mdx_poetic-0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 18eefc2c149e6788607e2d338670794c028b763f5aac049d131ffe4f796413df
MD5 d9aad9cb6612d97ed7ce0af13738e7c0
BLAKE2b-256 fb51d101e2b3c6e7231cb66dd9ae54aa03afae524e02d1a700cb4e303819d29d

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