MARKDOWN(2)

NAME
mkd_in, mkd_string, markdown, mkd_compile, mkd_css, mkd_generatecss, mkd_document, mkd_generatehtml, mkd_xhtmlpage, mkd_toc, mkd_generatetoc, mkd_cleanup, mkd_doc_title, mkd_doc_author, mkd_doc_date, mkd_line, mkd_generateline - convert Markdown text to HTML

SYNOPSIS
#include <mkdio.h>

MMIOT* mkd_in(FILE *input, int flags)

MMIOT* mkd_string(char *buf, int size, int flags)

int    markdown(MMIOT *doc, FILE *output, int flags)

int    mkd_compile(MMIOT *document, int flags)

int    mkd_css(MMIOT *document, char **doc)

int    mkd_generatecss(MMIOT *document, FILE *output)

int    mkd_document(MMIOT *document, char **doc)

int    mkd_generatehtml(MMIOT *document, FILE *output)

int    mkd_xhtmlpage(MMIOT *document, int flags, FILE *output)

int    mkd_toc(MMIOT *document, char **doc)

int    mkd_generatetoc(MMIOT *document, FILE *output)

void    mkd_cleanup(MMIOT*);

char*    mkd_doc_title(MMIOT*)

char*    mkd_doc_author(MMIOT*)

char*    mkd_doc_date(MMIOT*)

int    mkd_line(char *string, int size, char **doc, int flags)

int    mkd_generateline(char *string, int size, FILE *output, int flags)

DESCRIPTION
These functions convert Markdown(6) text into HTML markup.

Mkd_in reads the text referenced by pointer to FILE input and returns a pointer to an MMIOT structure of the form expected by markdown and the other converters. Mkd_string accepts one string and returns a pointer to MMIOT.

After such preparation, markdown converts doc and writes the result to output, while mkd_compile transforms document in-place.

One or more of the following flags (combined with OR) control markdown's processing of doc:

MKD_NOIMAGE
    Do not process ![] and remove <img> tags from the output.

MKD_NOLINKS
    Do not process [] and remove <a> tags from the output.

MKD_NOPANTS
    Suppress Smartypants-style replacement of quotes, dashes, or ellipses.

MKD_STRICT
    Disable superscript and relaxed emphasis processing.

MKD_TAGTEXT
    Process as inside an HTML tag: no <em>, no <bold>, no HTML or [] expansion.

MKD_NO_EXT
    Don't process pseudo-protocols (in markdown(6)).

MKD_CDATA
    Generate code for XML ![CDATA[...]] element.

MKD_NOHEADER
    Don't process Pandoc-style headers.

MKD_TABSTOP
    When reading documents, expand tabs to 4 spaces, overriding any compile-time configuration.

MKD_TOC
    Label headings for use with the mkd_generatetoc and mkd_toc functions.

MKD_1_COMPAT
    MarkdownTest_1.0 compatibility. Trim trailing spaces from first line of code blocks and disable implicit reference links (in markdown(6)).

MKD_AUTOLINK
    Greedy URL generation. When set, any URL is converted to a hyperlink, even those not encased in <>.

MKD_SAFELINK
    Don't make hyperlinks from [][] links that have unknown URL protocol types.

MKD_NOTABLES
    Do not process the syntax extension for tables (in markdown(6)).

MKD_EMBED
    All of MKD_NOLINKS, MKD_NOIMAGE, and MKD_TAGTEXT.

This implementation supports Pandoc-style headers and inline CSS <style> blocks, but markdown does not access the data provided by these extensions. The following functions do, and allow other manipulations.

Given a pointer to MMIOT prepared by mkd_in or mkd_string, mkd_compile compiles the document into <style>, Pandoc, and HTML sections. It accepts the flags described for markdown, above.

Once compiled, the document particulars can be read and written:

Mkd_css allocates a string and populates it with any <style> sections from the document. Mkd_generatecss writes any <style> sections to output.

Mkd_document points doc to the MMIOT document, returning document's size.

Mkd_generatehtml writes the rest of the document to the output.

Mkd_doc_title, mkd_doc_author, and mkd_doc_date read the contents of any Pandoc header.

Mkd_xhtmlpage writes an XHTML page representation of the document. It accepts the flags described for markdown, above.

Mkd_toc mallocs a buffer into which it writes an outline, in the form of a <ul> element populated with <li>s each containing a link to successive headings in the document. It returns the size of that string. Mkd_generatetoc is similar, but writes the outline to the output referenced by a pointer to FILE.

Mkd_cleanup deletes a processed MMIOT.

The last two functions convert a single line of markdown source, for example a page title or a signature. Mkd_line allocates a buffer into which it writes an HTML fragment representation of the string. Mkd_generateline writes the result to output.

SOURCE
/sys/src/cmd/discount

SEE ALSO
markdown(1), markdown(6)

DIAGNOSTICS
The mkd_in and mkd_string functions return a pointer to MMIOT on success, null on failure. Markdown, mkd_compile, mkd_style, and mkd_generatehtml return 0 on success, -1 otherwise.

BUGS
Error handling is minimal at best.

The MMIOT created by mkd_string is deleted by the markdown function.

This is an APE library.