Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rsms committed Dec 9, 2019
0 parents commit 46892d1
Show file tree
Hide file tree
Showing 35 changed files with 9,258 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
/_*
**/.DS_Store
/build
/node_modules
*.sublime*
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2019 Rasmus Andersson <https://rsms.me/>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
114 changes: 114 additions & 0 deletions README.md
@@ -0,0 +1,114 @@
# markdown-wasm

Very fast Markdown parser & HTML renderer implemented in WebAssembly

- Zero dependencies
- Portable
- Simple API
- Fast and efficient

Based on [md4c](http://github.com/mity/md4c)


## Examples

In Nodejs

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

ES module

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

Separately loded wasm module (useful in web browsers)

```js
require("./dist/markdown").ready.then(markdown => {
console.log(markdown.parse("# hello\n*world*"))
})
```


## API

```ts
/**
* 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-es into ./build/debug and watch source files:

```
npx wasmc -g -w
```
3 changes: 3 additions & 0 deletions dist/markdown.es.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/markdown.es.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 46892d1

Please sign in to comment.