Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
};
const cnt = block.end - block.start + 1;
mdast.children.splice(block.start + off, cnt, dat);
off += -cnt + 1; // cnt removed, 1 inserted
} else {
const { warning, source, start } = block;
const fst = mdast.children[start + off];
// This also needs to account for settext headings
// hence the usage of end here, instead of using start
const { line } = fst.position.end;
// Source file pretty printing with line numbers
const sourceref = pipe(
source.split('\n'),
zipLeast2(range(line, Infinity)),
map(([l, no]) => ` ${no} | ${l} `),
join('\n'),
);
const err = new FrontmatterParsingError(`${warning}\n${sourceref}`);
if (!production()) {
logger.warn(err);
}
logger.debug(err);
}
}
};
return (schemas) => {
if (readme) {
console.log('building readme');
const toplevel = flist(pipe(
schemas,
filter(schema => !schema[s.parent]), // remove schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
text(' – '),
inlineCode(schema[keyword`$id`] || '-'),
]))),
), Array);
const bytype = type => flist(pipe(
schemas,
filter(schema => schema[keyword`type`] === type), // remove schemas without matching type
filter(schema => !!schema[s.parent]), // keep only schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
const bytype = type => flist(pipe(
schemas,
filter(schema => schema[keyword`type`] === type), // remove schemas without matching type
filter(schema => !!schema[s.parent]), // keep only schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
text(' – '),
inlineCode(`${schema[s.id]}#${schema[s.pointer]}`),
]))),
), Array);
return warn(null,
'Found ambigous frontmatter block: Block contains valid yaml, but '
+ `it's data type is ${type(data)} instead of Object.`
+ 'Make sure your yaml blocks contain only key-value pairs at the root level!');
}
return {
type: 'frontmatter',
payload: data,
start: fst.idx,
end: last.idx,
};
});
// Preprocessing
return pipe(
enumerate(mdast.children),
// Find any potential frontmatter starts/ends in the mdast
/* eslint-disable-next-line no-unused-vars */
filter(([idx, nod]) => isPotential(nod)),
// Filter out dom nodes based on their actual text content;
// this filters out HRs made from other characters or setext
// headings with more than three dashes...
//
// And: Perform some more sophisticated feature extraction on the nodes
map(([idx, nod]) => {
const mat = nodeStr(idx).match(re(`(?<=^|\\n)---${hspace}*\\n?$`));
if (!mat) {
return null;
}
// Offset of the actual separator line (this may deviate from the)
const offStart = mat.index + start(idx);