Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function compile(source: string, options: Options = {}) {
// Find all code blocks in markdown
let node = Remark.parse(source);
let testCaseList = [];
mdastVisitNode(node, 'code', (node, index, parent) => {
let prev = parent.children[index - 1];
let title = null;
if (prev && prev.type === 'paragraph') {
title = mdastToString(prev);
}
if (title && title[title.length - 1] === ':') {
title = title.slice(0, title.length - 1);
}
if (SUPPORTED_LANG[node.lang]) {
testCaseList.push({
title: title,
lang: node.lang,
value: node.value
});
title: () => {
// attempt to generate a title by finding the first h1 in markdown content
// if none title should be fileName
const ast = remark.parse(data.content);
// make title file name by default
let title = file.metadata.fileName;
// visit heading
visit(ast, 'heading', node => {
// is node on first line and a h1 or h2?
if (title === file.metadata.fileName && (node.depth === 1 || node.depth === 2)) {
// accept headers up to 3rd line of markdown file
if (node.position.start.line < 3) {
title = node.children[0].value;
}
}
});
return title;
},
ignore: () => false, // should this markdown siphon node be ignored
node,
name: 'resourceType',
value: RESOURCE_TYPES.EVENTS,
});
createNodeField({
node,
name: 'standAlonePath',
value: node.link,
});
}
if (isMarkdownRemark(node)) {
const parentNode = getNode(node.parent);
let title = node.frontmatter.title;
const ast = remark.parse(node.internal.content);
//if our title is blank, visit will search through the content for a usable and reasonable title
visit(ast, 'heading', node => {
// is title blank and is node on first line and a h1 or h2?
if (title === '' && (node.depth === 1 || node.depth === 2)) {
// accept headers up to 3rd line of markdown file
if (node.position.start.line < 3) {
title = node.children[0].value;
}
}
});
let labels = {};
// assert the shape of labels in frontmatter
if (Object.prototype.hasOwnProperty.call(node.frontmatter, 'labels')) {
if (isPlainObject(node.frontmatter.labels)) {
labels = node.frontmatter.labels;
test('main', function (t) {
var comments = [
{
path: [],
context: {},
description: remark.parse('test'),
members: {
static: [],
instance: []
},
returns: [{
type: {
type: 'NameExpression',
name: 'Foo'
}
}]
}
];
theme(comments, {}, function (err) {
t.ifError(err);
t.done();
test('main', function (t) {
t.deepEqual(formatMarkdown(remark.parse('Converts from `Result` to `?Error`')),
'<p>Converts from <code>Result<T></code> to <code>?Error</code></p>\n');
t.done();
});
module.exports = mdx => {
const imports = select(parse(mdx), IMPORT_SELECTOR)
.map(i => {
const squeezed = i.value.replace(/\s+/g, ' ').split(' import').join('\nimport')
const parsed = parseImports(squeezed)
return {
raw: i.value,
parsed
}
})
const scope = importScope(imports)
return {
imports,
scope,
blocks: blocks.concat(scope)
documentationFormatter(comments, {}, function (err, output) {
if (err) {
throw new Error(err)
}
var inputMarkdownContent = remark.parse(fs.readFileSync('src/api/docs.md', 'utf-8'))
var newStuff = remark.parse(output)
inject('Uppy Core & Plugins', inputMarkdownContent, newStuff)
fs.writeFileSync('src/api/docs.md', remark.stringify(inputMarkdownContent))
console.info(chalk.green('✓ documentation generated'))
})
})
documentationFormatter(comments, {}, function (err, output) {
if (err) {
throw new Error(err)
}
var inputMarkdownContent = remark.parse(fs.readFileSync('src/api/docs.md', 'utf-8'))
var newStuff = remark.parse(output)
inject('Uppy Core & Plugins', inputMarkdownContent, newStuff)
fs.writeFileSync('src/api/docs.md', remark.stringify(inputMarkdownContent))
console.info(chalk.green('✓ documentation generated'))
})
})
return
}
const transcludedFile = path.join(file.cwd, node.value)
let content = null
try {
content = fs.readFileSync(transcludedFile, 'utf8')
} catch (e) {
console.log(`Error transcluding ${transcludedFile}`)
}
if (content) {
tree.children = [].concat(
tree.children.slice(0, index),
parse(content).children,
tree.children.slice(index + 1)
)
}
})
createFromMarkdown (text) {
const ast = remark.parse(text)
const tasks = []
ast.children.forEach(node => {
if (node.type === HEADING) {
tasks.unshift([node])
} else if (tasks.length > 0) {
tasks[0].push(node)
}
})
return new TaskCollection(
tasks.reverse().map(obj => this.createOneFromNodes(obj))
)
}