Skip to content

tools,doc: add support for several flavors of JS code snippets

Enable code example using both modern ESM syntax and legacy CJS syntax. It adds a toggle on the web interface to let users switch from one JavaScript flavor to the other.

html.js detects code snippets with a meta attribute:

```mjs
export default {};
```
```cjs
'use strict';
module.exports = {};
```

And adds a <input type=checkbox> toggle:

Toggle ESM Toggle CJS

With dark mode on

Toggle ESM, with dark mode Toggle CJS, with dark-mode

Originally suggested by @jasnell in https://github.com/nodejs/node/pull/37077#discussion_r565397566.

Merge request reports

Loading