Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createMDAST(value, forceArray = false) {
const result = removePosition(remarkInstance.parse(value), true);
if (result.children.length === 1 && !forceArray) {
return result.children[0];
}
return result.children;
},
exists() {
const start: Location = {
line: 1,
column: 1,
offset: 0,
}
const node: Node = {
type: 'root',
children,
position: {
start,
end: parser.eof || Object.assign({}, start),
},
}
if (!parser.options.position) {
removePosition(node)
}
return node
})
},
export default function parser(dir = process.cwd()) {
let _mtree;
const pathname = path.resolve(dir, 'CHANGELOG.md');
const contents = read(pathname);
return {
remark: remarkInstance,
gitCompare: null,
SEPARATORS,
root: removePosition(remarkInstance.parse(contents), true),
createMDAST(value, forceArray = false) {
const result = removePosition(remarkInstance.parse(value), true);
if (result.children.length === 1 && !forceArray) {
return result.children[0];
}
return result.children;
},
exists() {
return contents !== null;
},
write(content = this.stringify()) {
return write(pathname, content);
},
stringify(root = this.root) {
return remarkInstance.stringify(root, {
listItemIndent: '1'
export function parseMarkdown(str: string): mdast.Root {
const ast = removePosition(parsePipeline.parse(str))
assertMdAST(ast)
return ast
}
const parse = ({ position, raw, ...options }) => (value) => {
const { content } = value
const instance = parser(options)
const parsed = instance.runSync(instance.parse(content))
return {
...value,
content: position ? parsed : removePosition(parsed, true),
raw: raw ? content : undefined
}
}