Browse Source

Update api docs header

pull/981/head
Vitaly Puzrin 1 year ago
parent
commit
21f7b85fd5
  1. 2
      README.md
  2. 91
      support/api_header.md

2
README.md

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

91
support/api_header.md

@ -2,10 +2,10 @@
## Install
**node.js**
**node.js**:
```bash
npm install markdown-it --save
npm install markdown-it
```
**browser (CDN):**
@ -25,26 +25,24 @@ See also:
### Simple
```js
// node.js, "classic" way:
var MarkdownIt = require('markdown-it'),
md = new MarkdownIt();
var result = md.render('# markdown-it rulezz!');
// node.js
// can use `require('markdown-it')` for CJS
import markdownit from 'markdown-it'
const md = markdownit()
const result = md.render('# markdown-it rulezz!');
// node.js, the same, but with sugar:
var md = require('markdown-it')();
var result = md.render('# markdown-it rulezz!');
// browser without AMD, added to "window" on script load
// browser with UMD build, added to "window" on script load
// Note, there is no dash in "markdownit".
var md = window.markdownit();
var result = md.render('# markdown-it rulezz!');
const md = window.markdownit();
const result = md.render('# markdown-it rulezz!');
```
Single line rendering, without paragraph wrap:
```js
var md = require('markdown-it')();
var result = md.renderInline('__markdown-it__ rulezz!');
import markdownit from 'markdown-it'
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.
```js
import markdownit from 'markdown-it'
// commonmark mode
var md = require('markdown-it')('commonmark');
const md = markdownit('commonmark')
// default mode
var md = require('markdown-it')();
const md = markdownit()
// enable everything
var md = require('markdown-it')({
const md = markdownit({
html: true,
linkify: true,
typographer: true
});
})
// full options list (defaults)
var md = require('markdown-it')({
html: false, // Enable HTML tags in source
xhtmlOut: false, // Use '/' to close single tags (<br />).
const md = markdownit({
// Enable HTML tags in source
html: false,
// Use '/' to close single tags (<br />).
// This is only for full CommonMark compatibility.
breaks: false, // Convert '\n' in paragraphs into <br>
langPrefix: 'language-', // CSS language prefix for fenced blocks. Can be
xhtmlOut: false,
// Convert '\n' in paragraphs into <br>
breaks: false,
// CSS language prefix for fenced blocks. Can be
// useful for external highlighters.
linkify: false, // Autoconvert URL-like text to links
langPrefix: 'language-',
// Autoconvert URL-like text to links
linkify: false,
// 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,
// Double + single quotes replacement pairs, when typographer enabled,
@ -89,16 +99,19 @@ var md = require('markdown-it')({
quotes: '“”‘’',
// 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.
highlight: function (/*str, lang*/) { return ''; }
});
```
### Plugins load
```js
var md = require('markdown-it')()
import markdownit from 'markdown-it'
const md = markdownit
.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:
```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
var md = require('markdown-it')({
const md = markdownit({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
@ -129,10 +143,11 @@ var md = require('markdown-it')({
Or with full wrapper override (if you need assign class to `<pre>` or `<code>`):
```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
var md = require('markdown-it')({
const md = markdownit({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
@ -153,15 +168,15 @@ var md = require('markdown-it')({
configure linkify-it, access the linkify instance through `md.linkify`:
```js
md.linkify.tlds('.py', false); // disables .py as top level domain
md.linkify.set({ fuzzyEmail: false }); // disables converting email to link
```
## Syntax extensions
Embedded (enabled by default):
- [Tables](https://help.github.com/articles/github-flavored-markdown/#tables) (GFM)
- [Strikethrough](https://help.github.com/articles/github-flavored-markdown/#strikethrough) (GFM)
- [Tables](https://help.github.com/articles/organizing-information-with-tables/) (GFM)
- [Strikethrough](https://help.github.com/articles/basic-writing-and-formatting-syntax/#styling-text) (GFM)
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.
```js
// Activate/deactivate rules, with curring
var md = require('markdown-it')()
import markdownit from 'markdown-it'
// Activate/deactivate rules, with currying
const md = markdownit()
.disable(['link', 'image'])
.enable(['link'])
.enable('image');
// Enable everything
md = require('markdown-it')('full', {
const md = markdownit({
html: true,
linkify: true,
typographer: true,

Loading…
Cancel
Save