Browse Source

README: update samples to esm

pull/981/head
Vitaly Puzrin 5 months ago
parent
commit
8725522c8c
  1. 91
      README.md

91
README.md

@ -59,26 +59,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!');
``` ```
@ -89,28 +87,39 @@ 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 // For the full list of replacements, see https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.js
@ -133,10 +142,12 @@ var md = require('markdown-it')({
### 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);
``` ```
@ -145,10 +156,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 {
@ -164,10 +176,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 {
@ -227,14 +240,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
import markdownit from 'markdown-it'
// Activate/deactivate rules, with currying // Activate/deactivate rules, with currying
var md = require('markdown-it')() const md = markdownit()
.disable([ 'link', 'image' ]) .disable(['link', 'image'])
.enable([ 'link' ]) .enable(['link'])
.enable('image'); .enable('image');
// Enable everything // Enable everything
md = require('markdown-it')({ const md = markdownit({
html: true, html: true,
linkify: true, linkify: true,
typographer: true, typographer: true,

Loading…
Cancel
Save