---
title: Markdown
project: Total.js V4
version: 0.0.99
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v4/0-0-99/reference/markdown/
updated: 2026-11-18T16:57:49.579Z
---

# Markdown

> String.markdown() and its options.

## API

### String.markdown([opt])

Type: `method`

Converts a Markdown string to HTML.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `opt` | `Object` | no | `{}` | Options: `wrap`, `linetag`, `bookmarks`, `prefix`, `html`, `custom` and the feature switches listed above. |

Returns: `String` HTML.

The framework loads the parser at start, so every string has this method. HTML tags in the source are encoded. Every block gets the class `markdown-line` and its line number in `data-line` (`data-index` for headlines). By default the output is wrapped in `<div class="markdown markdown-container">` and tabs become four spaces.

Each feature can be turned off with `false` in `opt`: `headlines`, `ul` (lists), `code`, `images`, `links`, `formatting`, `icons`, `tables`, `br`, `hr`, `blockquotes`, `sections`, `blocks`, `footnotes`, `urlify`, `keywords` and `emptynewline`. Bullet lists can start with `-`, `*` or `+`. Links to an e-mail address or a phone number become `mailto:` and `tel:` links.

Example: Render a README
```js
var html = '# Hello\n\n- one\n- two\n\nWrite to [us](info@company.com).'.markdown();
```

Example: Only basic formatting
```js
var html = text.markdown({ tables: false, code: false, images: false, wrap: false });
```

### String.markdown({ wrap: Boolean })

Type: `property`

Wraps the output in a `div` container.

Returns: `Boolean` Default `true`.

With `true` the output is `<div class="markdown markdown-container">...</div>`. Use `false` to insert the HTML into your own element.

Example: Without the container
```js
var html = '**Bold** text'.markdown({ wrap: false });
// <p class="markdown-line" data-line="0"><strong>Bold</strong> text</p>
```

### String.markdown({ linetag: String })

Type: `property`

The tag of a normal paragraph line.

Returns: `String` Default `'p'`.

Each line that is not a headline, list, table or other block is wrapped in this tag. An empty string writes the lines without a tag.

Example: Lines as div
```js
var html = text.markdown({ linetag: 'div' });
```

### String.markdown({ bookmarks: Boolean })

Type: `property` · Since: `0.0.96`

Adds an `id` (a slug of the text) to headlines.

Returns: `Boolean` Default `true`.

`# Hello world` becomes `<h1 id="hello-world" ...>`, so you can link to `#hello-world`. Set `false` to leave the `id` out.

Example: Headlines without id
```js
var html = '# Title'.markdown({ bookmarks: false, wrap: false });
// <h1 class="markdown-line" data-index="0">Title</h1>
```

### String.markdown({ prefix: String })

Type: `property` · Since: `0.0.96`

A prefix for the `id` of headlines.

Returns: `String` Default `''`.

Useful when more Markdown documents are on one page and their headlines would get the same `id`.

Example: Prefixed bookmarks
```js
var html = '# Hello world'.markdown({ prefix: 'doc-' });
// <h1 id="doc-hello-world" ...>
```

### String.markdown({ html: function(line, type) })

Type: `delegate`

Changes the HTML of a block before it is written.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `line` | `String` | yes |  | The content of the block. |
| `type` | `String` | yes |  | The block type. |

Returns: `String` The new content.

Called with the content and the block type: `#` to `#####` for headlines, `li`, `blockquote`, `section`, `block` or the value of `linetag` for normal lines. Return the new content.

Example: Upper-case h1
```js
var html = text.markdown({ html: function(line, type) {
	return type === '#' ? line.toUpperCase() : line;
}});
```

### String.markdown({ custom: function(line) })

Type: `delegate`

Changes each raw line before the inline formatting is applied.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `line` | `String` | yes |  | One line of the source. |

Returns: `String` The new line.

Use it for your own inline syntax. The line is already HTML-encoded. Return the new line.

Example: Replace a placeholder
```js
var html = text.markdown({ custom: function(line) {
	return line.replace(/\{year\}/g, NOW.getFullYear());
}});
```
