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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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