Skip to content

jasedit/pymmd

Repository files navigation

Latest Version

Downloads

License

Code Health

pymmd

Python wrapper for MultiMarkdown, which converts MultiMarkdown flavored text into one of several outputs formats. This package directly wraps the reference implementation, and provides a simple interface to the library.

The ctypes package is used to wrap libMultiMarkdown in a portable fashion.

Installation

This package requires MultiMarkdown installed as a shared library in order to function. For Windows and macOS, the shared library is included in the distributed package.

This package can be installed via pypi:

pip install pymmd

For Linux users, the shared library can be installed by executing:

python -c "import pymmd; pymmd.build_mmd()"

Which will download, build, and install the required library within the package's directory. This may need to be run with sudo if the package is installed to a system-level site-packages directory.

Verifying the package is working as intended can be accomplished via a simple test command, which should print out the MultiMarkdown version in use:

python -c "import pymmd; print(pymmd.version())"

Examples

Converting a string of MultiMarkdown directly to various outputs:

import pymmd
# Generate string of MultiMarkdown text named data

html_output = pymmd.convert(data)
latex_output = pymmd.convert(data, fmt=pymmd.LATEX)

#Generate a snippet
html_snippet = pymmd.convert(data, ext=pymmd.SNIPPET)

Conversion can be performed with the Transclusion capabilities of MultiMarkdown, either by specifying the directory name:

with open('./document.mmd') as fp:
  src = fp.read()
output = pymmd.convert(src, dname='.')

Files can also be converted directly from file:

import pymmd

#MMD file named data.mmd

html_output = pymmd.convert_from("./data.mmd")