Skip to main content

Small package for easily processing markdown files

Project description

Markie

A small project for processing markdown files with metadata.

Install

pip install markie

Note: This project is still in Alpha – significant changes are expected and features are limited

Example

from pprint import pprint

from markie import Doc

main_content = """
---
title: "Ducks: And how to Make Them Pay"
year: 1894
---

# Ducks: And how to Make Them Pay

By William Cook

Author of "The Practical Poultry Breeder and Feeder";
"The Horse: its keep and management";
"Pheasants, Turkeys, and Geese: their management for pleasure and profit"
""".strip()

chapter_1 = """
## Introduction

Not so many years ago roast duck was a luxury only for the rich, unless it 
might have been a few foreign birds sent into our markets, which could 
usually be bought up at a very low price. 
""".strip()

doc = Doc.from_md(main_content)

# content can be appended with .append, or prepended with .prepend
doc.append(chapter_1)

# Metadata can be retrieved and set
doc.metadata["authors"] = ["William Cook"]

# can be pretty printed to quickly glean the overall document structure
pprint(doc)

# Iterating over docs yields markdown-it tokens in order
# pprint([*doc])

# Docs are rendered to markdown
with open(f"{doc.metadata['title']}.md", "w") as f:
    f.write(doc.render())

The above would print:

Doc(metadata={'authors': ['William Cook'],
              'title': 'Ducks: And how to Make Them Pay',
              'year': 1894},
    preamble='',
    sections=[Section(level=1,
                      title='Ducks: And how to Make Them Pay',
                      preamble='By William Cook\n'
                               '\n'
                               'Author of "The Practical Poultry Breeder and '
                               'Feeder";\n'
                               '"The Horse: its keep and management";\n'
                               '"Pheasants, Turkeys, and Geese: their '
                               'management for pleasure and profit"',
                      subsections=[Section(level=2,
                                           title='Introduction',
                                           preamble='Not so many years ago '
                                                    'roast duck was a luxury '
                                                    'only for the rich, unless '
                                                    'it\n'
                                                    'might have been a few '
                                                    'foreign birds sent into '
                                                    'our markets, which could\n'
                                                    'usually be bought up at a '
                                                    'very low price.',
                                           subsections=[])])])

And write the following to a file "Ducks: And how to Make Them Pay.md":

---
title: 'Ducks: And how to Make Them Pay'
year: 1894
authors:
  - William Cook
---

# Ducks: And how to Make Them Pay

By William Cook

Author of "The Practical Poultry Breeder and Feeder";
"The Horse: its keep and management";
"Pheasants, Turkeys, and Geese: their management for pleasure and profit"

## Introduction

Not so many years ago roast duck was a luxury only for the rich, unless it
might have been a few foreign birds sent into our markets, which could
usually be bought up at a very low price.

Notes for Developers

Tests

Install the test requirements from tests/requirements.txt.

These tests use ApprovalTests and pytest with the ApprovalTests pytest plugin. To enable diff checking on PyCharm, see their documentation which describes how to set up a run configuration which uses PyCharm's built-in diff checker.

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

markie-0.0.1a3.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

markie-0.0.1a3-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file markie-0.0.1a3.tar.gz.

File metadata

  • Download URL: markie-0.0.1a3.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for markie-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 3bdfafaf4be9589a5737ad63e53366ab4214b0fce3a24ae1c981ab5c9aa354da
MD5 1a459b4972aa5a44752ed79cb406e289
BLAKE2b-256 f3efae5a1fd9e20afd0ab0525acaacdb6541f01ff2cbe5f087d2c149872412b3

See more details on using hashes here.

File details

Details for the file markie-0.0.1a3-py3-none-any.whl.

File metadata

  • Download URL: markie-0.0.1a3-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for markie-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 93f6da64f7254e2a5ec60fbe7ec098a059396ee9caf6ab059ccb5269f8b12d97
MD5 0c4e75e1cbbc278f14149c31e37a47bf
BLAKE2b-256 9ee1a7f3e00b71977a5ca3aae349db0eaae0a2a25c3849da33f7f6332466e240

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