Files
freeCodeCamp/tools/challenge-parser/parser/index.js
Sem Bauke df53c7778c feat: integrate The Odin Project (#48617)
* 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>
2023-01-19 14:55:26 +02:00

79 lines
2.8 KiB
JavaScript

const directive = require('remark-directive');
const frontmatter = require('remark-frontmatter');
const remark = require('remark-parse');
const { readSync } = require('to-vfile');
const unified = require('unified');
const addFrontmatter = require('./plugins/add-frontmatter');
const addSeed = require('./plugins/add-seed');
const addSolution = require('./plugins/add-solution');
const addTests = require('./plugins/add-tests');
const addText = require('./plugins/add-text');
const addVideoQuestion = require('./plugins/add-video-question');
const addAssignment = require('./plugins/add-assignment');
const replaceImports = require('./plugins/replace-imports');
const restoreDirectives = require('./plugins/restore-directives');
const tableAndStrikeThrough = require('./plugins/table-and-strikethrough');
// by convention, anything that adds to file.data has the name add<name>.
const processor = unified()
// add the remark parser
.use(remark)
// modify the parser so that Github flavour tables and strikethroughs get
// converted to 'delete' nodes
.use(tableAndStrikeThrough)
// directives are parsed into 'leafDirective' nodes and used for imports
.use(directive)
// convert the text at the top of the document (surrounded by ---) into a
// 'yaml' node
.use(frontmatter, ['yaml'])
// extract the content from that 'yaml' node
.use(addFrontmatter)
// Any imports will be replaced (in the tree) with
// the sub-tree of the target file. e.g.
// ::import{component="Script" from="./file.path" }
// means that file.path's tree will be inserted wherever
// ::use{component="Script"}
// appears.
.use(replaceImports)
// the final five 'add' plugins insert content into file.data
// TODO: rename test->hint everywhere? It should make things easier to reason
// about.
.use(addSeed)
.use(addSolution)
// the directives will have been parsed and used by this point, any remaining
// 'directives' will be from text like the css selector :root. These should be
// converted back to text before they're added to the challenge object.
.use(restoreDirectives)
.use(addVideoQuestion)
.use(addAssignment)
.use(addTests)
.use(addText, ['description', 'instructions', 'notes']);
exports.parseMD = function parseMD(filename) {
return new Promise((resolve, reject) => {
const file = readSync(filename);
const tree = processor.parse(file);
processor.run(tree, file, function (err, node, file) {
if (!err) {
resolve(file.data);
} else {
err.message += ' in file ' + filename;
reject(err);
}
});
});
};
exports.parseMDSync = function parseMDSync(filename) {
const file = readSync(filename);
const tree = processor.parse(file);
try {
processor.runSync(tree, file);
} catch (err) {
err.message += ' in file ' + filename;
throw err;
}
return file.data;
};