Skip to content
aeskildsenPublic

About

Regex-based python converter from markdown to miscellaneous formats

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

md2misc

md2misc is a Python library that converts Markdown to other text formats. It finds the elements of Markdown with regular expressions and writes them in the target syntax. It is for projects that write their documentation in Markdown and need TeX or SuperCollider help files from it. It has only been tested with latin script.

Each output format is a backend:

Backend Function Documentation
TeX convert docs/tex.md
SuperCollider help (schelp) convert_schelp docs/schelp.md

Install

md2misc needs Python 3.12 or later. It uses only the Python standard library. The citations of the schelp backend need the program pandoc (see docs/schelp.md).

pip install git+https://github.com/aeskildsen/md2misc

Use

from md2misc import convert, convert_schelp

print(convert("# A title"))         # \section{A title}
print(convert_schelp("## A title")) # SECTION::A title

Both functions take a string and return a string. For example, in a CI job:

from pathlib import Path
from md2misc import convert_schelp

source = Path("docs/MyClass.md")
target = Path("Help/MyClass.schelp")

markdown = source.read_text()
schelp = convert_schelp(markdown, metadata={"class": "MyClass"})

target.write_text(schelp)

A script can also put a checkout of this repository (for example a git submodule) first on sys.path and import md2misc from it, with no installation.

Errors and warnings

All errors are subclasses of md2misc.Md2miscError:

  • UnsupportedConstruct: the output format has no form for a Markdown construct. line is the line of the construct, if known, and describe(source) gives a message with the file name, for example docs/MyClass.md:12: ....
  • DocumentError: a problem with the document as a whole, or with an argument.
  • ParsingException: badly formed Markdown, for example a list with bad indentation.

Warnings have the category md2misc.Md2miscWarning. Use the warnings module to filter them or to make them errors.

Origin

md2misc is derived from md2tex by Paul Kervegan. The full history of md2tex, with the commits of both authors, is part of the git history of this repository. The TeX output is meant to stay identical to the output of md2tex. See NOTICE.

Documentation

  • docs/tex.md: the TeX backend, the supported Markdown and the rules for lists
  • docs/schelp.md: the schelp backend, the header, the insertion points and the constructs that stop the conversion
  • CHANGELOG.md: the changes in each version
  • DEVELOPING.md: for contributors

Licence

Released under the GNU General Public License version 3 only (GPL-3.0-only). md2tex was developed by Paul Kervegan in August 2022. Later additions to md2tex were made by Anders Eskildsen, and md2misc continues from there. See NOTICE.

About

Regex-based python converter from markdown to miscellaneous formats

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages