Wizards

This is what drives MDiocre’s user interface.

Wizard

class mdiocre.wizard.Wizard(quiet=False)
generate_from_directory(args, callback=None)

Generates pages based on the directory it is supplied through args.

This function looks at the files inside the argssource_dir path recursively and copies the files to build_dir, or generates a page if it is a MDiocre file (see is_mdiocre_string()).

In order to generate pages, it needs a template. The template file is supplied through each file’s mdiocre-template variable, and it is relative to source_dir.

Parameters
  • args (dict) – A dictionary containing arguments for this function. It must have the following keys: source_dir and build_dir.

  • callback (func) – A function to call every file completion. Its arguments are a dictionary containing the keys “original_file”, “target_file”, “root”.

Returns

True, if every file is successfully processed. Otherwise, return False. Additionally, it will also create or modify files on the filesystem.

generate_from_path(source_file, built_file, root='')

If the file is a MDiocre file, generate an HTML page from a source file to a built file. Otherwise, simply copy the file.

generate_from_string(md_string, root)

Given a MDiocre string and a “root” path, convert it to a proper HTML document.

MDiocre is simple: HTML template + Markdown = New HTML page

The HTML template itself is obtained from the presence of the mdiocre_template variable, which simply contains the path of the template file relative to the root set here. Which is why the mdiocre-template variable must be present for the markdown to be considered convertable by MDiocre.

Parameters
  • md_string (string) – The markdown-formatted text to convert.

  • root (string) – The ‘root’ path.

Returns

A rendered HTML string. If the md_string is invalid or if it cannot find the template file, it will return an empty string.

is_mdiocre_string(md_string)

Determines whether or not this is valid MDiocre-formatted markdown.

The only criteria currently needed for this is whether or not it contains a mdiocre-template variable.

Parameters

md_string (string) – The markdown-formatted text to validate.

Returns

True if it is a valid string, False otherwise.

register_converter(file_extension, parser_name)

Registers a parser with a file extension.