Skip to content

Commit

Permalink
Update api docs header
Browse files Browse the repository at this point in the history
  • Loading branch information
puzrin committed Dec 8, 2023
1 parent 4949a10 commit 21f7b85
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ __Table of content__
**node.js**:

```bash
npm install markdown-it --save
npm install markdown-it
```

**browser (CDN):**
Expand Down
107 changes: 62 additions & 45 deletions support/api_header.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## Install

**node.js**
**node.js**:

```bash
npm install markdown-it --save
npm install markdown-it
```

**browser (CDN):**
Expand All @@ -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!');
```


Expand All @@ -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 />).
// 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
// useful for external highlighters.
linkify: false, // Autoconvert URL-like text to links
const md = markdownit({
// Enable HTML tags in source
html: false,

// Use '/' to close single tags (<br />).
// This is only for full CommonMark compatibility.
xhtmlOut: false,

// 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
// 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,
Expand All @@ -89,19 +99,22 @@ 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')()
.use(plugin1)
.use(plugin2, opts, ...)
.use(plugin3);
import markdownit from 'markdown-it'

const md = markdownit
.use(plugin1)
.use(plugin2, opts, ...)
.use(plugin3);
```


Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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:

Expand All @@ -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')()
.disable([ 'link', 'image' ])
.enable([ 'link' ])
.enable('image');
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,
Expand Down

0 comments on commit 21f7b85

Please sign in to comment.