source: node_modules/remarkable/README.md

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 9.1 KB
RevLine 
[d24f17c]1# remarkable
2
3[![Build Status](https://travis-ci.org/jonschlinkert/remarkable.svg?branch=master)](https://travis-ci.org/jonschlinkert/remarkable)
4[![NPM version](https://img.shields.io/npm/v/remarkable.svg)](https://www.npmjs.org/package/remarkable)
5[![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/remarkable/badge?style=rounded)](https://www.jsdelivr.com/package/npm/remarkable)
6[![Coverage Status](https://img.shields.io/coveralls/jonschlinkert/remarkable.svg)](https://coveralls.io/r/jonschlinkert/remarkable?branch=dev)
7
8> Markdown parser done right. Fast and easy to extend.
9
10__[Live demo](http://jonschlinkert.github.io/remarkable/demo/)__
11
12- Supports the [CommonMark](http://commonmark.org/) spec +
13 [syntax extensions](#syntax-extensions) + sugar (URL autolinking, typographer).
14- Configurable syntax! You can add new rules and even replace existing ones.
15- [High speed](#benchmark)!
16- [Community plugins](https://www.npmjs.org/browse/keyword/remarkable) on npm.
17
18
19## Install
20
21**node.js:**
22
23```bash
24npm install remarkable --save
25```
26
27**browser (CDN):**
28
29- [jsDeliver CDN](http://www.jsdelivr.com/#!remarkable "jsDelivr CDN")
30- [cdnjs](https://cdnjs.com/libraries/remarkable "cdnjs")
31
32
33## Usage
34
35```js
36import { Remarkable } from 'remarkable';
37var md = new Remarkable();
38
39console.log(md.render('# Remarkable rulezz!'));
40// => <h1>Remarkable rulezz!</h1>
41```
42
43or with commonjs
44
45```js
46const { Remarkable } = require('remarkable');
47var md = new Remarkable();
48
49console.log(md.render('# Remarkable rulezz!'));
50// => <h1>Remarkable rulezz!</h1>
51```
52
53
54If installed globally with `npm`:
55
56```sh
57cat myfile.md | remarkable
58remarkable --file myfile.md
59
60# get options
61remarkable -h
62```
63
64## Documentation
65
66See the [docs](docs/) directory for documentation on the following topics:
67
68- [parser](docs/parser.md)
69- [parsing_block](docs/parsing_block.md)
70- [parsing_core](docs/parsing_core.md)
71- [parsing_inline](docs/parsing_inline.md)
72- [plugins](docs/plugins.md)
73- [renderer](docs/renderer.md)
74
75### Options
76
77By default, remarkable is configured to be similar to GFM, but with HTML disabled.
78This is easy to change if you prefer different settings.
79
80There are two ways to define options.
81
82#### constructor
83
84Define options in the constructor:
85
86```js
87// Actual default values
88var md = new Remarkable({
89 html: false, // Enable HTML tags in source
90 xhtmlOut: false, // Use '/' to close single tags (<br />)
91 breaks: false, // Convert '\n' in paragraphs into <br>
92 langPrefix: 'language-', // CSS language prefix for fenced blocks
93
94 // Enable some language-neutral replacement + quotes beautification
95 typographer: false,
96
97 // Double + single quotes replacement pairs, when typographer enabled,
98 // and smartquotes on. Set doubles to '«»' for Russian, '„“' for German.
99 quotes: '“”‘’',
100
101 // Highlighter function. Should return escaped HTML,
102 // or '' if the source string is not changed
103 highlight: function (/*str, lang*/) { return ''; }
104});
105
106console.log(md.render('# Remarkable rulezz!'));
107// => <h1>Remarkable rulezz!</h1>
108```
109
110#### .set
111
112Or define options via the `.set()` method:
113
114```js
115import { Remarkable } from 'remarkable';
116
117var md = new Remarkable();
118
119md.set({
120 html: true,
121 breaks: true
122});
123```
124
125**Note:** To achieve the best possible performance, don't modify a `Remarkable`
126instance on the fly. If you need multiple configurations, create
127multiple instances and initialize each with a configuration that is ideal for
128that instance.
129
130
131### Presets
132
133Remarkable offers some "presets" as a convenience to quickly enable/disable
134active syntax rules and options for common use cases.
135
136#### commonmark
137
138Enable strict [CommonMark](http://commonmark.org/) mode with the `commonmark` preset:
139
140```js
141import { Remarkable } from 'remarkable';
142var md = new Remarkable('commonmark');
143```
144
145#### full
146
147Enable all available rules (but still with default options, if not set):
148
149```js
150import { Remarkable } from 'remarkable';
151var md = new Remarkable('full');
152
153// Or with options:
154var md = new Remarkable('full', {
155 html: true,
156 typographer: true
157});
158```
159
160
161### Syntax highlighting
162
163Apply syntax highlighting to fenced code blocks with the `highlight` option:
164
165```js
166import { Remarkable } from 'remarkable';
167import hljs from 'highlight.js' // https://highlightjs.org/
168
169// Actual default values
170var md = new Remarkable({
171 highlight: function (str, lang) {
172 if (lang && hljs.getLanguage(lang)) {
173 try {
174 return hljs.highlight(lang, str).value;
175 } catch (err) {}
176 }
177
178 try {
179 return hljs.highlightAuto(str).value;
180 } catch (err) {}
181
182 return ''; // use external default escaping
183 }
184});
185```
186
187
188### Syntax extensions
189
190Enabled by default:
191
192- [Footnotes](http://johnmacfarlane.net/pandoc/README.html#footnotes)
193- [Tables](https://help.github.com/articles/github-flavored-markdown/#tables) (GFM)
194- [\<del>](https://help.github.com/articles/github-flavored-markdown/#strikethrough)
195 (GFM strikethrough) - `~~deleted text~~`
196
197Disabled by default:
198
199- [\<sup>](http://johnmacfarlane.net/pandoc/README.html#superscripts-and-subscripts) - `19^th^`
200- [\<sub>](http://johnmacfarlane.net/pandoc/README.html#superscripts-and-subscripts) - `H~2~O`
201- [abbreviations](https://michelf.ca/projects/php-markdown/extra/#abbr)
202- __\<ins>__ - `++inserted text++` (experimental)
203- __\<mark>__ - `==marked text==` (experimental)
204
205**HEADS UP!**: Experimental extensions can be changed later for something like [Critic Markup](http://criticmarkup.com/), but you will still be able to use old-style rules via external plugins if you prefer.
206
207
208### Manage rules
209
210```js
211var md = new Remarkable();
212md.inline.ruler.enable([ 'ins', 'mark' ]);
213md.block.ruler.disable([ 'table', 'footnote' ]);
214
215// Enable everything
216md = new Remarkable('full', {
217 html: true,
218 typographer: true,
219});
220
221//
222// Manually enable rules, disabled by default:
223//
224var md = new Remarkable();
225md.core.ruler.enable([
226 'abbr'
227]);
228md.block.ruler.enable([
229 'footnote',
230 'deflist'
231]);
232md.inline.ruler.enable([
233 'footnote_inline',
234 'ins',
235 'mark',
236 'sub',
237 'sup'
238]);
239```
240
241
242### Typographer
243
244Although full-weight typographical replacements are language specific, `remarkable`
245provides coverage for the most common and universal use cases:
246
247```js
248import { Remarkable } from 'remarkable';
249var md = new Remarkable({
250 typographer: true,
251 quotes: '“”‘’'
252});
253
254// Disable rules at all:
255md.core.ruler.disable([ 'replacements', 'smartquotes' ]);
256
257// Actual default replacements:
258//
259// '' → ‘’
260// "" → “”. Set '«»' for Russian, '„“' for German, empty to disable
261// (c) (C) → ©
262// (tm) (TM) → ™
263// (r) (R) → ®
264// +- → ±
265// (p) (P) -> §
266// ... → … (also ?.... → ?.., !.... → !..)
267// ???????? → ???, !!!!! → !!!, `,,` → `,`
268// -- → &ndash;, --- → &mdash;
269//
270```
271
272Of course, you can also add your own rules or replace the defaults with something
273more advanced or specific to your language.
274
275
276### Plugins
277
278Easily load plugins with the `.use()` method:
279
280```js
281var md = new Remarkable();
282
283md.use(plugin1)
284 .use(plugin2, opts)
285 .use(plugin3);
286```
287
288Please refer to the [plugin documentation](docs/plugins.md) to create your own
289plugins.
290
291### linkify plugin
292
293Autoconvert URL-like text to links
294
295```js
296import { Remarkable } from 'remarkable';
297import { linkify } from 'remarkable/linkify';
298
299var md = new Remarkable().use(linkify);
300```
301
302### UMD
303
304UMD bundle provides linkify out of the box
305
306```js
307const { Remarkable, linkify, utils } = window.remarkable;
308```
309
310
311## References / Thanks
312
313Big thanks to [John MacFarlane](https://github.com/jgm) for his work on the
314CommonMark spec and reference implementations. His work saved us a lot of time
315during this project's development.
316
317**Related Links:**
318
3191. https://github.com/jgm/CommonMark - reference CommonMark implementations in C & JS,
320 also contains latest spec & online demo.
3212. http://talk.commonmark.org - CommonMark forum, good place to collaborate
322 developers' efforts.
323
324
325## Development / Modification
326
327[Parser](docs/parser.md) consists of several responsibility chains filled with
328rules. You can reconfigure any of them as you wish. [Renderer](docs/renderer.md) also
329can be modified and extended. See source code to understand details. Pay
330attention to these properties:
331
332```js
333Remarkable.core
334Remarkable.core.ruler
335Remarkable.block
336Remarkable.block.ruler
337Remarkable.inline
338Remarkable.inline.ruler
339Remarkable.renderer
340Remarkable.renderer.rules
341```
342
343## Benchmark
344
345Here is result of CommonMark spec parse at Core i5 2.4 GHz (i5-4258U):
346
347```bash
348$ benchmark/benchmark.js spec
349Selected samples: (1 of 27)
350 > spec
351
352Sample: spec.txt (110610 bytes)
353 > commonmark-reference x 40.42 ops/sec ±4.07% (51 runs sampled)
354 > current x 74.99 ops/sec ±4.69% (67 runs sampled)
355 > current-commonmark x 93.76 ops/sec ±1.23% (79 runs sampled)
356 > marked-0.3.2 x 22.92 ops/sec ±0.79% (41 runs sampled)
357```
358
359As you can see, `remarkable` doesn't pay with speed for its flexibility. Because
360it's written in monomorphic style and uses JIT inline caches effectively.
361
362
363## Authors
364
365- Jon Schlinkert [github/jonschlinkert](https://github.com/jonschlinkert)
366- Alex Kocharin [github/rlidwka](https://github.com/rlidwka)
367- Vitaly Puzrin [github/puzrin](https://github.com/puzrin)
368
369
370## License
371
372[MIT](https://github.com/jonschlinkert/remarkable/blob/master/LICENSE)
Note: See TracBrowser for help on using the repository browser.