Spanish Total.js
English
Documentation For AI agents
Contents

Markdown

Convert Markdown to HTML with String.markdown() and choose what it produces with its options.

.md GitHub

Every string has the method markdown([opt]), which returns HTML:

var html = '# Hello\n\nThis is **bold**, _underlined_ and `code`.\n\n- one\n- two\n\t- nested'.markdown();

The parser supports headlines (# to #####), lists with -, * or + and ordered lists (1. or a.), task lists (- [x] done), tables with alignment, code blocks with a language, blockquotes (> ), sections (< ), collapsible blocks between ::: lines, horizontal lines (---, ***), images (alt, alt without the responsive class, alt for a gallery), links, footnotes (1 and #1: text), keywords (text), icons ( or ), and links detected in plain text. Links to an e-mail address or a phone number become mailto: and tel: links.

HTML in the source is always encoded, so the output is safe to put into a page. Every block has the class markdown-line and its line number, which helps you style the output and map it back to the source.

Options change the output:

var html = text.markdown({
    wrap: false,          // no <div class="markdown markdown-container">
    linetag: 'div',       // tag of normal lines (default 'p')
    bookmarks: true,      // id="..." for headlines (default true)
    prefix: 'help-',      // prefix of those ids
    tables: false,        // turn off a feature
    html: function(line, type) {
        return type === '#' ? line.toUpperCase() : line;
    }
});

Every feature can be turned off with false: headlines, ul, code, images, links, formatting, icons, tables, br, hr, blockquotes, sections, blocks, footnotes, urlify, keywords and emptynewline. The custom function changes each raw line before formatting, so you can add your own syntax.

Made in Europe