Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(wat, () => {
const { proc } = procMd(md);
// Discard position info
const nodes = flattenTree(proc,
(node, recurse) => concat([node], recurse(node.children || [])));
each(nodes, (node) => {
delete node.position;
});
assert.deepStrictEqual(proc.children, yaml.safeLoad(ast));
});
};
function selecttest(context, { request }) {
const cont = setdefault(context, 'content', { mdast: {} });
const params = request.params || {};
const { strain } = params;
const sections = cont.mdast.children;
if (!strain || !sections) {
return;
}
const selected = pick(testgroups(sections), strain);
each(sections, (section) => {
if (!section.meta || !section.meta.test) {
return;
}
section.meta.hidden = !(section === selected[section.meta.test]);
});
}
function selectstrain(context, { request, logger }) {
const cont = setdefault(context, 'content', { mdast: {} });
const params = request.params || {};
const { strain } = params;
const sections = cont.mdast.children;
if (!strain || !sections) {
return;
}
logger.debug(`Filtering sections not intended for strain ${strain}`);
each(sections, (section) => {
const meta = setdefault(section, 'meta', {});
const strainList = type(meta.strain) === Array ? meta.strain : [meta.strain];
meta.hidden = Boolean(meta.strain && meta.strain !== [] && !strainList.includes(strain));
});
}
each([yaml, title, intro, image, sectiontype, fallback], (fn) => {
each(sections, fn);
});
function getmetadata({ content }, { logger }) {
const { mdast: { children = [] } } = content;
let sections = children.filter((node) => node.type === 'section');
if (!sections.length) {
sections = [content.mdast];
}
logger.debug(`Parsing Markdown Metadata from ${sections.length} sections`);
each([yaml, title, intro, image, sectiontype, fallback], (fn) => {
each(sections, fn);
});
const img = sections.filter((section) => section.image)[0];
const titl = sections.filter((section) => section.title)[0];
content.meta = sections[0].meta;
content.title = titl ? titl.title : '';
content.intro = sections[0].intro;
content.image = img ? img.image : undefined;
}