All Projects → rsms → Markdown Wasm

rsms / Markdown Wasm

Licence: mit
Markdown parser and HTML generator implemented in WebAssembly, based on md4c

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Markdown Wasm

Diagon
Interactive ASCII art diagram generators. 🌟
Stars: ✭ 189 (-77.31%)
Mutual labels:  markdown, parser, webassembly
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (-32.05%)
Mutual labels:  parser, webassembly, wasm
React Markdown Editor Lite
a light-weight Markdown editor based on React. 一款轻量的基于React的markdown编辑器
Stars: ✭ 553 (-33.61%)
Mutual labels:  markdown, parser
Remarkable
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.
Stars: ✭ 5,252 (+530.49%)
Mutual labels:  markdown, parser
Graphql Client
Typed, correct GraphQL requests and responses in Rust
Stars: ✭ 620 (-25.57%)
Mutual labels:  webassembly, wasm
Webassembly
A minimal toolkit and runtime to produce and run WebAssembly modules.
Stars: ✭ 786 (-5.64%)
Mutual labels:  webassembly, wasm
Dotnet Webassembly
Create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications.
Stars: ✭ 535 (-35.77%)
Mutual labels:  webassembly, wasm
Wasm Loader
✨ WASM webpack loader
Stars: ✭ 604 (-27.49%)
Mutual labels:  webassembly, wasm
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+623.77%)
Mutual labels:  webassembly, wasm
Ngx Markdown
Angular markdown component/directive/pipe/service to parse static, dynamic or remote content to HTML with syntax highlight
Stars: ✭ 687 (-17.53%)
Mutual labels:  markdown, parser
Awesome Wasm
😎 Curated list of awesome things regarding WebAssembly (wasm) ecosystem.
Stars: ✭ 6,377 (+665.55%)
Mutual labels:  webassembly, wasm
Wasmer Php
🐘🕸️ WebAssembly runtime for PHP
Stars: ✭ 796 (-4.44%)
Mutual labels:  webassembly, wasm
Wasmtime
Standalone JIT-style runtime for WebAssembly, using Cranelift
Stars: ✭ 6,413 (+669.87%)
Mutual labels:  webassembly, wasm
Vim.wasm
Vim editor ported to WebAssembly
Stars: ✭ 4,915 (+490.04%)
Mutual labels:  webassembly, wasm
Zwitterion
A web dev server that lets you import anything*
Stars: ✭ 514 (-38.3%)
Mutual labels:  webassembly, wasm
Astro
A fun safe language for rapid prototyping and high performance applications
Stars: ✭ 588 (-29.41%)
Mutual labels:  webassembly, wasm
Ssvm
SSVM is a high performance, extensible, and hardware optimized WebAssembly Virtual Machine for cloud, AI, and blockchain applications.
Stars: ✭ 751 (-9.84%)
Mutual labels:  webassembly, wasm
Genact
🌀 A nonsense activity generator
Stars: ✭ 5,109 (+513.33%)
Mutual labels:  webassembly, wasm
Awesome Wasm Runtimes
A list of webassemby runtimes
Stars: ✭ 490 (-41.18%)
Mutual labels:  webassembly, wasm
Pib
PHP in Browser (powered by WebAssembly)
Stars: ✭ 649 (-22.09%)
Mutual labels:  webassembly, wasm

markdown-wasm

Very fast Markdown parser & HTML renderer implemented in WebAssembly

  • Zero dependencies (31 kB gzipped)
  • Portable & safe (WASM executes in isolated memory and can run almost anywhere)
  • Simple API
  • Very fast
  • Based on md4c — compliant to the CommonMark specification

Examples

In NodeJS, single file with embedded compressed WASM

const markdown = require("./dist/markdown.node.js")
console.log(markdown.parse("# hello\n*world*"))

ES module with WASM loaded separately

import * as markdown from "./dist/markdown.es.js"
await markdown.ready
console.log(markdown.parse("# hello\n*world*"))

Web browser

<script src="markdown.js"></script>
<script>
window["markdown"].ready.then(markdown => {
  console.log(markdown.parse("# hello\n*world*"))
})
</script>

Install

npm install markdown-wasm

Benchmarks

The test/benchmark directory contain a benchmark suite which you can run yourself. It tests a few popular markdown parser-renderers by parsing & rendering a bunch of different sample markdown files.

The following results were samples on a 2.9 GHz MacBook running macOS 10.15, NodeJS v14.11.0

Average ops/second

Ops/second represents how many times a library is able to parse markdown and render HTML during a second, on average across all sample files.

Average throughput

Throughput is the average amount of markdown data processed during a second while both parsing and rendering to HTML. The statistics does not include HTML generated but only bytes of markdown source text parsed.

Min–max parse time

This graph shows the spread between the fastest and slowest parse-and-render operations for each library. Lower numbers are better.

See test/benchmark for more information.

API

/**
 * 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

/** Markdown source code can be provided as a JavaScript string or UTF8 encoded data */
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
   */
  parseFlags? :ParseFlags

  /**
   * asMemoryView=true causes parse() to return a view of heap memory 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,
   * as each call to parse() uses the same underlying memory.
   *
   * 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.
   */
  asMemoryView? :boolean
}

/** Flags that customize Markdown parsing */
export enum ParseFlags {
  /** In TEXT, collapse non-trivial whitespace into single ' ' */ COLLAPSE_WHITESPACE,
  /** Enable $ and $$ containing LaTeX equations. */              LATEX_MATH_SPANS,
  /** Disable raw HTML blocks. */                                 NO_HTML_BLOCKS,
  /** Disable raw HTML (inline). */                               NO_HTML_SPANS,
  /** Disable indented code blocks. (Only fenced code works.) */  NO_INDENTED_CODE_BLOCKS,
  /** Do not require space in ATX headers ( ###header ) */        PERMISSIVE_ATX_HEADERS,
  /** Recognize e-mails as links even without <...> */            PERMISSIVE_EMAIL_AUTO_LINKS,
  /** Recognize URLs as links even without <...> */               PERMISSIVE_URL_AUTO_LINKS,
  /** Enable WWW autolinks (without proto; just 'www.') */        PERMISSIVE_WWW_AUTOLINKS,
  /** Enable strikethrough extension. */                          STRIKETHROUGH,
  /** Enable tables extension. */                                 TABLES,
  /** Enable task list extension. */                              TASK_LISTS,
  /** Enable wiki links extension. */                             WIKI_LINKS,

  /** Default flags */                                            DEFAULT,
  /** Shorthand for NO_HTML_BLOCKS | NO_HTML_SPANS */             NO_HTML,
}

See markdown.d.ts

Building from source

npm install
npx wasmc

Build debug version of markdown into ./build/debug and watch source files:

npx wasmc -g -w

If you need special builds, like for example an ES module with embedded WASM, edit the wasmc.js file and add module({...}) directives.

Example:

module({ ...m,
  name:   "markdown-custom",
  out:    outdir + "/markdown.custom.js",
  embed:  true,
  format: "es",
})
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].