The core converter.

class mdiocre.core.MDiocre(parser=None, parser_name=None)

Main class to process Markdown source files and render HTML files.

  • parser (Optional) – a BaseParser-derived object. If both parser_name and parser are defined, parser takes the priority.

  • parser_name (Optional) – The parser name. See switch_parser() for which ones are currently implemented.

process(string, ignore_content=False)

Process a string into a variable dictionary to use e.g. with render().

The string is processed according to a parser that converts it to HTML and extracts any MDiocre “commands”. For Markdown and HTML, these are stuff that is prefixed with <!–:, for RST, it’s :mdiocre:.

More details about the conversion process can be found in VariableManager.

As of 3.1, this is really a wrapper for all the parsers.

  • string (string) – A string containing MDiocre commands.

  • ignore_content (bool, Optional) – If True, it will not convert the string to the content variable.


A VariableManager object containing the processed variables, that also contains the converted HTML under the content variable, if ignore_content is False.

render(template, variables)

Renders a template with the specified variables.

Due to the mechanism, template variables are separate from the page’s variables. The converted page is defined in the content variable, and can be used by templates to render the documents.

  • template (string) – A string containing formatted comments.

  • variables (VariableManager) – Variable object to use with the template.


The processed string.

sub_func(match, v)

Moved to mdiocre.parsers.sub_func(). Will remove in MDiocre 3.2.


Switch parsers by using an identifier. To implement a new parser, it must be a class with inherited from BaseParser, Its name and file name must also match, e.g. a parser with the html identifier must be in and have the class name of HtmlParser.


name (string) – Parser name. Currently implemented: markdown, html, rst



Variable Manager

This stores information that can be set and or replaced in a text.

class mdiocre.core.VariableManager

Variable manager.

Variables are stored as a dictionary under self.variables. The identifiers can be any character except the = operator, which serves to separate the identifier and the value.


There are a few reserved variables, which their names cannot be used, namely:
  • content : The contents of a page that will be put into a template

  • mdiocre-gen-timestamp : Timestamp of the generated content


The mdiocre-template variable is required when using the Wizard.


Assigns a variable to a value.

The variable name has almost no limitations (especially not limitations usually posed by a programming language), but it is terminated by the = symbol.

The value can be one of the following:
  • Stringif the value has quotes (single or double) around it.

    Example query: My Variable = "Toast"

  • Concatenationif two or more variable names are specified, with a comma separating each.

    Example query: My Variable = Var 1, Var 2

  • Math expressionif the value is in the form of a simple math expression e.g. 1 * 2 + 3

    Example query: My Variable = 1 + 4 * 7 + 4 * 0

  • Value assignment : if the value is a variable name. This is assumed to be the default. Will assign to an empty string if the variable is not found.

    Example query: My Variable = Something else


query (string) – Expects a string in the form of variable = value.


None (or SyntaxError). If the variable is successfully assigned, its value will be added to the object’s variables dictionary.


Gets a variable from the variables list and returns its value.


variable (string) – Name of the variable.


String contents of the variable, or an empty string if the variable is not found.