Skip to main content

Pelican plugin for converting MyST's Markdown variant to HTML.

Project description

MyST Reader: A Plugin for Pelican

Build Status pre-commit.ci status PyPI Version License

MyST Reader is a Pelican plugin that converts documents written in MyST’s variant of Markdown into HTML.

Requirements

This plugin requires:

  • Python 3.9 or higher

Installation

This plugin can be installed via:

python -m pip install pelican-myst-reader

Configuration

This plugin converts MyST’s variant of Markdown into HTML. MyST being a superset of CommonMark should cover most Markdown variants, but strictly speaking, conversion from other Markdown variants is unsupported. Converting to output formats other than HTML is also unsupported.

Specifying File Metadata

The plugin expects all Markdown files to start with a YAML-formatted content header, as shown below.

---
title: "<post-title>"
author: "<author-name>"
date: "<date>"
summary: |
  The summary (can be on more than one line)...
---

If the values of the metadata can include MyST syntax, in which case, the field name should be added to the FORMATTED_FIELDS list variable in pelicanconf.py.

⚠️ Note: The YAML-formatted header shown above is syntax specific to MyST for specifying content metadata. This maybe different from Pelican’s front-matter format. If you ever decide to stop using this plugin and switch to Pelican’s default Markdown handling, you may need to switch your front-matter metadata to Python-Markdown’s Meta-Data format.

As a compromise and in order to support both metadata formats (although this means deviating away from MyST standard), title case headers are acceptable. The advantage is that files are compatible with both MyST reader and Pelican's Markdown reader.

---
Title: "<post-title>"
Author: "<author-name>"
Date: "<date>"
---

For more information on Pelican's default metadata format please visit the link below:

Specifying MyST Options

The plugin supports passing options to MyST. This is done by configuring your Pelican settings file (e.g., pelicanconf.py):

  • MYST_EXTENSIONS

In the MYST_EXTENSIONS setting, you may enable/disable any number of the supported MyST extensions:

MYST_EXTENSIONS = [
    "amsmath",
    "dollarmath",
]
  • MYST_FORCE_SPHINX

The Sphinx renderer is automatically used if any math extension is enabled or BibTeX files are found. This setting would force Sphinx rendering for all cases which is slightly slower but has more features.

MYST_FORCE_SPHINX = True

Calculating and Displaying Reading Time

This plugin may be used to calculate the estimated reading time of articles and pages by setting CALCULATE_READING_TIME to True in your Pelican settings file:

CALCULATE_READING_TIME = True

You may display the estimated reading time using the {{ article.reading_time }} or {{ page.reading_time }} template variables. The unit of time will be displayed as “minute” for reading times less than or equal to one minute, or “minutes” for those greater than one minute.

The reading time is calculated by dividing the number of words by the reading speed, which is the average number words read in a minute.

The default value for reading speed is set to 200 words per minute, but may be customized by setting READING_SPEED to the desired words per minute value in your Pelican settings file:

READING_SPEED = <words-per-minute>

The number of words in a document is calculated using the Markdown Word Count package.

Contributing

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.

To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.

Special thanks to Justin Mayer, Erwin Janssen, Joseph Reagle and Deniz Turgut for their improvements and feedback on this plugin.

License

This project is licensed under the AGPL-3.0 license.

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

pelican_myst_reader-1.2.0b1.tar.gz (20.6 kB view hashes)

Uploaded Source

Built Distribution

pelican_myst_reader-1.2.0b1-py3-none-any.whl (20.5 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