Compare commits

..

3 commits

Author SHA1 Message Date
Daniel Bulant
ad5043fd69 Render SVG images 2021-08-08 16:35:13 +02:00
Daniel Bulant
41cf2dc97c add remarkable benchmark 2021-08-08 16:31:39 +02:00
Rasmus Andersson
0d99d1151f readme 2021-07-06 13:11:58 -07:00
6 changed files with 60 additions and 21 deletions

View file

@ -89,29 +89,22 @@ See [`test/benchmark`](test/benchmark#readme) for more information.
* parse reads markdown source at s and converts it to HTML.
* When output is a byte array, it will be a reference.
*/
export function parse(s :Source, o? :ParseOptions & { asMemoryView? :never|false }) :string
export function parse(s :Source, o? :ParseOptions & { asMemoryView :true }) :Uint8Array
export function parse(s :Source, o? :ParseOptions & { bytes? :never|false }) :string
export function parse(s :Source, o? :ParseOptions & { bytes :true }) :Uint8Array
/** Markdown source code can be provided as a JavaScript string or UTF8 encoded data */
type Source = string|ArrayLike<number>
type Source = string | ArrayLike<number>
/** Options for the parse function */
export interface ParseOptions {
/**
* Customize parsing.
* If not provided, the following flags are used, equating to github-style parsing:
* COLLAPSE_WHITESPACE
* PERMISSIVE_ATX_HEADERS
* PERMISSIVE_URL_AUTO_LINKS
* STRIKETHROUGH
* TABLES
* TASK_LISTS
*/
/** Customize parsing. Defaults to ParseFlags.DEFAULT */
parseFlags? :ParseFlags
/** Select output format. Defaults to "html" */
format? : "html" | "xhtml"
/**
* asMemoryView=true causes parse() to return a view of heap memory as a Uint8Array,
* instead of a string.
* bytes=true causes parse() to return the result as a Uint8Array instead of a string.
*
* The returned Uint8Array is only valid until the next call to parse().
* If you need to keep the returned data around, call Uint8Array.slice() to make a copy,
@ -120,9 +113,36 @@ export interface ParseOptions {
* This only provides a performance benefit when you never need to convert the output
* to a string. In most cases you're better off leaving this unset or false.
*/
bytes? :boolean
/** Allow "javascript:" in links */
allowJSURIs? :boolean
/**
* Optional callback which if provided is called for each code block.
* langname holds the "language tag", if any, of the block.
*
* The returned value is inserted into the resulting HTML verbatim, without HTML escaping.
* Thus, you should take care of properly escaping any special HTML characters.
*
* If the function returns null or undefined, or an exception occurs, the body will be
* included as-is after going through HTML escaping.
*
* Note that use of this callback has an adverse impact on performance as it casues
* calls and data to be bridged between WASM and JS on every invocation.
*/
onCodeBlock? :(langname :string, body :UTF8Bytes) => Uint8Array|string|null|undefined
/** @depreceated use "bytes" instead (v1.1.1) */
asMemoryView? :boolean
}
/** UTF8Bytes is a Uint8Array representing UTF8 text */
export interface UTF8Bytes extends Uint8Array {
/** toString returns a UTF8 decoded string (lazily decoded and cached) */
toString() :string
}
/** Flags that customize Markdown parsing */
export enum ParseFlags {
/** In TEXT, collapse non-trivial whitespace into single ' ' */ COLLAPSE_WHITESPACE,
@ -138,13 +158,24 @@ export enum ParseFlags {
/** Enable tables extension. */ TABLES,
/** Enable task list extension. */ TASK_LISTS,
/** Enable wiki links extension. */ WIKI_LINKS,
/** Enable underline extension (disables '_' for emphasis) */ UNDERLINE,
/** Default flags */ DEFAULT,
/** Shorthand for NO_HTML_BLOCKS | NO_HTML_SPANS */ NO_HTML,
/** Default flags are:
* COLLAPSE_WHITESPACE |
* PERMISSIVE_ATX_HEADERS |
* PERMISSIVE_URL_AUTO_LINKS |
* STRIKETHROUGH |
* TABLES |
* TASK_LISTS
*/
DEFAULT,
/** Shorthand for NO_HTML_BLOCKS | NO_HTML_SPANS */
NO_HTML,
}
```
See `markdown.d.ts`
See [`markdown.d.ts`](markdown.d.ts)
## Building from source

View file

@ -6,6 +6,7 @@ const Path = require('path')
const commonmark = require('commonmark')
const Showdown = require('showdown')
const marked = require('marked')
const { Remarkable } = require('remarkable');
const markdownit = require('markdown-it')('commonmark')
const markdown_wasm = require('../../dist/markdown.node.js')
@ -22,6 +23,9 @@ var showdown = new Showdown.Converter()
var parser = new commonmark.Parser()
var renderer = new commonmark.HtmlRenderer()
// setup remarkable
var remarkable = new Remarkable();
// parse CLI input
let filename = process.argv[2]
if (!filename) {
@ -76,6 +80,9 @@ function benchmarkFile(benchfile) {
.add('marked', function() {
marked(contents);
})
.add('remarkable', function() {
remarkable.render(contents);
})
.add('markdown-it', function() {
markdownit.render(contents);
})

View file

@ -18,6 +18,7 @@
"d3-node": "^2.2.2",
"markdown-it": "^10.0.0",
"marked": "^0.7.0",
"remarkable": "^2.0.1",
"showdown": "^1.9.1",
"svgo": "^1.3.2"
}

View file

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="840" height="264" font-family="-apple-system,BlinkMacSystemFont,&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif" font-size="16"><g text-anchor="end" font-weight="500"><text alignment-baseline="central" x="156" y="68" dx="-10">markdown-wasm</text><text alignment-baseline="central" x="156" y="104" dx="-10">markdown-it</text><text alignment-baseline="central" x="156" y="140" dx="-10">marked</text><text alignment-baseline="central" x="156" y="176" dx="-10">commonmark</text><text alignment-baseline="central" x="156" y="212" dx="-10">showdown</text></g><path fill="#4e79a7" d="M156 52h668v32H156z"/><path fill="#f28e2c" d="M156 88h290.307v32H156z"/><path fill="#e15759" d="M156 124h263.486v32H156z"/><path fill="#76b7b2" d="M156 160h226.65v32H156z"/><path fill="#59a14f" d="M156 196h29.116v32H156z"/><g fill="#fff" text-anchor="end" font-weight="500"><text x="824" y="68" alignment-baseline="central" dx="-5">195,065</text><text x="446.307" y="104" alignment-baseline="central" dx="-5">84,774</text><text x="419.486" y="140" alignment-baseline="central" dx="-5">76,942</text><text x="382.65" y="176" alignment-baseline="central" dx="-5">66,185</text><text x="185.116" y="212" alignment-baseline="central" dx="5" fill="#000" text-anchor="start">8,502</text></g><g fill="none" font-size="12.8" text-anchor="middle" opacity=".5"><g class="tick"><path stroke="currentColor" d="M156.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(156.5 48)">0</text></g><g class="tick"><path stroke="currentColor" d="M224.99 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(224.99 48)">20,000</text></g><g class="tick"><path stroke="currentColor" d="M293.48 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(293.48 48)">40,000</text></g><g class="tick"><path stroke="currentColor" d="M361.97 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(361.97 48)">60,000</text></g><g class="tick"><path stroke="currentColor" d="M430.46 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(430.46 48)">80,000</text></g><g class="tick"><path stroke="currentColor" d="M498.95 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(498.95 48)">100,000</text></g><g class="tick"><path stroke="currentColor" d="M567.44 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(567.44 48)">120,000</text></g><g class="tick"><path stroke="currentColor" d="M635.93 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(635.93 48)">140,000</text></g><g class="tick"><path stroke="currentColor" d="M704.42 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(704.42 48)">160,000</text></g><g class="tick"><path stroke="currentColor" d="M772.909 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(772.909 48)">180,000</text></g></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="840" height="300" font-family="-apple-system,BlinkMacSystemFont,&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif" font-size="16"><g text-anchor="end" font-weight="500"><text alignment-baseline="central" x="156" y="68" dx="-10">markdown-wasm</text><text alignment-baseline="central" x="156" y="104" dx="-10">remarkable</text><text alignment-baseline="central" x="156" y="140" dx="-10">markdown-it</text><text alignment-baseline="central" x="156" y="176" dx="-10">marked</text><text alignment-baseline="central" x="156" y="212" dx="-10">commonmark</text><text alignment-baseline="central" x="156" y="248" dx="-10">showdown</text></g><path fill="#4e79a7" d="M156 52h668v32H156z"/><path fill="#f28e2c" d="M156 88h453.666v32H156z"/><path fill="#e15759" d="M156 124h300.527v32H156z"/><path fill="#76b7b2" d="M156 160h259.363v32H156z"/><path fill="#59a14f" d="M156 196h210.906v32H156z"/><path fill="#edc949" d="M156 232h30.517v32H156z"/><g fill="#fff" text-anchor="end" font-weight="500"><text x="824" y="68" alignment-baseline="central" dx="-5">136,888</text><text x="609.666" y="104" alignment-baseline="central" dx="-5">92,966</text><text x="456.527" y="140" alignment-baseline="central" dx="-5">61,584</text><text x="415.363" y="176" alignment-baseline="central" dx="-5">53,149</text><text x="366.906" y="212" alignment-baseline="central" dx="-5">43,219</text><text x="186.517" y="248" alignment-baseline="central" dx="5" fill="#000" text-anchor="start">6,254</text></g><g fill="none" font-size="12.8" text-anchor="middle" opacity=".5"><g class="tick"><path stroke="currentColor" d="M156.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(156.5 48)">0</text></g><g class="tick"><path stroke="currentColor" d="M254.098 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(254.098 48)">20,000</text></g><g class="tick"><path stroke="currentColor" d="M351.697 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(351.697 48)">40,000</text></g><g class="tick"><path stroke="currentColor" d="M449.295 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(449.295 48)">60,000</text></g><g class="tick"><path stroke="currentColor" d="M546.893 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(546.893 48)">80,000</text></g><g class="tick"><path stroke="currentColor" d="M644.491 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(644.491 48)">100,000</text></g><g class="tick"><path stroke="currentColor" d="M742.09 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(742.09 48)">120,000</text></g></g></svg>

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="840" height="264" font-family="-apple-system,BlinkMacSystemFont,&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif" font-size="16"><path fill="#4e79a7" d="M21 52h486v32H21z"/><path fill="#e15759" d="M16 88h576v32H16z"/><path fill="#f28e2c" d="M21 124h573v32H21z"/><path fill="#76b7b2" d="M70 160h541v32H70z"/><path fill="#59a14f" d="M227 196h597v32H227z"/><g fill="#fff" font-weight="500" text-anchor="middle"><text x="264" y="68" alignment-baseline="central">markdown-wasm</text><text x="304" y="104" alignment-baseline="central">marked</text><text x="307.5" y="140" alignment-baseline="central">markdown-it</text><text x="340.5" y="176" alignment-baseline="central">commonmark</text><text x="525.5" y="212" alignment-baseline="central">showdown</text></g><g fill="#fff" font-weight="500"><text x="21" y="68" alignment-baseline="central" dx="5">2.0us</text><text x="16" y="104" alignment-baseline="central" dx="5">1.8us</text><text x="21" y="140" alignment-baseline="central" dx="5">2.0us</text><text x="70" y="176" alignment-baseline="central" dx="5">4.0us</text><text x="227" y="212" alignment-baseline="central" dx="5">40.8us</text></g><g fill="#fff" font-weight="500" text-anchor="end"><text x="507" y="68" alignment-baseline="central" dx="-5">2.5ms</text><text x="592" y="104" alignment-baseline="central" dx="-5">8.6ms</text><text x="594" y="140" alignment-baseline="central" dx="-5">8.9ms</text><text x="611" y="176" alignment-baseline="central" dx="-5">11.4ms</text><text x="824" y="212" alignment-baseline="central" dx="-5">262.8ms</text></g><g fill="none" font-size="12.8" text-anchor="middle" opacity=".5"><path stroke="currentColor" d="M22.5 48v-6M50.5 48v-6M69.5 48v-6M85.5 48v-6M97.5 48v-6M108.5 48v-6M117.5 48v-6M125.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M132.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(132.5 48)">10.0us</text></g><path stroke="currentColor" d="M179.5 48v-6M207.5 48v-6M226.5 48v-6M241.5 48v-6M254.5 48v-6M264.5 48v-6M273.5 48v-6M281.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M288.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(288.5 48)">100.0us</text></g><path stroke="currentColor" d="M336.5 48v-6M363.5 48v-6M383.5 48v-6M398.5 48v-6M410.5 48v-6M421.5 48v-6M430.5 48v-6M438.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M445.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(445.5 48)">1000.0us</text></g><path stroke="currentColor" d="M492.5 48v-6M520.5 48v-6M539.5 48v-6M555.5 48v-6M567.5 48v-6M577.5 48v-6M586.5 48v-6M594.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M602.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(602.5 48)">10.0ms</text></g><path stroke="currentColor" d="M649.5 48v-6M676.5 48v-6M696.5 48v-6M711.5 48v-6M724.5 48v-6M734.5 48v-6M743.5 48v-6M751.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M758.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(758.5 48)">100.0ms</text></g><path stroke="currentColor" d="M805.5 48v-6"/></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="840" height="300" font-family="-apple-system,BlinkMacSystemFont,&quot;Segoe UI&quot;,Helvetica,Arial,sans-serif" font-size="16"><path fill="#4e79a7" d="M45 52h483v32H45z"/><path fill="#f28e2c" d="M16 88h582v32H16z"/><path fill="#76b7b2" d="M38 124h584v32H38z"/><path fill="#e15759" d="M47 160h578v32H47z"/><path fill="#59a14f" d="M96 196h553v32H96z"/><path fill="#edc949" d="M258 232h566v32H258z"/><g fill="#fff" font-weight="500" text-anchor="middle"><text x="286.5" y="68" alignment-baseline="central">markdown-wasm</text><text x="307" y="104" alignment-baseline="central">remarkable</text><text x="330" y="140" alignment-baseline="central">marked</text><text x="336" y="176" alignment-baseline="central">markdown-it</text><text x="372.5" y="212" alignment-baseline="central">commonmark</text><text x="541" y="248" alignment-baseline="central">showdown</text></g><g fill="#fff" font-weight="500"><text x="45" y="68" alignment-baseline="central" dx="5">2.7us</text><text x="16" y="104" alignment-baseline="central" dx="5">1.8us</text><text x="38" y="140" alignment-baseline="central" dx="5">2.5us</text><text x="47" y="176" alignment-baseline="central" dx="5">2.8us</text><text x="96" y="212" alignment-baseline="central" dx="5">5.7us</text><text x="258" y="248" alignment-baseline="central" dx="5">59.6us</text></g><g fill="#fff" font-weight="500" text-anchor="end"><text x="528" y="68" alignment-baseline="central" dx="-5">3.1ms</text><text x="598" y="104" alignment-baseline="central" dx="-5">8.4ms</text><text x="622" y="140" alignment-baseline="central" dx="-5">12.0ms</text><text x="625" y="176" alignment-baseline="central" dx="-5">12.5ms</text><text x="649" y="212" alignment-baseline="central" dx="-5">17.9ms</text><text x="824" y="248" alignment-baseline="central" dx="-5">226.4ms</text></g><g fill="none" font-size="12.8" text-anchor="middle" opacity=".5"><path stroke="currentColor" d="M24.5 48v-6M52.5 48v-6M72.5 48v-6M87.5 48v-6M100.5 48v-6M111.5 48v-6M120.5 48v-6M128.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M135.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(135.5 48)">10.0us</text></g><path stroke="currentColor" d="M183.5 48v-6M211.5 48v-6M230.5 48v-6M246.5 48v-6M258.5 48v-6M269.5 48v-6M278.5 48v-6M286.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M293.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(293.5 48)">100.0us</text></g><path stroke="currentColor" d="M341.5 48v-6M369.5 48v-6M388.5 48v-6M404.5 48v-6M416.5 48v-6M427.5 48v-6M436.5 48v-6M444.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M451.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(451.5 48)">1000.0us</text></g><path stroke="currentColor" d="M499.5 48v-6M527.5 48v-6M547.5 48v-6M562.5 48v-6M575.5 48v-6M585.5 48v-6M594.5 48v-6M602.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M610.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(610.5 48)">10.0ms</text></g><path stroke="currentColor" d="M657.5 48v-6M685.5 48v-6M705.5 48v-6M720.5 48v-6M733.5 48v-6M743.5 48v-6M753.5 48v-6M761.5 48v-6"/><g class="tick"><path stroke="currentColor" d="M768.5 48v-6"/><text fill="currentColor" y="-9" dy="0em" transform="translate(768.5 48)">100.0ms</text></g><path stroke="currentColor" d="M815.5 48v-6"/></g></svg>

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB