File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- Copyright (c) 2022 Tim Branyen (@tbranyen)
1+ Copyright (c) 2023 Tim Branyen (@tbranyen)
22
33Permission is hereby granted, free of charge, to any person obtaining a copy of
44this software and associated documentation files (the "Software"), to deal in
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ Internals.parse = parse;
2929
3030// Now the html`` tagged template will be parsed using WASM
3131innerHTML (document .body , html `
32- <div >Parsed with TL using WASM</div >
32+ <div >Parsed with TL using WASM</div >
3333` );
3434
3535// Simple HTML strings are also automatically parsed using WASM now
@@ -44,9 +44,9 @@ your build step. This is done with the `NODE_OPTIONS` env var and the
4444
4545``` json
4646{
47- "scripts" : {
48- "build" : " NODE_OPTIONS=--experimental-wasm-modules babel input.js -o output.js"
49- }
47+ "scripts" : {
48+ "build" : " NODE_OPTIONS=--experimental-wasm-modules babel input.js -o output.js"
49+ }
5050}
5151```
5252
@@ -75,4 +75,3 @@ example of how you could integrate the WASM parser in both development and
7575production is available.
7676
7777- [ Sample webpack example] ( ./examples/webpack )
78-
Original file line number Diff line number Diff line change 2323 "Parser" : [" parser.html" , {
2424 "Options" : " #options" ,
2525 "Override parser" : " #override-parser" ,
26- "Dynamic values " : " #dynamic-values " ,
27- "Rust WASM " : " #rust-wasm "
26+ "Rust WASM " : " #rust-wasm " ,
27+ "Dynamic values " : " #dynamic-values "
2828 }],
2929
3030 "Middleware" : [" middleware.html" , {
Original file line number Diff line number Diff line change @@ -174,6 +174,38 @@ Internals.parse = input => {
174174};
175175```
176176
177+ <a name =" rust-wasm " ></a >
178+
179+ ---
180+
181+ ## <a href =" #rust-wasm " >Rust WASM</a >
182+
183+ An alternative parser is readily available that is authored in Rust and
184+ compiled to [ WASM] ( https://webassembly.org/ ) . You can install this with:
185+
186+ ``` bash
187+ npm install diffhtml-rust-parser --save
188+ ```
189+
190+ To use, simply import and attach to the ` Internals.parse ` as described in the
191+ section above. For example:
192+
193+ ```
194+ import { Internals, innerHTML, html } from 'diffhtml';
195+ import { parse } from 'diffhtml-rust-parser';
196+
197+ // Use the rust parser
198+ Internals.parse = parse;
199+
200+ // Now the html`` tagged template will be parsed using WASM
201+ innerHTML(document.body, html`
202+ <div>Parsed with TL using WASM</div>
203+ `);
204+
205+ // Simple HTML strings are also automatically parsed using WASM now
206+ innerHTML(document.body, '<div>Also parsed with WASM</div>');
207+ ```
208+
177209<a name =" dynamic-values " ></a >
178210
179211---
You can’t perform that action at this time.
0 commit comments