• Stars
    star
    5,745
  • Rank 7,082 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.

remarkable

Build Status NPM version jsDelivr Hits Coverage Status

Markdown parser done right. Fast and easy to extend.

Live demo

Install

node.js:

npm install remarkable --save

browser (CDN):

Usage

import { Remarkable } from 'remarkable';
var md = new Remarkable();

console.log(md.render('# Remarkable rulezz!'));
// => <h1>Remarkable rulezz!</h1>

or with commonjs

const { Remarkable } = require('remarkable');
var md = new Remarkable();

console.log(md.render('# Remarkable rulezz!'));
// => <h1>Remarkable rulezz!</h1>

If installed globally with npm:

cat myfile.md | remarkable
remarkable --file myfile.md

# get options
remarkable -h

Documentation

See the docs directory for documentation on the following topics:

Options

By default, remarkable is configured to be similar to GFM, but with HTML disabled. This is easy to change if you prefer different settings.

There are two ways to define options.

constructor

Define options in the constructor:

// Actual default values
var md = new Remarkable({
  html:         false,        // Enable HTML tags in source
  xhtmlOut:     false,        // Use '/' to close single tags (<br />)
  breaks:       false,        // Convert '\n' in paragraphs into <br>
  langPrefix:   'language-',  // CSS language prefix for fenced blocks

  // Enable some language-neutral replacement + quotes beautification
  typographer:  false,

  // Double + single quotes replacement pairs, when typographer enabled,
  // and smartquotes on. Set doubles to '«»' for Russian, '„“' for German.
  quotes: '“”‘’',

  // Highlighter function. Should return escaped HTML,
  // or '' if the source string is not changed
  highlight: function (/*str, lang*/) { return ''; }
});

console.log(md.render('# Remarkable rulezz!'));
// => <h1>Remarkable rulezz!</h1>

.set

Or define options via the .set() method:

import { Remarkable } from 'remarkable';

var md = new Remarkable();

md.set({
  html: true,
  breaks: true
});

Note: To achieve the best possible performance, don't modify a Remarkable instance on the fly. If you need multiple configurations, create multiple instances and initialize each with a configuration that is ideal for that instance.

Presets

Remarkable offers some "presets" as a convenience to quickly enable/disable active syntax rules and options for common use cases.

commonmark

Enable strict CommonMark mode with the commonmark preset:

import { Remarkable } from 'remarkable';
var md = new Remarkable('commonmark');

full

Enable all available rules (but still with default options, if not set):

import { Remarkable } from 'remarkable';
var md = new Remarkable('full');

// Or with options:
var md = new Remarkable('full', {
  html: true,
  typographer: true
});

Syntax highlighting

Apply syntax highlighting to fenced code blocks with the highlight option:

import { Remarkable } from 'remarkable';
import hljs from 'highlight.js' // https://highlightjs.org/

// Actual default values
var md = new Remarkable({
  highlight: function (str, lang) {
    if (lang && hljs.getLanguage(lang)) {
      try {
        return hljs.highlight(lang, str).value;
      } catch (err) {}
    }

    try {
      return hljs.highlightAuto(str).value;
    } catch (err) {}

    return ''; // use external default escaping
  }
});

Syntax extensions

Enabled by default:

Disabled by default:

  • <sup> - 19^th^
  • <sub> - H~2~O
  • abbreviations
  • <ins> - ++inserted text++ (experimental)
  • <mark> - ==marked text== (experimental)

HEADS UP!: Experimental extensions can be changed later for something like Critic Markup, but you will still be able to use old-style rules via external plugins if you prefer.

Manage rules

var md = new Remarkable();
md.inline.ruler.enable([ 'ins', 'mark' ]);
md.block.ruler.disable([ 'table', 'footnote' ]);

// Enable everything
md = new Remarkable('full', {
  html: true,
  typographer: true,
});

//
// Manually enable rules, disabled by default:
//
var md = new Remarkable();
md.core.ruler.enable([
  'abbr'
]);
md.block.ruler.enable([
  'footnote',
  'deflist'
]);
md.inline.ruler.enable([
  'footnote_inline',
  'ins',
  'mark',
  'sub',
  'sup'
]);

Typographer

Although full-weight typographical replacements are language specific, remarkable provides coverage for the most common and universal use cases:

import { Remarkable } from 'remarkable';
var md = new Remarkable({
  typographer: true,
  quotes: '“”‘’'
});

// Disable rules at all:
md.core.ruler.disable([ 'replacements', 'smartquotes' ]);

// Actual default replacements:
//
// '' → ‘’
// "" → “”. Set '«»' for Russian, '„“' for German, empty to disable
// (c) (C) → ©
// (tm) (TM) → ™
// (r) (R) → ®
// +- → ±
// (p) (P) -> §
// ... → … (also ?.... → ?.., !.... → !..)
// ???????? → ???, !!!!! → !!!, `,,` → `,`
// -- → &ndash;, --- → &mdash;
//

Of course, you can also add your own rules or replace the defaults with something more advanced or specific to your language.

Plugins

Easily load plugins with the .use() method:

var md = new Remarkable();

md.use(plugin1)
  .use(plugin2, opts)
  .use(plugin3);

Please refer to the plugin documentation to create your own plugins.

linkify plugin

Autoconvert URL-like text to links

import { Remarkable } from 'remarkable';
import { linkify } from 'remarkable/linkify';

var md = new Remarkable().use(linkify);

UMD

UMD bundle provides linkify out of the box

const { Remarkable, linkify, utils } = window.remarkable;

References / Thanks

Big thanks to John MacFarlane for his work on the CommonMark spec and reference implementations. His work saved us a lot of time during this project's development.

Related Links:

  1. https://github.com/jgm/CommonMark - reference CommonMark implementations in C & JS, also contains latest spec & online demo.
  2. http://talk.commonmark.org - CommonMark forum, good place to collaborate developers' efforts.

Development / Modification

Parser consists of several responsibility chains filled with rules. You can reconfigure any of them as you wish. Renderer also can be modified and extended. See source code to understand details. Pay attention to these properties:

Remarkable.core
Remarkable.core.ruler
Remarkable.block
Remarkable.block.ruler
Remarkable.inline
Remarkable.inline.ruler
Remarkable.renderer
Remarkable.renderer.rules

Benchmark

Here is result of CommonMark spec parse at Core i5 2.4 GHz (i5-4258U):

$ benchmark/benchmark.js spec
Selected samples: (1 of 27)
 > spec

Sample: spec.txt (110610 bytes)
 > commonmark-reference x 40.42 ops/sec ±4.07% (51 runs sampled)
 > current x 74.99 ops/sec ±4.69% (67 runs sampled)
 > current-commonmark x 93.76 ops/sec ±1.23% (79 runs sampled)
 > marked-0.3.2 x 22.92 ops/sec ±0.79% (41 runs sampled)

As you can see, remarkable doesn't pay with speed for its flexibility. Because it's written in monomorphic style and uses JIT inline caches effectively.

Authors

License

MIT

More Repositories

1

gray-matter

Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert
JavaScript
3,863
star
2

markdown-toc

API and CLI for generating a markdown TOC (table of contents) for a README or any markdown files. Uses Remarkable to parse markdown. Used by NASA/openmct, Prisma, Joi, Mocha, Sass, Prettier, Orbit DB, FormatJS, Raneto, hapijs/code, webpack-flow, docusaurus, release-it, ts-loader, json-server, reactfire, bunyan, husky, react-easy-state, react-snap, chakra-ui, carbon, alfresco, repolinter, Assemble, Verb, and thousands of other projects.
JavaScript
1,508
star
3

gulp-htmlmin

Minify HTML
HTML
730
star
4

sublime-markdown-extended

Top 100 Sublime Text plugin! Markdown syntax highlighter for Sublime Text, with extended support for GFM fenced code blocks, with language-specific syntax highlighting. YAML Front Matter. Works with ST2/ST3. Goes great with Assemble.
658
star
5

maintainers-guide-to-staying-positive

Don't let the trolls get you down! Use this as a reference to avoid open-source burnout and keep doing what you love: writing code! Contributions and any kind of improvements are very welcome!
625
star
6

sublime-monokai-extended

Extends Monokai from Soda with additional syntax highlighting for Markdown, LESS, HTML, Handlebars and more.
511
star
7

kind-of

Get the native JavaScript type of a value, fast. Used by superstruct, micromatch and many others!
JavaScript
334
star
8

clone-deep

Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives. Used by superstruct, merge-deep, and many others!
JavaScript
305
star
9

set-value

Set nested properties on an object using dot-notation.
JavaScript
261
star
10

is-number

JavaScript/Node.js utility. Returns `true` if the value is a number or string number. Useful for checking regex match results, user input, parsed strings, etc.
JavaScript
256
star
11

get-value

Use property paths (`a.b.c`) get a nested value from an object.
JavaScript
229
star
12

word-wrap

Wrap words to a specified length.
JavaScript
194
star
13

randomatic

Easily generate random strings like passwords, with simple options for specifying a length and for using patterns of numeric, alpha-numeric, alphabetical, special or custom characters. (the original "generate-password")
JavaScript
178
star
14

data-store

Easily get, set and persist config data. Fast. Supports dot-notation in keys. No dependencies.
JavaScript
158
star
15

is-plain-object

Returns true if the given value is an object created by the Object constructor.
HTML
147
star
16

guide-to-staying-productive

If you're looking for ways to stay motivated and focused, while still having fun, this guide is for you! Contributions and any kind of improvements are very welcome!
136
star
17

pretty

Sensible presets and some tweaks for beautifying HTML with js-beautify according to my preferences.
JavaScript
135
star
18

parse-github-url

Parse a Github URL into an object. Supports a wide variety of GitHub URL formats.
JavaScript
117
star
19

time-stamp

Get a formatted timestamp. Used in gulp, assemble, generate, and many others.
JavaScript
112
star
20

idiomatic-contributing

A brief guide to being an effective open source contributor.
111
star
21

merge-deep

Recursively merge values in a JavaScript object.
JavaScript
111
star
22

strip-comments

Strip block comments or line comments from JavaScript code.
JavaScript
105
star
23

isobject

Is the value an object, and not an array or null?
JavaScript
101
star
24

normalize-path

Normalize file path slashes to be unix-like forward slashes. Used by chokidar, anymatch, and many others!
JavaScript
99
star
25

gists

Methods for working with the GitHub Gist API. Node.js/JavaScript
JavaScript
97
star
26

copy

Copy files using glob patterns. Sync, async, promise or streams. (node.js utility)
JavaScript
93
star
27

git-branch

Get the current branch for a local git repository
JavaScript
91
star
28

dashify

Convert a string to a dash-separated string (kebab case). Works with camelcase, pascalcase, space-separated, etc.
JavaScript
86
star
29

vertical-rhythm

Put some typographical vertical rhythm in your CSS. LESS, Stylus and SCSS/SASS versions included.
CSS
85
star
30

write

Write data to the file system, creating any intermediate directories if they don't already exist. Used by flat-cache and many others!
JavaScript
82
star
31

window-size

Reliable way to to get the height and width of the terminal/console in a node.js environment.
JavaScript
80
star
32

object.omit

Return a copy of an object without the given keys.
JavaScript
79
star
33

mixin-deep

Deeply mix the properties of objects into the first object, while also mixing-in child objects.
JavaScript
79
star
34

assign-deep

Deeply assign the enumerable properties of source objects to a destination object.
JavaScript
78
star
35

grunt-prettify

Grunt plugin for beautifying HTML. Lots of options so that you can format/beautify the generated HTML the way you want it.
JavaScript
77
star
36

template-helpers

Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or any engine that supports helper functions.
JavaScript
75
star
37

omit-deep

Recursively omit specified keys from an object.
JavaScript
73
star
38

omit-empty

Recursively omit empty properties from an object. Omits empty objects, arrays, strings, and optionally zero. Similar results to what you would expect with `compact` for arrays.
JavaScript
73
star
39

array-sort

Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.
JavaScript
72
star
40

dry

Dry is a new template engine and language, and is a superset of Shopify's Liquid, with first-class support for advanced inheritance features, and more. From the creators of Enquirer, Assemble, Remarkable, and Micromatch.
JavaScript
69
star
41

grunt-refactor

Grunt tasks for re-factoring code.
JavaScript
65
star
42

parse-comments

Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
JavaScript
64
star
43

utils

Fast, generic JavaScript/node.js utility functions.
JavaScript
61
star
44

github-base

Simple, opinionated node.js interface for creating basic apps with the GitHub API.
JavaScript
60
star
45

arr-flatten

Recursively flatten an array or arrays. This is the fastest implementation of array flatten.
JavaScript
60
star
46

templates

System for creating and managing view collections, rendering, engines, routes and more. See the "dev" branch for most recent updates.
JavaScript
60
star
47

parse-gitignore

Parse a gitignore file into an array of patterns. Comments and empty lines are stripped.
JavaScript
59
star
48

parse-git-config

Parse `.git/config` into a JavaScript object. sync or async.
JavaScript
58
star
49

array-unique

Return an array free of duplicate values. Very fast implementation.
JavaScript
58
star
50

sublime-swig

Swig template syntax highlighting for Sublime Text.
58
star
51

to-regex

Generate a regex from a string or array of strings.
JavaScript
56
star
52

split-string

Split a string on a given character or characters, with support for escaping.
JavaScript
55
star
53

fill-range

Fill in a range of numbers or letters, positive or negative, optionally passing an increment or multiplier to use.
JavaScript
54
star
54

cache-base

Basic object store with methods like get/set/extend/omit
JavaScript
54
star
55

template

Render templates from any engine. Make custom template types, use layouts on pages, partials or any custom template type, custom delimiters, helpers, middleware, routes, loaders, and lots more. Powers Assemble v0.6.0, Verb v0.3.0 and your application.
JavaScript
54
star
56

align-text

Align the text in a string.
JavaScript
51
star
57

grunt-fixmyjs

Automatically fix js-hint errors.
JavaScript
51
star
58

lazy-cache

Cache requires to be lazy-loaded when needed. Uses node's own require system with tried and true, plain-vanilla JavaScript getters.
JavaScript
51
star
59

gulp-prettify

Prettify HTML.
HTML
50
star
60

exponential-moving-average

Calculate an exponential moving average from an array of numbers.
JavaScript
50
star
61

pretty-time

Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.
JavaScript
50
star
62

is-windows

Returns true if the platform is Windows (and Cygwin or MSYS/MinGW for unit tests)
JavaScript
48
star
63

extract-comments

Extract JavaScript code comments from a string or glob of files.
JavaScript
46
star
64

repeat-string

Repeat the given string n times. Fastest implementation for repeating a string (2x faster than the native method)
JavaScript
45
star
65

arr-diff

Returns an array with only the unique values from all given arrays using strict equality for comparisons.
JavaScript
44
star
66

pad-left

Left pad a string with zeros or a specified string. Fastest implementation.
JavaScript
44
star
67

unixify

Convert a windows file path to a unix-style file path.
JavaScript
42
star
68

object.pick

(object pick) returns a filtered copy of an object with only the specified keys, exactly like `pick` from lo-dash / underscore.
JavaScript
42
star
69

delete-empty

Recursively delete all empty folders in a directory and child directories.
JavaScript
41
star
70

handlebars-delimiters

Custom delimiters, for Handlebars templates.
JavaScript
41
star
71

write-yaml

Basic node.js utility for converting JSON to YAML and writing formatting YAML files to disk.
JavaScript
40
star
72

regex-cache

Memoize the results of a call to the RegExp constructor, avoiding repetitious runtime compilation of the same string and options, resulting in dramatic speed improvements.
JavaScript
39
star
73

unescape

Convert HTML entities to HTML characters, e.g. `&gt;` => `>`.
JavaScript
38
star
74

pascalcase

Convert a string to pascal case (upper camel case). Used by more than 8.7 million projects on GitHub! Please follow this library's author: https://github.com/jonschlinkert
JavaScript
36
star
75

is-primitive

Is the typeof value a javascript primitive?
JavaScript
36
star
76

is-git-url

Regex to validate that a URL is a git URL.
JavaScript
35
star
77

deep-rename-keys

Recursively rename the keys in an object.
JavaScript
35
star
78

unset-value

Delete nested properties from an object using dot notation.
JavaScript
34
star
79

fs-utils

Generalized file and path utils for Node.js projects.
JavaScript
34
star
80

array-last

Return the last element in an array. Faster than `.slice`
JavaScript
34
star
81

relative

Easily calculate the relative path from file A to file B in Node.js project. Will calculate correctly from a file to a directory, file to file, directory to file, and directory to directory.
JavaScript
34
star
82

for-in

Iterate over the enumerable properties of an object, and return an object with properties that evaluate to true from the callback. Exit early by returning `false`.
JavaScript
33
star
83

global-modules

Returns the directory used by NPM for globally installed NPM packages.
JavaScript
33
star
84

extend-shallow

Extend object A with the properties of object B. node.js/javascript util.
JavaScript
32
star
85

eval-estree-expression

Safely evaluate JavaScript (estree) expressions, sync and async.
JavaScript
32
star
86

regex-not

Create a javascript regular expression for matching everything except for the given string.
JavaScript
31
star
87

longest

Get the length of the longest item in an array.
JavaScript
31
star
88

whence

Add context awareness to your apps and frameworks by safely evaluating user-defined conditional expressions. Useful for evaluating expressions in config files, prompts, key bindings, completions, templates, and many other user cases.
JavaScript
31
star
89

markdown-utils

Convert plain text into snippets of markdown.
JavaScript
30
star
90

grunt-readme

DEPRECATED. Use Verb instead
JavaScript
30
star
91

js-comments

Parse JavaScript code comments and generate API documentation.
JavaScript
30
star
92

justified

Wrap, align and justify the words in a string.
JavaScript
29
star
93

is-equal-shallow

Does a shallow comparison of two objects, returning false if the keys or values differ.
JavaScript
29
star
94

shallow-clone

Make a shallow clone of an object, array or primitive.
JavaScript
29
star
95

parse-filepath

Parse a filepath and return an object of path parts. Falls back on native node.js `path.parse` if it exists
JavaScript
29
star
96

yarn-api

Basic API for yarn.
JavaScript
28
star
97

is-directory

Extends `stats.isDirectory()`, returns `true` if a filepath is a directory.
JavaScript
28
star
98

global-prefix

Get the npm global path prefix. Same code used internally by npm.
JavaScript
28
star
99

rename-keys

Modify/rename the keys of the own enumerable properties of an object.
JavaScript
27
star
100

has-value

Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
JavaScript
27
star