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:
-
✅ Doesn't require JavaScript on the client. -
✅ Doesn't break the accessibility of the docs. -
✅ Doesn't break GitHub auto-highlighting (well it breaks in the code diff, but it renders OK in the markdown preview, see https://github.com/aduh95/node/blob/doc-multi-syntax-snippets/doc/api/wasi.md). -
❓ Use non-free content (the toggle used in this PR is derived from https://fontawesome.com/icons/toggle-on?style=solid, which is under CC BY 4.0 License).
Originally suggested by @jasnell in https://github.com/nodejs/node/pull/37077#discussion_r565397566.