/
vasya2
/
var
Обзор
Документация
Войти
/
vasya2
/
var
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tools/challenge-parser/parser/plugins/add-text.js
36 строк
1 KB
Anna
feat: test page structure (#59113)
01 апр 2025, 23:32
Не верифицирован
01 апр 2025, 23:32
3104c9e
Код
Авторство
О чём код?
const { isEmpty } = require('lodash'); const find = require('unist-util-find'); const { root } = require('mdast-builder'); const { getSection, isMarker } = require('./utils/get-section'); const mdastToHTML = require('./utils/mdast-to-html'); function addText(sectionIds) { if (!sectionIds || !Array.isArray(sectionIds) || sectionIds.length <= 0) { throw new Error('addText must have an array of section ids supplied'); } function transformer(tree, file) { for (const sectionId of sectionIds) { const textNodes = getSection(tree, `--${sectionId}--`); const subSection = find(root(textNodes), isMarker); if (subSection) { throw Error( `The --${sectionId}-- section should not have any subsections. Found subsection ${subSection.children[0].value}` ); } const sectionText = mdastToHTML(textNodes); if (!isEmpty(sectionText)) { file.data = { ...file.data, [sectionId]: `<section id="${sectionId}"> ${sectionText} </section>` }; } } } return transformer; } module.exports = addText;