Rendering
Lawtext provides the functionality of rendering a StdEL
tree into several formats, such as Lawtext, Standard Law XML (opens in a new tab), HTML, and docx.
Rendering into Lawtext
The rendering process into Lawtext is basically the reverse transformation of parsing. However, the Lawtext renderer skips the creation of VirtualLine
s and directly transforms the StdEL
tree into Line
s.
You can find the entry point of the Lawtext renderer at renderLawtext()
.
Rendering into Standard Law XML
The rendering process into Standard Law XML is just serializing the StdEL
tree and adding an XML declaration on top of that.
You can find the entry point of the Standard Law XML renderer at renderXML()
.
Rendering into HTML
The rendering process into HTML utilizes React DOM Server API (opens in a new tab). The HTML renderer first constructs a tree of React components from the StdEL
tree and then converts the component into HTML string using renderToStaticMarkup()
(opens in a new tab).
The same React component such as HTMLLaw
, can be utilized to create React web apps that render StdEL
.
renderHTMLfragment()
renders the HTML fragment directly from renderToStaticMarkup()
, and renderHTML()
adds some other parts such as an HTML declaration and styles to make a stand-alone HTML file.
Rendering into docx
Like the HTML renderer, the rendering process into docx utilizes React DOM Server API (opens in a new tab) but builds a WordprocessingML of Office Open XML (opens in a new tab).
renderDocxAsync()
builds a docx binary as Office Open XML.
How to try
Try it out here
- On this page, open the browser console (for Chrome, press
Ctrl+Shift+J
(Windows/Linux) orCmd+Opt+J
(Mac)).. - Run the following command in the browser console:
ret = await lawtext.run({ input: { elaws: "405AC0000000088" }, outtypes: ["lawtext", "xml", "html", "htmlfragment", "docx"], }) .then(r => { console.log("\u{2705} Rendered Lawtext:"); console.log(r.lawtext); console.log("\u{2705} Rendered XML:"); console.log(r.xml); console.log("\u{2705} Rendered HTML:"); console.log(r.html); console.log("\u{2705} Rendered HTML fragment:"); console.log(r.htmlfragment); const saveDocx = () => { const base64 = btoa(r.docx.reduce((s, b) => s + String.fromCharCode(b), "")); const mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; const url = `data:${mime};base64,${base64}`; const a = document.createElement("a"); document.body.appendChild(a); a.download = "405AC0000000088.docx"; a.href = url; a.click(); a.remove(); }; console.log("\u{2705} Rendered Docx:"); console.log("run ret.saveDocx() to save the docx file."); return { saveDocx }; });
Hint: run console.log(lawtext.run.help)
to show the help.
Try using the CLI
Please see CLI usage and run CLI with output options like lawtext
, xml
, html
, docx
, etc., to get the rendered results.