Markdown
String.prototype.markdown() and the Markdown syntax.
On this page
API
method
String.prototype.markdown([options], [nested])
Converts a Markdown string to HTML.
String.prototype.markdown([options], [nested])| Parameter | Type | Description |
|---|---|---|
options? |
Object |
Options, see the table. Default: {} |
nested? |
Boolean |
Leaves out the markdown-container class. Default: false |
Returns String HTML.
Every option is on by default; set it to false to skip that syntax.
| Option | Description |
|---|---|
wrap | Wraps the output in <div class="markdown markdown-container"> |
linetag | Tag of paragraphs, default 'p'; an empty string gives plain lines |
bookmarks | Adds an id made from the text to headings |
prefix | Text before the id of headings |
headlines, ul, tables, code, blockquotes, sections, hr, blocks | Block syntax |
formatting, links, images, icons, keywords, footnotes, urlify, br | Inline syntax (urlify turns plain URLs into links, br keeps ) |
emptynewline | Two empty lines give |
custom | function(line) that changes each line before it is parsed |
html | function(text, type) that changes the text of a block; type is '#'…'#####', 'li', 'blockquote', 'section', 'block' or the line tag |
< and > in the source are encoded, so raw HTML is not passed through; a text in angle brackets, such as <www.totaljs.com>, becomes a link. With nested: true the wrapper has only the class markdown.
var html = article.body.markdown();
'**Note:** see [docs](https://docs.totaljs.com)'.markdown({ wrap: false, linetag: '' });
// '<strong>Note:</strong> see <a href="https://docs.totaljs.com" target="_blank">docs</a>'
type
Markdown syntax
Markdown supported by String.prototype.markdown(), with the Total.js extensions.
Markdown syntax| Syntax | Result |
|---|---|
# Title … ##### Title | <h1> … <h5> with an id |
**text**, *text* | <strong>, <em> |
__text__, _text_, ~~text~~ | <b>, <u>, <strike> |
code and js blocks | code, <pre>code class="lang-js"` |
- item, * item, + item, 1. item, a. item | Lists; a tab nests them; [ ] and [x] make tasks |
| a | b | with a |---|--:| line | A table with left, right or center columns |
> text | <blockquote> |
< text | <section> |
---, *** | <hr> |
[text](url), , | Links (external ones open in a new tab; e-mails and phone numbers get mailto: and tel:) and lazy images |
, | An image without img-responsive, a gallery image |
, | Icons |
text | <span class="markdown-keyword" data-type="type"> |
[1](#1) and #1: text | A footnote and its body |
::: Title … ::: | An expandable block |