MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / addText

Function addText

tools/challenge-parser/parser/plugins/add-text.js:7–34  ·  view source on GitHub ↗
(sectionIds)

Source from the content-addressed store, hash-verified

5const { createMdastToHtml } = require('./utils/i18n-stringify');
6
7function addText(sectionIds) {
8 if (!sectionIds || !Array.isArray(sectionIds) || sectionIds.length <= 0) {
9 throw new Error('addText must have an array of section ids supplied');
10 }
11 function transformer(tree, file) {
12 for (const sectionId of sectionIds) {
13 const textNodes = getSection(tree, `--${sectionId}--`, 1);
14 const subSection = find(root(textNodes), isMarker);
15 if (subSection) {
16 throw Error(
17 `The --${sectionId}-- section should not have any subsections. Found subsection ${subSection.children[0].value}`
18 );
19 }
20
21 const toHtml = createMdastToHtml(file.data.lang);
22 const sectionText = toHtml(textNodes);
23 if (!isEmpty(sectionText)) {
24 file.data = {
25 ...file.data,
26 [sectionId]: `<section id="${sectionId}">
27${sectionText}
28</section>`
29 };
30 }
31 }
32 }
33 return transformer;
34}
35
36module.exports = addText;

Callers 1

add-text.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected