markdown_yo 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -0
- package/index.d.ts +64 -0
- package/index.js +130 -0
- package/markdown_yo_demo.js +2 -0
- package/markdown_yo_demo.wasm +0 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# markdown_yo — WebAssembly API
|
|
2
|
+
|
|
3
|
+
A high-performance Markdown-to-HTML converter compiled to WebAssembly.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install markdown_yo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { createRenderer } from "markdown_yo";
|
|
15
|
+
|
|
16
|
+
const md = await createRenderer();
|
|
17
|
+
const html = md.render("# Hello\n\n**World**");
|
|
18
|
+
console.log(html);
|
|
19
|
+
// <h1>Hello</h1>
|
|
20
|
+
// <p><strong>World</strong></p>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API
|
|
24
|
+
|
|
25
|
+
### `createRenderer(wasmOptions?): Promise<MarkdownRenderer>`
|
|
26
|
+
|
|
27
|
+
Creates a new renderer instance by loading the WebAssembly module.
|
|
28
|
+
Call this once and reuse the returned renderer for all conversions.
|
|
29
|
+
|
|
30
|
+
**Parameters:**
|
|
31
|
+
|
|
32
|
+
| Name | Type | Description |
|
|
33
|
+
|------|------|-------------|
|
|
34
|
+
| `wasmOptions` | `WasmOptions` | Optional. Configuration for the Emscripten module loader. |
|
|
35
|
+
|
|
36
|
+
**`WasmOptions`:**
|
|
37
|
+
|
|
38
|
+
| Property | Type | Description |
|
|
39
|
+
|----------|------|-------------|
|
|
40
|
+
| `locateFile` | `(path: string, prefix: string) => string` | Custom resolver for the `.wasm` file location |
|
|
41
|
+
|
|
42
|
+
**Returns:** `Promise<MarkdownRenderer>`
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### `MarkdownRenderer.render(markdown, options?): string`
|
|
47
|
+
|
|
48
|
+
Render a Markdown string to HTML.
|
|
49
|
+
|
|
50
|
+
**Parameters:**
|
|
51
|
+
|
|
52
|
+
| Name | Type | Description |
|
|
53
|
+
|------|------|-------------|
|
|
54
|
+
| `markdown` | `string` | The Markdown source text |
|
|
55
|
+
| `options` | `RenderOptions` | Optional. Rendering options |
|
|
56
|
+
|
|
57
|
+
**`RenderOptions`:**
|
|
58
|
+
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
|--------|------|---------|-------------|
|
|
61
|
+
| `commonmark` | `boolean` | `false` | Use CommonMark-compliant parsing |
|
|
62
|
+
| `html` | `boolean` | `false` | Allow raw HTML tags in output |
|
|
63
|
+
| `typographer` | `boolean` | `false` | Enable typographic replacements (`"` → `"`, `--` → `—`, etc.) |
|
|
64
|
+
|
|
65
|
+
**Returns:** `string` — the rendered HTML
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### `MarkdownRenderer.destroy(): void`
|
|
70
|
+
|
|
71
|
+
Release WASM module resources. The renderer should not be used after calling this.
|
|
72
|
+
|
|
73
|
+
## Examples
|
|
74
|
+
|
|
75
|
+
### Node.js
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const { createRenderer } = require("markdown_yo");
|
|
79
|
+
|
|
80
|
+
async function main() {
|
|
81
|
+
const md = await createRenderer();
|
|
82
|
+
|
|
83
|
+
// Basic rendering
|
|
84
|
+
console.log(md.render("# Title\n\nA paragraph with **bold** text."));
|
|
85
|
+
|
|
86
|
+
// With CommonMark mode
|
|
87
|
+
console.log(md.render(source, { commonmark: true }));
|
|
88
|
+
|
|
89
|
+
// Allow HTML passthrough
|
|
90
|
+
console.log(md.render("<div>raw html</div>", { html: true }));
|
|
91
|
+
|
|
92
|
+
md.destroy();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
main();
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Browser (bundler)
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
import { createRenderer } from "markdown_yo";
|
|
102
|
+
|
|
103
|
+
const md = await createRenderer();
|
|
104
|
+
document.getElementById("preview").innerHTML = md.render(markdownSource);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Browser (script tag)
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<script src="https://unpkg.com/markdown_yo/markdown_yo_demo.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/markdown_yo/index.js"></script>
|
|
112
|
+
<script>
|
|
113
|
+
markdownYo.createRenderer().then((md) => {
|
|
114
|
+
const html = md.render("# Hello from **markdown_yo**!");
|
|
115
|
+
document.body.innerHTML = html;
|
|
116
|
+
});
|
|
117
|
+
</script>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Custom WASM file location
|
|
121
|
+
|
|
122
|
+
If you host the `.wasm` file separately (e.g., on a CDN), use `locateFile`:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
const md = await createRenderer({
|
|
126
|
+
locateFile: (path) => `https://cdn.example.com/wasm/${path}`,
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### TypeScript
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { createRenderer, type RenderOptions } from "markdown_yo";
|
|
134
|
+
|
|
135
|
+
const md = await createRenderer();
|
|
136
|
+
|
|
137
|
+
const opts: RenderOptions = { commonmark: true, html: true };
|
|
138
|
+
const html: string = md.render("# Hello", opts);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Supported Markdown Features
|
|
142
|
+
|
|
143
|
+
- **CommonMark** — 815/826 spec tests pass (98.7%)
|
|
144
|
+
- **GFM Tables** — pipe tables with alignment
|
|
145
|
+
- **Strikethrough** — `~~text~~`
|
|
146
|
+
- **Fenced code blocks** — with language info strings
|
|
147
|
+
- **HTML passthrough** — when `html: true` is set
|
|
148
|
+
- **Typographic replacements** — when `typographer: true` is set
|
|
149
|
+
|
|
150
|
+
## Live Demo
|
|
151
|
+
|
|
152
|
+
Try it in the browser: **https://shd101wyy.github.io/markdown_yo/**
|
|
153
|
+
|
|
154
|
+
## Building from Source
|
|
155
|
+
|
|
156
|
+
Requires the [Yo compiler](https://github.com/shd101wyy/Yo) and [Emscripten](https://emscripten.org/).
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# Install Yo compiler
|
|
160
|
+
npm install -g @shd101wyy/yo
|
|
161
|
+
|
|
162
|
+
# Build the WASM demo target
|
|
163
|
+
yo build demo
|
|
164
|
+
|
|
165
|
+
# Output files:
|
|
166
|
+
# yo-out/wasm32-emscripten/bin/markdown_yo_demo.js
|
|
167
|
+
# yo-out/wasm32-emscripten/bin/markdown_yo_demo.wasm
|
|
168
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering options for markdown conversion.
|
|
3
|
+
*/
|
|
4
|
+
export interface RenderOptions {
|
|
5
|
+
/** Use CommonMark-compliant parsing (default: false) */
|
|
6
|
+
commonmark?: boolean;
|
|
7
|
+
/** Allow raw HTML tags in output (default: false) */
|
|
8
|
+
html?: boolean;
|
|
9
|
+
/** Enable typographic replacements (default: false) */
|
|
10
|
+
typographer?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A markdown renderer instance backed by WebAssembly.
|
|
15
|
+
*/
|
|
16
|
+
export interface MarkdownRenderer {
|
|
17
|
+
/**
|
|
18
|
+
* Render a markdown string to HTML.
|
|
19
|
+
* @param markdown - The markdown source text
|
|
20
|
+
* @param options - Rendering options
|
|
21
|
+
* @returns The rendered HTML string
|
|
22
|
+
*/
|
|
23
|
+
render(markdown: string, options?: RenderOptions): string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Free WASM module resources.
|
|
27
|
+
* After calling destroy(), the renderer should not be used.
|
|
28
|
+
*/
|
|
29
|
+
destroy(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Options for the Emscripten module loader.
|
|
34
|
+
*/
|
|
35
|
+
export interface WasmOptions {
|
|
36
|
+
/** Custom path resolver for the .wasm file */
|
|
37
|
+
locateFile?: (path: string, prefix: string) => string;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a markdown renderer instance.
|
|
43
|
+
*
|
|
44
|
+
* Loads the WebAssembly module and returns a renderer with a simple
|
|
45
|
+
* `render(markdown, options?)` API.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { createRenderer } from "markdown_yo";
|
|
50
|
+
*
|
|
51
|
+
* const md = await createRenderer();
|
|
52
|
+
* const html = md.render("# Hello\n\n**World**");
|
|
53
|
+
* console.log(html);
|
|
54
|
+
* // => <h1>Hello</h1>\n<p><strong>World</strong></p>
|
|
55
|
+
*
|
|
56
|
+
* // With options
|
|
57
|
+
* const html2 = md.render(src, { commonmark: true, html: true });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function createRenderer(
|
|
61
|
+
wasmOptions?: WasmOptions,
|
|
62
|
+
): Promise<MarkdownRenderer>;
|
|
63
|
+
|
|
64
|
+
export default createRenderer;
|
package/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* markdown_yo — High-performance Markdown-to-HTML converter (WebAssembly)
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```js
|
|
6
|
+
* import { createRenderer } from "markdown_yo";
|
|
7
|
+
* const md = await createRenderer();
|
|
8
|
+
* const html = md.render("# Hello\n\nWorld");
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Re-export the Emscripten module loader
|
|
13
|
+
const createMarkdownYo =
|
|
14
|
+
typeof require !== "undefined"
|
|
15
|
+
? require("./markdown_yo_demo.js")
|
|
16
|
+
: undefined;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Render options for markdown conversion.
|
|
20
|
+
* @typedef {Object} RenderOptions
|
|
21
|
+
* @property {boolean} [commonmark=false] - Use CommonMark-compliant parsing
|
|
22
|
+
* @property {boolean} [html=false] - Allow raw HTML tags in output
|
|
23
|
+
* @property {boolean} [typographer=false] - Enable typographic replacements
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A markdown renderer instance backed by WebAssembly.
|
|
28
|
+
* @typedef {Object} MarkdownRenderer
|
|
29
|
+
* @property {function(string, RenderOptions=): string} render - Render markdown to HTML
|
|
30
|
+
* @property {function(): void} destroy - Free WASM resources
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Build a flags bitmask from options.
|
|
35
|
+
* @param {RenderOptions} [options]
|
|
36
|
+
* @returns {number}
|
|
37
|
+
*/
|
|
38
|
+
function buildFlags(options) {
|
|
39
|
+
if (!options) return 0;
|
|
40
|
+
let flags = 0;
|
|
41
|
+
if (options.commonmark) flags |= 1;
|
|
42
|
+
if (options.html) flags |= 2;
|
|
43
|
+
if (options.typographer) flags |= 4;
|
|
44
|
+
return flags;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create a markdown renderer instance.
|
|
49
|
+
*
|
|
50
|
+
* Loads the WebAssembly module and returns a renderer with a simple
|
|
51
|
+
* `render(markdown, options?)` API.
|
|
52
|
+
*
|
|
53
|
+
* @param {Object} [wasmOptions] - Options passed to the Emscripten module loader
|
|
54
|
+
* @param {string} [wasmOptions.locateFile] - Custom path resolver for .wasm file
|
|
55
|
+
* @returns {Promise<MarkdownRenderer>}
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```js
|
|
59
|
+
* import { createRenderer } from "markdown_yo";
|
|
60
|
+
*
|
|
61
|
+
* const md = await createRenderer();
|
|
62
|
+
* console.log(md.render("**bold**"));
|
|
63
|
+
* // => <p><strong>bold</strong></p>
|
|
64
|
+
*
|
|
65
|
+
* console.log(md.render("# Title", { commonmark: true, html: true }));
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
async function createRenderer(wasmOptions) {
|
|
69
|
+
let loader;
|
|
70
|
+
if (createMarkdownYo) {
|
|
71
|
+
loader = createMarkdownYo;
|
|
72
|
+
} else {
|
|
73
|
+
// ESM / browser dynamic import
|
|
74
|
+
const mod = await import("./markdown_yo_demo.js");
|
|
75
|
+
loader = mod.default || mod.createMarkdownYo || mod;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const Module = await loader(wasmOptions || {});
|
|
79
|
+
const encoder = new TextEncoder();
|
|
80
|
+
const decoder = new TextDecoder();
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
/**
|
|
84
|
+
* Render a markdown string to HTML.
|
|
85
|
+
* @param {string} markdown - The markdown source text
|
|
86
|
+
* @param {RenderOptions} [options] - Rendering options
|
|
87
|
+
* @returns {string} The rendered HTML
|
|
88
|
+
*/
|
|
89
|
+
render(markdown, options) {
|
|
90
|
+
const inputBytes = encoder.encode(markdown);
|
|
91
|
+
const inputPtr = Module._malloc(inputBytes.length);
|
|
92
|
+
try {
|
|
93
|
+
Module.HEAPU8.set(inputBytes, inputPtr);
|
|
94
|
+
const flags = buildFlags(options);
|
|
95
|
+
const resultPtr = Module._wasm_render(
|
|
96
|
+
inputPtr,
|
|
97
|
+
inputBytes.length,
|
|
98
|
+
flags,
|
|
99
|
+
);
|
|
100
|
+
const resultLen = Module._wasm_result_len();
|
|
101
|
+
const resultBytes = Module.HEAPU8.slice(
|
|
102
|
+
resultPtr,
|
|
103
|
+
resultPtr + resultLen,
|
|
104
|
+
);
|
|
105
|
+
Module._wasm_free(resultPtr);
|
|
106
|
+
return decoder.decode(resultBytes);
|
|
107
|
+
} finally {
|
|
108
|
+
Module._free(inputPtr);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Free WASM module resources.
|
|
114
|
+
* After calling destroy(), the renderer should not be used.
|
|
115
|
+
*/
|
|
116
|
+
destroy() {
|
|
117
|
+
// Emscripten modules don't have a standard destroy, but we clear the ref
|
|
118
|
+
Module = null;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// CommonJS + ESM compatible exports
|
|
124
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
125
|
+
module.exports = { createRenderer };
|
|
126
|
+
module.exports.createRenderer = createRenderer;
|
|
127
|
+
module.exports.default = createRenderer;
|
|
128
|
+
} else if (typeof globalThis !== "undefined") {
|
|
129
|
+
globalThis.markdownYo = { createRenderer };
|
|
130
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var createMarkdownYo=(()=>{var _scriptName=typeof document!="undefined"?document.currentScript?.src:undefined;return async function(moduleArg={}){var moduleRtn;var Module=moduleArg;var ENVIRONMENT_IS_WEB=true;var ENVIRONMENT_IS_WORKER=false;var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var EXITSTATUS;var readyPromiseResolve,readyPromiseReject;var wasmMemory;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["j"]()}function preMain(){}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}var runDependencies=0;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject?.(e);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("markdown_yo_demo.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){return{a:wasmImports}}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["i"];updateMemoryViews();assignWasmExports(wasmExports);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(mod,inst)=>{resolve(receiveInstance(mod,inst))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var noExitRuntime=true;var __abort_js=()=>abort("");var runtimeKeepaliveCounter=0;var __emscripten_runtime_keepalive_clear=()=>{noExitRuntime=false;runtimeKeepaliveCounter=0};var timers={};var handleException=e=>{if(e instanceof ExitStatus||e=="unwind"){return EXITSTATUS}quit_(1,e)};var keepRuntimeAlive=()=>noExitRuntime||runtimeKeepaliveCounter>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var exitJS=(status,implicit)=>{EXITSTATUS=status;_proc_exit(status)};var _exit=exitJS;var maybeExit=()=>{if(!keepRuntimeAlive()){try{_exit(EXITSTATUS)}catch(e){handleException(e)}}};var callUserCallback=func=>{if(ABORT){return}try{func();maybeExit()}catch(e){handleException(e)}};var _emscripten_get_now=()=>performance.now();var __setitimer_js=(which,timeout_ms)=>{if(timers[which]){clearTimeout(timers[which].id);delete timers[which]}if(!timeout_ms)return 0;var id=setTimeout(()=>{delete timers[which];callUserCallback(()=>__emscripten_timeout(which,_emscripten_get_now()))},timeout_ms);timers[which]={id,timeout_ms};return 0};var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var _fd_close=fd=>52;var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>num<INT53_MIN||num>INT53_MAX?NaN:Number(num);function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);return 70}var printCharBuffers=[null,[],[]];var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder:undefined;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};var _fd_write=(fd,iov,iovcnt,pnum)=>{var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j])}num+=len}HEAPU32[pnum>>2]=num;return 0};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"]}var _wasm_render,_malloc,_wasm_result_len,_wasm_free,_free,_main,__emscripten_timeout,__emscripten_stack_alloc,dynCall_ii,dynCall_iiii,dynCall_jiji,dynCall_vi;function assignWasmExports(wasmExports){Module["_wasm_render"]=_wasm_render=wasmExports["k"];Module["_malloc"]=_malloc=wasmExports["l"];Module["_wasm_result_len"]=_wasm_result_len=wasmExports["m"];Module["_wasm_free"]=_wasm_free=wasmExports["n"];Module["_free"]=_free=wasmExports["o"];Module["_main"]=_main=wasmExports["p"];__emscripten_timeout=wasmExports["q"];__emscripten_stack_alloc=wasmExports["r"];dynCall_ii=wasmExports["dynCall_ii"];dynCall_iiii=wasmExports["dynCall_iiii"];dynCall_jiji=wasmExports["dynCall_jiji"];dynCall_vi=wasmExports["dynCall_vi"]}var wasmImports={h:__abort_js,b:__emscripten_runtime_keepalive_clear,c:__setitimer_js,d:_emscripten_resize_heap,g:_fd_close,e:_fd_seek,f:_fd_write,a:_proc_exit};var wasmExports=await createWasm();function callMain(args=[]){var entryFunction=_main;args.unshift(thisProgram);var argc=args.length;var argv=stackAlloc((argc+1)*4);var argv_ptr=argv;args.forEach(arg=>{HEAPU32[argv_ptr>>2]=stringToUTF8OnStack(arg);argv_ptr+=4});HEAPU32[argv_ptr>>2]=0;try{var ret=entryFunction(argc,argv);exitJS(ret,true);return ret}catch(e){return handleException(e)}}function run(args=arguments_){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();preMain();readyPromiseResolve?.(Module);Module["onRuntimeInitialized"]?.();var noInitialRun=Module["noInitialRun"]||false;if(!noInitialRun)callMain(args);postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}function preInit(){if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}preInit();run();if(runtimeInitialized){moduleRtn=Module}else{moduleRtn=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject})}
|
|
2
|
+
;return moduleRtn}})();if(typeof exports==="object"&&typeof module==="object"){module.exports=createMarkdownYo;module.exports.default=createMarkdownYo}else if(typeof define==="function"&&define["amd"])define([],()=>createMarkdownYo);
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown_yo",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "A high-performance Markdown-to-HTML converter compiled to WebAssembly",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"markdown_yo_demo.js",
|
|
11
|
+
"markdown_yo_demo.wasm",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"markdown",
|
|
16
|
+
"html",
|
|
17
|
+
"parser",
|
|
18
|
+
"wasm",
|
|
19
|
+
"webassembly",
|
|
20
|
+
"commonmark"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/shd101wyy/markdown_yo.git"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://shd101wyy.github.io/markdown_yo/",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "shd101wyy"
|
|
29
|
+
}
|