markdown Module

Tools for parsing and manipulating markdown, including a very basic tokenizer.

Parses and removes any links from the input string


text – An input string which may be a markdown link, either literal or an ID


A tuple of (name, url, id). If the input is not a link, it is returned verbatim as the name.

join(segments: List[str])str

Joins multiple lines of markdown by adding double newlines between them, or a single newline between list items


segments – A list of strings to join


A joined markdown string

class Token(line_no: int, lines: List[str], kind: str)

A single tokenized block of markdown, consisting of one or more lines of text.


Which line this block appears on in the original file


The lines of text making up this block


What kind of token this is. One of h[1-6], p, li or code

tokenize(text: str)

Tokenize a markdown string

The tokenizer is very basic, and only cares about the highest-level blocks (Headers, top-level list items, links, code blocks, paragraphs).


text – input text to tokenize


A list of tokens and a dictionary of links