markdown_yo 0.0.3 → 0.0.4

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 CHANGED
@@ -61,6 +61,11 @@ Render a Markdown string to HTML.
61
61
  | `commonmark` | `boolean` | `false` | Use CommonMark-compliant parsing |
62
62
  | `html` | `boolean` | `false` | Allow raw HTML tags in output |
63
63
  | `typographer` | `boolean` | `false` | Enable typographic replacements (`"` → `"`, `--` → `—`, etc.) |
64
+ | `subscript` | `boolean` | `false` | Enable `~subscript~` syntax → `<sub>` |
65
+ | `superscript` | `boolean` | `false` | Enable `^superscript^` syntax → `<sup>` |
66
+ | `mark` | `boolean` | `false` | Enable `==highlight==` syntax → `<mark>` |
67
+ | `math` | `boolean` | `false` | Enable `$inline$` and `$$block$$` math syntax |
68
+ | `fullFeatures` | `boolean` | `false` | Enable all optional features at once |
64
69
 
65
70
  **Returns:** `string` — the rendered HTML
66
71
 
@@ -107,7 +112,7 @@ document.getElementById("preview").innerHTML = md.render(markdownSource);
107
112
  ### Browser (script tag)
108
113
 
109
114
  ```html
110
- <script src="https://unpkg.com/markdown_yo/markdown_yo_demo.js"></script>
115
+ <script src="https://unpkg.com/markdown_yo/markdown_yo_wasm_api.js"></script>
111
116
  <script src="https://unpkg.com/markdown_yo/index.js"></script>
112
117
  <script>
113
118
  markdownYo.createRenderer().then((md) => {
@@ -146,6 +151,10 @@ const html: string = md.render("# Hello", opts);
146
151
  - **Fenced code blocks** — with language info strings
147
152
  - **HTML passthrough** — when `html: true` is set
148
153
  - **Typographic replacements** — when `typographer: true` is set
154
+ - **Subscript** — `~text~` → `<sub>text</sub>` (when `subscript: true`)
155
+ - **Superscript** — `^text^` → `<sup>text</sup>` (when `superscript: true`)
156
+ - **Mark/Highlight** — `==text==` → `<mark>text</mark>` (when `mark: true`)
157
+ - **Math** — `$inline$` and `$$block$$` math (when `math: true`)
149
158
 
150
159
  ## Live Demo
151
160
 
@@ -159,10 +168,10 @@ Requires the [Yo compiler](https://github.com/shd101wyy/Yo) and [Emscripten](htt
159
168
  # Install Yo compiler
160
169
  npm install -g @shd101wyy/yo
161
170
 
162
- # Build the WASM demo target
163
- yo build demo
171
+ # Build the WASM API target
172
+ yo build wasm_api
164
173
 
165
174
  # Output files:
166
- # yo-out/wasm32-emscripten/bin/markdown_yo_demo.js
167
- # yo-out/wasm32-emscripten/bin/markdown_yo_demo.wasm
175
+ # yo-out/wasm32-emscripten/bin/markdown_yo_wasm_api.js
176
+ # yo-out/wasm32-emscripten/bin/markdown_yo_wasm_api.wasm
168
177
  ```
package/index.d.ts CHANGED
@@ -8,6 +8,38 @@ export interface RenderOptions {
8
8
  html?: boolean;
9
9
  /** Enable typographic replacements (default: false) */
10
10
  typographer?: boolean;
11
+ /** Enable ~subscript~ syntax (default: false) */
12
+ subscript?: boolean;
13
+ /** Enable ^superscript^ syntax (default: false) */
14
+ superscript?: boolean;
15
+ /** Enable ==highlight== syntax (default: false) */
16
+ mark?: boolean;
17
+ /** Enable $inline$ and $$block$$ math syntax (default: false) */
18
+ math?: boolean;
19
+ /** Enable :emoji: shortcodes (default: false) */
20
+ emoji?: boolean;
21
+ /** Enable [[wikilinks]] (default: false) */
22
+ wikilink?: boolean;
23
+ /** Enable critic markup ({++add++}, {--del--}, etc.) (default: false) */
24
+ critic?: boolean;
25
+ /** Enable abbreviations (*[abbr]: expansion) (default: false) */
26
+ abbr?: boolean;
27
+ /** Enable definition lists (Term + : Definition) (default: false) */
28
+ deflist?: boolean;
29
+ /** Enable admonition blocks (!!! type title) (default: false) */
30
+ admonition?: boolean;
31
+ /** Enable callout blocks (> [!type] title) (default: false) */
32
+ callout?: boolean;
33
+ /** Enable footnotes ([^id] refs and ^[inline]) (default: false) */
34
+ footnote?: boolean;
35
+ /** Emit data-source-line attributes on block elements (default: false) */
36
+ sourceMap?: boolean;
37
+ /** Convert newlines in paragraphs to <br> (default: false) */
38
+ breaks?: boolean;
39
+ /** Self-close tags as <br /> instead of <br> (default: false) */
40
+ xhtmlOut?: boolean;
41
+ /** Enable all optional features (default: false) */
42
+ fullFeatures?: boolean;
11
43
  }
12
44
 
13
45
  /**
@@ -44,6 +76,10 @@ export interface WasmOptions {
44
76
  * Loads the WebAssembly module and returns a renderer with a simple
45
77
  * `render(markdown, options?)` API.
46
78
  *
79
+ * @param wasmOptions - Options passed to the Emscripten module loader
80
+ * @param defaultOptions - Default rendering options applied to every render() call.
81
+ * Per-call options override defaults.
82
+ *
47
83
  * @example
48
84
  * ```ts
49
85
  * import { createRenderer } from "markdown_yo";
@@ -53,12 +89,17 @@ export interface WasmOptions {
53
89
  * console.log(html);
54
90
  * // => <h1>Hello</h1>\n<p><strong>World</strong></p>
55
91
  *
56
- * // With options
92
+ * // With per-call options
57
93
  * const html2 = md.render(src, { commonmark: true, html: true });
94
+ *
95
+ * // Set default options once
96
+ * const md2 = await createRenderer(null, { html: true, fullFeatures: true });
97
+ * md2.render("H~2~O"); // => <p>H<sub>2</sub>O</p>
58
98
  * ```
59
99
  */
60
100
  export function createRenderer(
61
- wasmOptions?: WasmOptions,
101
+ wasmOptions?: WasmOptions | null,
102
+ defaultOptions?: RenderOptions,
62
103
  ): Promise<MarkdownRenderer>;
63
104
 
64
105
  export default createRenderer;
package/index.js CHANGED
@@ -12,7 +12,7 @@
12
12
  // Re-export the Emscripten module loader
13
13
  const createMarkdownYo =
14
14
  typeof require !== "undefined"
15
- ? require("./markdown_yo_demo.js")
15
+ ? require("./markdown_yo_wasm_api.js")
16
16
  : undefined;
17
17
 
18
18
  /**
@@ -21,6 +21,22 @@ const createMarkdownYo =
21
21
  * @property {boolean} [commonmark=false] - Use CommonMark-compliant parsing
22
22
  * @property {boolean} [html=false] - Allow raw HTML tags in output
23
23
  * @property {boolean} [typographer=false] - Enable typographic replacements
24
+ * @property {boolean} [subscript=false] - Enable ~subscript~ syntax
25
+ * @property {boolean} [superscript=false] - Enable ^superscript^ syntax
26
+ * @property {boolean} [mark=false] - Enable ==highlight== syntax
27
+ * @property {boolean} [math=false] - Enable $inline$ and $$block$$ math
28
+ * @property {boolean} [emoji=false] - Enable :emoji: shortcodes
29
+ * @property {boolean} [wikilink=false] - Enable [[wikilinks]]
30
+ * @property {boolean} [critic=false] - Enable critic markup ({++add++}, {--del--}, etc.)
31
+ * @property {boolean} [abbr=false] - Enable abbreviations (*[abbr]: expansion)
32
+ * @property {boolean} [deflist=false] - Enable definition lists (Term + : Definition)
33
+ * @property {boolean} [admonition=false] - Enable admonition blocks (!!! type title)
34
+ * @property {boolean} [callout=false] - Enable callout blocks (> [!type] title)
35
+ * @property {boolean} [footnote=false] - Enable footnotes ([^id] refs and ^[inline])
36
+ * @property {boolean} [sourceMap=false] - Emit data-source-line attributes on block elements
37
+ * @property {boolean} [breaks=false] - Convert newlines in paragraphs to <br>
38
+ * @property {boolean} [xhtmlOut=false] - Self-close tags as <br /> instead of <br>
39
+ * @property {boolean} [fullFeatures=false] - Enable all optional features
24
40
  */
25
41
 
26
42
  /**
@@ -41,6 +57,21 @@ function buildFlags(options) {
41
57
  if (options.commonmark) flags |= 1;
42
58
  if (options.html) flags |= 2;
43
59
  if (options.typographer) flags |= 4;
60
+ if (options.subscript || options.fullFeatures) flags |= 8;
61
+ if (options.superscript || options.fullFeatures) flags |= 16;
62
+ if (options.mark || options.fullFeatures) flags |= 32;
63
+ if (options.math || options.fullFeatures) flags |= 64;
64
+ if (options.emoji || options.fullFeatures) flags |= 128;
65
+ if (options.wikilink || options.fullFeatures) flags |= 256;
66
+ if (options.critic || options.fullFeatures) flags |= 512;
67
+ if (options.abbr || options.fullFeatures) flags |= 1024;
68
+ if (options.deflist || options.fullFeatures) flags |= 2048;
69
+ if (options.admonition || options.fullFeatures) flags |= 4096;
70
+ if (options.callout || options.fullFeatures) flags |= 8192;
71
+ if (options.footnote || options.fullFeatures) flags |= 16384;
72
+ if (options.sourceMap) flags |= 32768;
73
+ if (options.breaks) flags |= 65536;
74
+ if (options.xhtmlOut) flags |= 131072;
44
75
  return flags;
45
76
  }
46
77
 
@@ -52,6 +83,7 @@ function buildFlags(options) {
52
83
  *
53
84
  * @param {Object} [wasmOptions] - Options passed to the Emscripten module loader
54
85
  * @param {string} [wasmOptions.locateFile] - Custom path resolver for .wasm file
86
+ * @param {RenderOptions} [defaultOptions] - Default rendering options applied to every render() call
55
87
  * @returns {Promise<MarkdownRenderer>}
56
88
  *
57
89
  * @example
@@ -63,19 +95,24 @@ function buildFlags(options) {
63
95
  * // => <p><strong>bold</strong></p>
64
96
  *
65
97
  * console.log(md.render("# Title", { commonmark: true, html: true }));
98
+ *
99
+ * // Set default options once — applied to all render() calls
100
+ * const md2 = await createRenderer(null, { html: true, fullFeatures: true });
101
+ * console.log(md2.render("H~2~O"));
102
+ * // => <p>H<sub>2</sub>O</p>
66
103
  * ```
67
104
  */
68
- async function createRenderer(wasmOptions) {
105
+ async function createRenderer(wasmOptions, defaultOptions) {
69
106
  let loader;
70
107
  if (createMarkdownYo) {
71
108
  loader = createMarkdownYo;
72
109
  } else {
73
110
  // ESM / browser dynamic import
74
- const mod = await import("./markdown_yo_demo.js");
111
+ const mod = await import("./markdown_yo_wasm_api.js");
75
112
  loader = mod.default || mod.createMarkdownYo || mod;
76
113
  }
77
114
 
78
- const Module = await loader(wasmOptions || {});
115
+ let wasmModule = await loader(wasmOptions || {});
79
116
  const encoder = new TextEncoder();
80
117
  const decoder = new TextDecoder();
81
118
 
@@ -87,25 +124,28 @@ async function createRenderer(wasmOptions) {
87
124
  * @returns {string} The rendered HTML
88
125
  */
89
126
  render(markdown, options) {
127
+ const merged = defaultOptions
128
+ ? { ...defaultOptions, ...options }
129
+ : options;
90
130
  const inputBytes = encoder.encode(markdown);
91
- const inputPtr = Module._malloc(inputBytes.length);
131
+ const inputPtr = wasmModule._malloc(inputBytes.length);
92
132
  try {
93
- Module.HEAPU8.set(inputBytes, inputPtr);
94
- const flags = buildFlags(options);
95
- const resultPtr = Module._wasm_render(
133
+ wasmModule.HEAPU8.set(inputBytes, inputPtr);
134
+ const flags = buildFlags(merged);
135
+ const resultPtr = wasmModule._wasm_render(
96
136
  inputPtr,
97
137
  inputBytes.length,
98
138
  flags,
99
139
  );
100
- const resultLen = Module._wasm_result_len();
101
- const resultBytes = Module.HEAPU8.slice(
140
+ const resultLen = wasmModule._wasm_result_len();
141
+ const resultBytes = wasmModule.HEAPU8.slice(
102
142
  resultPtr,
103
143
  resultPtr + resultLen,
104
144
  );
105
- Module._wasm_free(resultPtr);
145
+ wasmModule._wasm_free(resultPtr);
106
146
  return decoder.decode(resultBytes);
107
147
  } finally {
108
- Module._free(inputPtr);
148
+ wasmModule._free(inputPtr);
109
149
  }
110
150
  },
111
151
 
@@ -115,7 +155,7 @@ async function createRenderer(wasmOptions) {
115
155
  */
116
156
  destroy() {
117
157
  // Emscripten modules don't have a standard destroy, but we clear the ref
118
- Module = null;
158
+ wasmModule = null;
119
159
  },
120
160
  };
121
161
  }
@@ -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=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&process.versions?.node&&process.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};if(typeof __filename!="undefined"){_scriptName=__filename}else{}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else 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 isFileURI=filename=>filename.startsWith("file://");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_wasm_api.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&&!ENVIRONMENT_IS_NODE){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 CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "markdown_yo",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A high-performance Markdown-to-HTML converter compiled to WebAssembly",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "files": [
8
8
  "index.js",
9
9
  "index.d.ts",
10
- "markdown_yo_demo.js",
11
- "markdown_yo_demo.wasm",
10
+ "markdown_yo_wasm_api.js",
11
+ "markdown_yo_wasm_api.wasm",
12
12
  "README.md"
13
13
  ],
14
14
  "keywords": [
@@ -1,2 +0,0 @@
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