Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.split('\n')
.map(line => {
if (/^\/.+\.md$/.test(line)) {
const f = path.join(path.dirname(filepath), line);
const result = md(f, { root });
dependencies.push(...result.dependencies, f);
return result.data;
}
return line;
})
.join('\n');
// Load YAML frontmatter
const { body: data, attributes: meta } = frontmatter(text);
const title = meta.title || getNameFromPath(filepath);
return {
filepath: path.relative(root, filepath),
title,
description: meta.description || '',
link: meta.link || dashify(title),
data,
type: 'md',
dependencies,
};
}
_.map((post: BlogPostType & {path: string, requirePath: string}) => {
// read the markdown file
const content = String(
fs.readFileSync(path.join(__dirname, `/pages/${post.requirePath}`))
);
// extract yaml meta tags
const meta = frontMatter(content);
// render markdown to html
const html = md.render(meta.body);
// replace relative links with absolute ones
const $ = parseHtml(html, {
recognizeSelfClosing: true,
decodeEntities: false,
});
$('img').each((idx: number, elem: Object) => {
const src = _.last(
$(elem)
.attr('src')
.split('./')
);
$(elem).attr('src', `${hostname}${post.path}${src}`);
});
const renderHTML = tab => {
const render = tab => md.render(tab.content).replace(/src="([^"]+)"/g, (m, p1) => {
if (p1[0] === '.') {
p1 = path.join(path.dirname(tab.filePath), p1)
return `src="${p1}"`
}
return m
})
const data = fm(tab.content)
if (tab.isPresentationMode) {
return {
attrs: data.attributes,
html: data.body.split('\n\n---\n\n')
.map(content => render({
content,
filePath: tab.filePath
}))
}
}
return {
attrs: data.attributes,
html: xss(render({content: data.body, filePath: tab.filePath}))
}
}
transform (md, id) {
if (!/\.md$/.test(id)) return null
if (!filter(id)) return null
const data = fm(md)
data.body = snarkdown(data.body)
return {
code: `export default ${JSON.stringify(data)};`,
map: { mappings: '' }
}
}
}
static async getInitialProps({ query: { id }}) {
const request = new Request(
'https://raw.githubusercontent.com/Popmotion/popmotion/master/docs/api/calc.md',
{
headers: new Headers({
'Content-Type': 'text/plain'
})
}
);
const response = await fetch(request);
const doc = await response.text();
const { attributes, body } = frontMatter(doc);
const { title, description } = attributes;
return {
title,
description,
body
};
}
function parseJade(jadeContent) {
const fmContent = fm(jadeContent);
const htmlContent = jade.render(fmContent.body);
return Object.assign({ content: htmlContent }, fmContent.attributes);
}
return Promise.resolve();
}
let htmlContents = '';
let markdownMetadata: MarkdownContent = {};
const jsonFileName = path.relative(SOURCE_DIR, filePath);
const destinationFileName = path.join(
DESTINATION_DIR,
path.dirname(jsonFileName),
path.basename(jsonFileName, '.md') + '.json'
);
markdownMetadata.headings = [];
const markdownContents = await readFile(filePath, { encoding: 'utf8' });
try {
let parsedMarkdown = frontMatter(markdownContents);
parsedMarkdown = await getGithubData(filePath, parsedMarkdown);
const renderer = new marked.Renderer();
collectHeadingMetadata(renderer, markdownMetadata);
changeCodeCreation(renderer);
localizeMarkdownLink(renderer, destinationFileName.replace('src',''), siteStructureJson);
htmlContents = marked(parsedMarkdown.body, {
renderer,
headerIds: true
}).trim();
await mkdirp(path.join(
DESTINATION_DIR,
path.dirname(jsonFileName)
));
fetch(path).then(response => response.text().then(text => {
let parsedMarkdown = frontmatter(text)
fragments[fragment] = {
jsx: () => (
),
...parsedMarkdown.attributes
}
}))
}
if (existing) {
level = existing;
return null;
}
const fromPatterns = path.resolve.bind(null, "./patterns");
const contents = await getDoc(fromPatterns(...itemPath), {
type
});
const ast = remark().parse(contents);
const first = find(ast, { type: "heading", depth: 1 });
const front =
typeof contents === "string"
? frontmatter(contents).attributes
: {};
const manifest = merge({}, DEFAULT_MANIFEST, front);
manifest.name = first ? first.children[0].value : name;
manifest.displayName = manifest.displayName || manifest.name;
const item = {
contents,
name,
manifest: type === "folder" ? manifest : file.manifest,
id: parts.slice(0, i + 1).join("/"),
path: itemPath,
type
};
level.children.push(item);