The Live Script Renderer converts MATLAB® plain text live scripts (.m) to HTML. It parses the markup in the plain text live code file and generates HTML and CSS that you can use as a complete, self-contained document or embed in another page.
The renderer runs independently of MATLAB. MATLAB does not need to be installed.
The renderer supports:
- Formatted text
- LaTeX equations
- Syntax-highlighted MATLAB code
- Code output, including text, matrices, tables, images, errors, and warnings
- Live controls, including sliders, checkboxes, drop-down lists, buttons, and text inputs
- Tables of contents
- Embedded images and videos
- Section breaks
- Light and dark themes
The renderer is not available on npm. To use it, clone this repository and build the renderer:
npm install
npm run build
The build produces dist/index.js, a single bundle with no runtime dependencies.
Require the bundle by path:
const fs = require('fs')
const { render } = require('<path-to-live-script-renderer>/dist/index.js')
const html = await render(
fs.readFileSync('script.m', 'utf8'),
'light'
)To use the Live Script Renderer from another repository, add this repository as a Git submodule and build the renderer as part of that project's build process.
render(text, theme): Promise<string>
Renders a plain text live script (.m) as a complete, self-contained HTML document.
| Parameter | Type | Description |
|---|---|---|
text |
string |
Full text of live script |
theme |
'light' | 'dark' |
Color theme for the rendered content |
Returns a Promise<string> containing the complete HTML document with all required styles embedded.
renderBody(text, theme): Promise<{ bodyHtml, styles }>
Renders a plain text live script (.m) without creating the surrounding HTML document. Use this function when the application creates its own page, for example, to add scripts or define a Content Security Policy.
renderBody takes the same parameters as render.
It returns a Promise containing an object with these properties:
| Property | Type | Description |
|---|---|---|
bodyHtml |
string |
Rendered content, to place inside <body> |
styles |
string |
CSS for the content, to place inside a <style> element |
- Node.js 16 or later
- npm
npm install
npm run build
Run the visual smoke test to render a fixture file to HTML:
node test/render-test.js
node test/render-test.js dark
node test/render-test.js path/to/script.m
node test/render-test.js path/to/script.m dark
This table shows the input and theme for each command.
| Command | Input | Theme |
|---|---|---|
node test/render-test.js |
Default fixture | Light |
node test/render-test.js dark |
Default fixture | Dark |
node test/render-test.js path/to/script.m |
Specified file | Light |
node test/render-test.js path/to/script.m dark |
Specified file | Dark |
To verify the output, open the generated HTML file in a browser.