Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function makeheader(schema) {
// console.log('making header for', schema[s.filename], schema[s.pointer]);
if (header) {
return [
heading(1, text(i18n`${gentitle(schema[s.titles], schema[keyword`type`])} Schema`)),
paragraph(code('txt', schema[s.id] + (schema[s.pointer] ? `#${schema[s.pointer]}` : ''))),
schema[s.meta].longdescription,
...makecomment(schema),
table('left', [
// iterate over header
tableRow(
flist(
map(headerprops,
({ name, title }) => {
if (links[name]) {
return tableCell(link(links[name], i18n`What does ${title} mean?`, text(title)));
}
return tableCell(text(title));
}), Array,
),
),
tableRow(
flist(
map(headerprops,
(prop) => {
// this is a linked property
if (schema[s.meta]
&& typeof schema[s.meta][prop.name] === 'object'
&& schema[s.meta][prop.name].link
const end = (idx) => mdast.children[idx].position.end.offset;
const nodeStr = (idx) => str.slice(start(idx), end(idx));
// Identifying MDAST nodes which are potential fences (but later
// still need to be checked more thoroughly)
const isHead2 = (n) => n.type === 'heading' && n.depth === 2;
const isHr = (n) => n.type === 'thematicBreak';
const isPotential = (n) => isHead2(n) || isHr(n);
// Classifiers for fences: Lets us distinguish actual fences
// from headers and horizontal rules which should not be altered:
const decentHead = (n) => n.after && isHead2(n.nod);
const decentHr = (n) => n.after && n.before;
const toIgnore = (n) => !n || decentHead(n) || decentHr(n);
const procwarnigns = map(([fst, last]) => {
const src = str.slice(fst.offStart, last === null ? undefined : last.offEnd);
const warn = (cause, prosa) => ({
type: 'warning',
warning: prosa,
source: src,
fst,
last,
start: fst.idx,
end: last && last.idx,
cause,
});
if (!fst.before) {
return warn(null,
'Found ambigous frontmatter fence: No empty line before the block! '
// Decide which blocks to ignore, which deserve warnings and which
// are actual frontmatter
procwarnigns,
filter(identity),
// Filter out false positive warnings for pseudo frontmatter blocks
// before actual frontmatter (warning gets invalidated by the fact
// that it DIRECTLY PRECEDES an actual frontmatter block)
lookahead(1, null),
reject(([val, next]) => true
&& val.type === 'warning'
&& val.warning.startsWith('Found ambigous frontmatter')
&& next
&& next.type === 'frontmatter'
&& val.end === next.start),
/* eslint-disable-next-line no-unused-vars */
map(([val, next]) => val),
);
};
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);
const offEnd = offStart + size(mat[0]);
// Is there a new line or EOF before/after the separator?
const before = Boolean(str.slice(0, offStart).match(re(`(^|(^|\\n)${hspace}*\\n)$`)));
const after = Boolean(str.slice(offEnd).match(re(`^(${hspace}*(\\n${hspace}*(\\n|$))|$)`)));
return {
idx, nod, offStart, offEnd, before, after,
};
}),
filter(identity),
// Pair up two fences each; we even do this if there is only a single
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 schemas => map(schemas, (schema) => {
try {
validator.addSchema(schema, schema[filename]);
return schema;
} catch (e) {
logger.error('Ajv processing error for schema at path', schema.path);
logger.error(e);
process.exit(1);
}
});
}