Browse Source

Update api docs header

pull/981/head
Vitaly Puzrin 5 months ago
parent
commit
21f7b85fd5
  1. 2
      README.md
  2. 107
      support/api_header.md

2
README.md

@ -37,7 +37,7 @@ __Table of content__
**node.js**: **node.js**:
```bash ```bash
npm install markdown-it --save npm install markdown-it
``` ```
**browser (CDN):** **browser (CDN):**

107
support/api_header.md

@ -2,10 +2,10 @@
## Install ## Install
**node.js** **node.js**:
```bash ```bash
npm install markdown-it --save npm install markdown-it
``` ```
**browser (CDN):** **browser (CDN):**
@ -25,26 +25,24 @@ See also:
### Simple ### Simple
```js ```js
// node.js, "classic" way: // node.js
var MarkdownIt = require('markdown-it'), // can use `require('markdown-it')` for CJS
md = new MarkdownIt(); import markdownit from 'markdown-it'
var result = md.render('# markdown-it rulezz!'); const md = markdownit()
const result = md.render('# markdown-it rulezz!');
// node.js, the same, but with sugar: // browser with UMD build, added to "window" on script load
var md = require('markdown-it')();
var result = md.render('# markdown-it rulezz!');
// browser without AMD, added to "window" on script load
// Note, there is no dash in "markdownit". // Note, there is no dash in "markdownit".
var md = window.markdownit(); const md = window.markdownit();
var result = md.render('# markdown-it rulezz!'); const result = md.render('# markdown-it rulezz!');
``` ```
Single line rendering, without paragraph wrap: Single line rendering, without paragraph wrap:
```js ```js
var md = require('markdown-it')(); import markdownit from 'markdown-it'
var result = md.renderInline('__markdown-it__ rulezz!'); const md = markdownit()
const result = md.renderInline('__markdown-it__ rulezz!');
``` ```
@ -55,30 +53,42 @@ var result = md.renderInline('__markdown-it__ rulezz!');
[API docs](https://markdown-it.github.io/markdown-it/#MarkdownIt.new) for more details. [API docs](https://markdown-it.github.io/markdown-it/#MarkdownIt.new) for more details.
```js ```js
import markdownit from 'markdown-it'
// commonmark mode // commonmark mode
var md = require('markdown-it')('commonmark'); const md = markdownit('commonmark')
// default mode // default mode
var md = require('markdown-it')(); const md = markdownit()
// enable everything // enable everything
var md = require('markdown-it')({ const md = markdownit({
html: true, html: true,
linkify: true, linkify: true,
typographer: true typographer: true
}); })
// full options list (defaults) // full options list (defaults)
var md = require('markdown-it')({ const md = markdownit({
html: false, // Enable HTML tags in source // Enable HTML tags in source
xhtmlOut: false, // Use '/' to close single tags (<br />). html: false,
// This is only for full CommonMark compatibility.
breaks: false, // Convert '\n' in paragraphs into <br> // Use '/' to close single tags (<br />).
langPrefix: 'language-', // CSS language prefix for fenced blocks. Can be // This is only for full CommonMark compatibility.
// useful for external highlighters. xhtmlOut: false,
linkify: false, // Autoconvert URL-like text to links
// Convert '\n' in paragraphs into <br>
breaks: false,
// CSS language prefix for fenced blocks. Can be
// useful for external highlighters.
langPrefix: 'language-',
// Autoconvert URL-like text to links
linkify: false,
// Enable some language-neutral replacement + quotes beautification // Enable some language-neutral replacement + quotes beautification
// For the full list of replacements, see https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js
typographer: false, typographer: false,
// Double + single quotes replacement pairs, when typographer enabled, // Double + single quotes replacement pairs, when typographer enabled,
@ -89,19 +99,22 @@ var md = require('markdown-it')({
quotes: '“”‘’', quotes: '“”‘’',
// Highlighter function. Should return escaped HTML, // Highlighter function. Should return escaped HTML,
// or '' if the source string is not changed and should be escaped externaly. // or '' if the source string is not changed and should be escaped externally.
// If result starts with <pre... internal wrapper is skipped. // If result starts with <pre... internal wrapper is skipped.
highlight: function (/*str, lang*/) { return ''; } highlight: function (/*str, lang*/) { return ''; }
}); });
``` ```
### Plugins load ### Plugins load
```js ```js
var md = require('markdown-it')() import markdownit from 'markdown-it'
.use(plugin1)
.use(plugin2, opts, ...) const md = markdownit
.use(plugin3); .use(plugin1)
.use(plugin2, opts, ...)
.use(plugin3);
``` ```
@ -110,10 +123,11 @@ var md = require('markdown-it')()
Apply syntax highlighting to fenced code blocks with the `highlight` option: Apply syntax highlighting to fenced code blocks with the `highlight` option:
```js ```js
var hljs = require('highlight.js') // https://highlightjs.org/ import markdownit from 'markdown-it'
import hljs from 'highlight.js' // https://highlightjs.org
// Actual default values // Actual default values
var md = require('markdown-it')({ const md = markdownit({
highlight: function (str, lang) { highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
@ -129,10 +143,11 @@ var md = require('markdown-it')({
Or with full wrapper override (if you need assign class to `<pre>` or `<code>`): Or with full wrapper override (if you need assign class to `<pre>` or `<code>`):
```js ```js
var hljs = require('highlight.js') // https://highlightjs.org/ import markdownit from 'markdown-it'
import hljs from 'highlight.js' // https://highlightjs.org
// Actual default values // Actual default values
var md = require('markdown-it')({ const md = markdownit({
highlight: function (str, lang) { highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
@ -153,15 +168,15 @@ var md = require('markdown-it')({
configure linkify-it, access the linkify instance through `md.linkify`: configure linkify-it, access the linkify instance through `md.linkify`:
```js ```js
md.linkify.tlds('.py', false); // disables .py as top level domain md.linkify.set({ fuzzyEmail: false }); // disables converting email to link
``` ```
## Syntax extensions ## Syntax extensions
Embedded (enabled by default): Embedded (enabled by default):
- [Tables](https://help.github.com/articles/github-flavored-markdown/#tables) (GFM) - [Tables](https://help.github.com/articles/organizing-information-with-tables/) (GFM)
- [Strikethrough](https://help.github.com/articles/github-flavored-markdown/#strikethrough) (GFM) - [Strikethrough](https://help.github.com/articles/basic-writing-and-formatting-syntax/#styling-text) (GFM)
Via plugins: Via plugins:
@ -183,14 +198,16 @@ By default all rules are enabled, but can be restricted by options. On plugin
load all its rules are enabled automatically. load all its rules are enabled automatically.
```js ```js
// Activate/deactivate rules, with curring import markdownit from 'markdown-it'
var md = require('markdown-it')()
.disable([ 'link', 'image' ]) // Activate/deactivate rules, with currying
.enable([ 'link' ]) const md = markdownit()
.enable('image'); .disable(['link', 'image'])
.enable(['link'])
.enable('image');
// Enable everything // Enable everything
md = require('markdown-it')('full', { const md = markdownit({
html: true, html: true,
linkify: true, linkify: true,
typographer: true, typographer: true,

Loading…
Cancel
Save