Markup interface

The main class for interacting with markups is AbstractMarkup.

However, you shouldn’t create direct instances of that class. Instead, use one of the standard markup classes.

class markups.abstract.AbstractMarkup(filename=None)

Abstract class for markup languages.

Parameters

filename (str) – optional name of the file

attributes = {}

various attributes, like links to website and syntax documentation

static available()
Returns

whether the markup is ready for use

(for example, whether the required third-party modules are importable)

Return type

bool

convert(text)
Returns

a ConvertedMarkup instance (or a subclass thereof) containing the markup converted to HTML

Return type

ConvertedMarkup

default_extension = ''

the default file extension

file_extensions = ()

indicates which file extensions are associated with the markup

name = ''

name of the markup visible to user

When AbstractMarkup’s convert() method is called it will return an instance of ConvertedMarkup or a subclass thereof that provides access to the conversion results.

class markups.abstract.ConvertedMarkup(body, title='', stylesheet='', javascript='')

This class encapsulates the title, body, stylesheet and javascript of a converted document.

Instances of this class are created by AbstractMarkup.convert() method, usually it should not be instantiated directly.

get_document_body()
Returns

the contents of the <body> HTML tag

Return type

str

get_document_title()
Returns

the document title

Return type

str

get_javascript(webenv=False)
Returns

one or more HTML tags to be inserted into the document <head>.

Return type

str

Parameters

webenv (bool) – if true, the specific markups may optimize the document for being used in the World Wide Web (for example, a remote version of MathJax script can be inserted instead of the local one).

get_stylesheet()
Returns

the contents of <style type="text/css"> HTML tag

Return type

str

get_whole_html(custom_headers='', include_stylesheet=True, fallback_title='', webenv=False)
Returns

the full contents of the HTML document (unless overridden this is a combination of the previous methods)

Return type

str

Parameters
  • custom_headers (str) – custom HTML to be inserted into the document <head>

  • include_stylesheet (bool) – if false, the stylesheet will not be included in the document <head>

  • fallback_title (str) – when impossible to get the <title> from the document, this string can be used as a fallback

  • webenv (bool) – like in get_javascript() above