tools,doc: fix misrendering of consecutive JS blocks

Our markdown-to-html tool was assuming that any consecutive JS blocks
were ESM vs CJS alternatives, but that is not always the case, resulting
in both a confusing interface and invalid HTML.

PR-URL: https://github.com/nodejs/node/pull/40146
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Rich Trott 2021-09-18 12:03:19 -07:00 committed by Node.js GitHub Bot
parent 0bafe6dd21
commit b0d5eecdd9

View File

@ -227,7 +227,8 @@ export function preprocessElements({ filename }) {
nextNode.lang !== node.lang) {
// Saving the highlight code as value to be added in the next node.
node.value = highlighted;
} else if (isJSFlavorSnippet(previousNode)) {
} else if (isJSFlavorSnippet(previousNode) &&
previousNode.lang !== node.lang) {
node.value = '<pre>' +
'<input class="js-flavor-selector" type="checkbox"' +
// If CJS comes in second, ESM should display by default.