mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-31 15:03:21 -05:00
* feat: integrate the odin project * feat: add assignment to markdown parser * feat: add assignment logic * fix: doe not always show assignment block * fix: some other stuff * fix: introdiction to html and css questions * fix: remove assignments after first question * fix: update snapshots and tests * feat: create rest of HTML foundation course structure * feat: meta file * feat: add descriptions to 'html boiler plate' questions * feat: add description for 'working with text and list items' * fix: multiple logic issues * fix: make linter happy * feat: add description for 'links and images' questions * fix: add assignments to Joi schema * fix: tests * fix: schema * fix: add help category * fix: change to possessive wording * fix: set upcoming change to true in meta file * fix: spell unordered and ordered correctly * fix: switch order in meta * fix: spell boilerplate correctly * feat: add final project * chore: add more tests to the final project * fix: question spelling * Apply suggestions from code review Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * Apply suggestions from code review Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * Apply suggestions from code review Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * Apply suggestions from code review Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * Apply suggestions from code review Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * Apply suggestions from code review Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * fix: translation * Update client/i18n/locales/english/translations.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: create new challenge type * fix: get the new challenge type working and remove ol css * fix: translation location * fix: add challenge type to epic * fix: set correct video * fix: max challengeType number * fix: spelling/grammar errors in project * fix: check if anchor tags is empty * Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update tools/challenge-parser/parser/plugins/add-video-question.js Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: multiple suggestions * chore: separate assignments into different plugin * Apply suggestions from code review Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com> * fix: dubble answer header after review * fix: issue with Gatsby hopefully * fix: add assignments to Gatsby's Challenge schema * Update curriculum/schema/challengeSchema.js Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>
63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
const { root } = require('mdast-builder');
|
|
const getAllBetween = require('./utils/between-headings');
|
|
const mdastToHtml = require('./utils/mdast-to-html');
|
|
|
|
const { splitOnThematicBreak } = require('./utils/split-on-thematic-break');
|
|
|
|
function plugin() {
|
|
return transformer;
|
|
function transformer(tree, file) {
|
|
const questionNodes = getAllBetween(tree, '--question--');
|
|
if (questionNodes.length > 0) {
|
|
const questionTree = root(questionNodes);
|
|
|
|
const textNodes = getAllBetween(questionTree, '--text--');
|
|
const answersNodes = getAllBetween(questionTree, '--answers--');
|
|
const solutionNodes = getAllBetween(questionTree, '--video-solution--');
|
|
|
|
const question = getQuestion(textNodes, answersNodes, solutionNodes);
|
|
|
|
file.data.question = question;
|
|
}
|
|
}
|
|
}
|
|
|
|
function getQuestion(textNodes, answersNodes, solutionNodes) {
|
|
const text = mdastToHtml(textNodes);
|
|
const answers = getAnswers(answersNodes);
|
|
const solution = getSolution(solutionNodes);
|
|
|
|
if (!text) throw Error('text is missing from question');
|
|
if (!answers) throw Error('answers are missing from question');
|
|
if (!solution) throw Error('solution is missing from question');
|
|
|
|
return { text, answers, solution };
|
|
}
|
|
|
|
function getAnswers(answersNodes) {
|
|
const answerGroups = splitOnThematicBreak(answersNodes);
|
|
return answerGroups.map(answer => mdastToHtml(answer));
|
|
}
|
|
|
|
function getSolution(solutionNodes) {
|
|
let solution;
|
|
try {
|
|
if (solutionNodes.length > 1) throw Error('Too many nodes');
|
|
if (solutionNodes[0].children.length > 1)
|
|
throw Error('Too many child nodes');
|
|
const solutionString = solutionNodes[0].children[0].value;
|
|
if (solutionString === '') throw Error('Non-empty string required');
|
|
|
|
solution = Number(solutionString);
|
|
if (Number.isNaN(solution)) throw Error('Not a number');
|
|
if (solution < 1) throw Error('Not positive number');
|
|
} catch (e) {
|
|
console.log(e);
|
|
throw Error('A video solution should be a positive integer');
|
|
}
|
|
|
|
return solution;
|
|
}
|
|
|
|
module.exports = plugin;
|