Skip to content
pekrauPublic

About

Compile Markdown file(s) to DOCX, PDF, EPUB3 and HTML. With extensions for hierarchy, footnotes, indexed terms and references.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

mdcompile

Compile Markdown file(s) to DOCX, PDF, EPUB3 and HTML. With extensions for hierarchy, footnotes, indexed terms and references.

Usage: mdcompile.py [OPTIONS] [INPUTPATH] [OUTPUTPATH]

  Command-line script to compile Markdown file(s).

Positional arguments:
  [INPUTPATH]   Directory or Markdown file to compile. If directory, assumes
                the existence of the file 'text.md' in it.
  [OUTPUTPATH]  Output file path (optional). Computed from INPUTPATH if not
                given. The file extension, if given, determines the output
                format.

Options:
  -h, --help                      Show this message and exit.

  Output formats: [mutually_exclusive]
                                  Formats to compile Markdown into. Overridden
                                  by an explicit extension in OUTPUTPATH.
    -D, --docx                    DOCX format (default).
    -P, --pdf                     PDF format.
    -E, --epub3                   EPUB3 format.
    -H, --html                    HTML format.
    -R, --readme                  Write out a 'README.md' file with a table of
                                  contents.

Description of inputs

The input path may be an existing directory a Markdown file. A Markdown file must have the file extension '.md'.

If the input path is a file, it will be the only Markdown file to be compiled. The extension of the output path determines the output format, overriding any format option provided. A document prepared from a single Markdown file will have neither table of contents nor an index.

If the input path is a directory, all Markdown files and subdirectories within it will be compiled. The directory structure must be as follows:

  • The top directory and all its subdirectories must contain a 'text.md' file. It contains frontmatter entries (see below) and a text preamble. These are optional; the file may be empty.

  • Each Markdown file and subdirectory on the first level are compiled into chapters of the document.

  • The first-level subdirectory's Markdown files and its subdirectories are compiled into sections of the chapter, recursively.

  • If there is no 'include' section in the 'text.md' file of a directory, the Markdown files and/or subdirectories in the directory will be added to the document in lexicographic order by file name.

The Markdown files may contain frontmatter in YAML dictionary format. The following entries are effective in all Markdown files:

  • title: The title of the document (if the top 'text.md' file) or title of the chapter or section. Default: the name of the file or directory, changing any underscore '_' characters to blanks.

  • subtitle: The subtitle of the document, chapter or section. Default: none.

The following frontmatter entries are effective only when provided in the Markdown file 'text.md' in a directory:

  • include: List of all names of files and subdirectorites that are to be included as subsections. The order is significant.

  • exclude: A list of the names of files in the same directory that are to be ignored.

The following frontmatter entries are effective only when provided in the top Markdown file 'text.md' for a document:

  • authors: A list of strings giving the authors of the document or document. No default.

  • language: Default: 'sv'.

  • identifier: A unique identifier for the document.

  • footnotes-location: One of 'document', 'chapter' or 'text' (default): specifying where footnote definitions will be written.

  • reference-title: Boolean 'true' or 'false' (default): Whether to write the title of a reference when given in the text.

  • reference-usage: Boolean 'true' or 'false' (default): Whether to write the references section where a reference was used in the text.

  • paragraph-number: Boolean 'true' or 'false' (default): Whether to write the number of each paragraph in the text.

  • refdir: The path to the refdir-style references library directory. Default: environment variable REFDIR_DIR

  • description: Description. Default: none.

  • subject: Subject description, keywords. Default: none.

  • publisher: Publisher. Default: none.

  • rights: Copyright notice or similar. Default: none.

Software

This code has been lovingly hand-crafted. No AI tools were used in its development.

Written in Python https://www.python.org/ using:

About

Compile Markdown file(s) to DOCX, PDF, EPUB3 and HTML. With extensions for hierarchy, footnotes, indexed terms and references.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages