chore: import upstream snapshot with attribution
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 11:55:53 +08:00
commit dde272c4b8
19405 changed files with 2730632 additions and 0 deletions
@@ -0,0 +1,73 @@
const { root } = require('mdast-builder');
const find = require('unist-util-find');
const { isEmpty } = require('lodash');
const { getFilenames } = require('./utils/get-file-visitor');
const { getSection, isMarker } = require('./utils/get-section');
const mdastToHTML = require('./utils/mdast-to-html');
function plugin() {
return transformer;
function transformer(tree, file) {
const interactiveNodes = getSection(tree, `--interactive--`, 1);
const subSection = find(root(interactiveNodes), isMarker);
if (subSection) {
throw Error(
`The --interactive-- section should not have any subsections. Found subsection ${subSection.children[0].value}`
);
}
if (!isEmpty(interactiveNodes)) {
const nodules =
interactiveNodes.map(node => {
if (
node.type === 'containerDirective' &&
node.name === 'interactive_editor'
) {
return {
type: 'interactiveEditor',
files: getFiles(node.children)
};
} else {
const paragraph = mdastToHTML([node]);
return {
type: 'paragraph',
contents: paragraph
};
}
}) ?? [];
file.data.nodules = nodules;
}
}
}
function getFiles(filesNodes) {
const invalidNode = filesNodes.find(node => node.type !== 'code');
if (invalidNode) {
throw Error('The :::interactive_editor should only contain code blocks.');
}
// TODO: refactor into two steps, 1) count languages, 2) map to files
const counts = {};
return filesNodes.map(node => {
counts[node.lang] = counts[node.lang] ? counts[node.lang] + 1 : 1;
const contentsHtml = mdastToHTML([node]);
const out = {
contents: node.value,
ext: node.lang,
name:
getFilenames(node.lang) +
(counts[node.lang] ? `-${counts[node.lang]}` : ''),
contentsHtml
};
return out;
});
}
module.exports = plugin;