All Projects → jonschlinkert → Remarkable

jonschlinkert / Remarkable

Licence: mit
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.

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to Remarkable

Breakdance
It's time for your markup to get down! HTML to markdown converter. Breakdance is a highly pluggable, flexible and easy to use.
Stars: ✭ 418 (-92.04%)
Mutual labels:  compile, markdown, parse, commonmark, gfm
Micromark
the smallest commonmark compliant markdown parser that exists; new basis for @unifiedjs (hundreds of projects w/ billions of downloads for dealing w/ content)
Stars: ✭ 793 (-84.9%)
Mutual labels:  compile, markdown, parse, commonmark, gfm
Marked
A markdown parser and compiler. Built for speed.
Stars: ✭ 26,556 (+405.64%)
Mutual labels:  markdown, parser, commonmark, gfm
Md4c
C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
Stars: ✭ 322 (-93.87%)
Mutual labels:  markdown, parser, commonmark, markdown-parser
Markdig
A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
Stars: ✭ 2,730 (-48.02%)
Mutual labels:  markdown, commonmark, gfm, markdown-parser
Vditor
♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。An In-browser Markdown editor, support WYSIWYG (Rich Text), Instant Rendering (Typora-like) and Split View modes.
Stars: ✭ 3,773 (-28.16%)
Mutual labels:  markdown, commonmark, gfm, md
Ngx Markdown
Angular markdown component/directive/pipe/service to parse static, dynamic or remote content to HTML with syntax highlight
Stars: ✭ 687 (-86.92%)
Mutual labels:  markdown, parser, syntax-highlighting, md
Lute
🎼 一款对中文语境优化的 Markdown 引擎,支持 Go 和 JavaScript。A structured Markdown engine that supports Go and JavaScript.
Stars: ✭ 222 (-95.77%)
Mutual labels:  markdown, commonmark, gfm, md
Showdown
A bidirectional Markdown to HTML to Markdown converter written in Javascript
Stars: ✭ 12,137 (+131.09%)
Mutual labels:  markdown, gfm, markdown-parser
Tui.editor
🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
Stars: ✭ 14,016 (+166.87%)
Mutual labels:  markdown, commonmark, gfm
Markserv
🏁 serve markdown as html (GitHub style), index directories, live-reload as you edit
Stars: ✭ 304 (-94.21%)
Mutual labels:  markdown, gfm, md
Commonmark
Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
Stars: ✭ 2,128 (-59.48%)
Mutual labels:  markdown, commonmark, gfm
Vditor
♏ 一款浏览器端的 Markdown 编辑器。
Stars: ✭ 1,742 (-66.83%)
Mutual labels:  markdown, commonmark, gfm
Editor.md
The open source embeddable online markdown editor (component).
Stars: ✭ 11,741 (+123.55%)
Mutual labels:  markdown, commonmark, gfm
Commonmark Java
Java library for parsing and rendering CommonMark (Markdown)
Stars: ✭ 1,675 (-68.11%)
Mutual labels:  markdown, parser, commonmark
Parsedown
Better Markdown Parser in PHP
Stars: ✭ 13,959 (+165.78%)
Mutual labels:  markdown, parser, markdown-parser
Lute
🎼 一款结构化的 Markdown 引擎,支持 Go 和 JavaScript。
Stars: ✭ 211 (-95.98%)
Mutual labels:  markdown, commonmark, gfm
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-96.57%)
Mutual labels:  compile, parser, parse
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (-59.92%)
Mutual labels:  markdown, parse, jonschlinkert
Flexmark Java
CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
Stars: ✭ 1,673 (-68.15%)
Mutual labels:  markdown, commonmark, markdown-parser

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].