Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import MarkdownIt from 'markdown-it';
import fm from 'front-matter';
import Immutable from 'immutable';
import { codeToText } from './util';
let markedownIt = new MarkdownIt();
export default function parse(md) {
const content = fm(md);
const parsedMarkdown = markedownIt.parseInline(content.body);
const blockParsedMarkdown = markedownIt.parse(content.body);
// Extract code blocks first
let codeBlocks = [];
for (let block of blockParsedMarkdown) {
if (block.type === 'fence') {
const info = block.info.split(';').map(s => s.trim());
const language = info[0];
const attrs = info.splice(1);
codeBlocks.push(Immutable.fromJS({
type: 'code',
content: block.content.trim(),
import taskList from "markdown-it-task-lists";
import TOC from "markdown-it-table-of-contents";
import twemoji from 'twemoji';
const markdownOption = {
html: false, // Enable HTML tags in source
xhtmlOut: false, // Use '/' to close single tags (<br>)
breaks: false, // Convert '\n' in paragraphs into <br>
langPrefix: 'language-', // CSS language prefix for fenced blocks
linkify: false, // autoconvert URL-like texts to links
typographer: true, // Enable smartypants and other sweet transforms
quotes: '“”‘’',
};
const md = new MarkdownIt(markdownOption);
const anchorOption = {
level: [1, 2, 3]
};
const imsizeOption = {
autofill: true
};
const TOC_Option = {
includeLevel: [1, 2, 3]
};
md.use(abbr)
.use(anchor, anchorOption)
import customFence from 'markdown-it-fence';
function generatedImage(md): void {
return customFence(md, 'generated_image', {
marker: '$',
validate: () => true,
});
}
const mdOptions = {
html: true,
langPrefix: 'highlight ',
linkify: false,
breaks: false,
};
const parser = markdownIt(mdOptions)
.use(attrs)
.use(lazyHeaders)
.use(emoji, { shortcuts: {} })
.use(expandTabs, { tabWidth: 4 })
.use(generatedImage)
.use(video, { youtube: { width: 640, height: 390 } });
function parseMarkdown(markdown: string): Token[] {
return parser.parse(markdown, {});
}
export default parseMarkdown;
import MarkdownIt from 'markdown-it';
import mentions from 'markdown-it-mentions';
import emojis from '../../emoji.json';
const shaRe = new RegExp(/ \b[0-9a-f]{5,40}\b/, 'gm');
const prOrIssueNumber = new RegExp(/#[0-9]+\b/gm);
const emojiRe = new RegExp(':[a-zA-Z]+:', 'gm');
const md = new MarkdownIt({
linkify: true
});
function parseURL(username) {
return `https://github.com/${ username }`;
}
export default function (str, repo, pr) {
str = str
.replace(emojiRe, function (str) {
const s = str.substr(1, str.length - 2);
if (emojis[s]) return emojis[s];
return str;
})
.replace(shaRe, function (str) {
constructor(props) {
super(props);
this.markdown = new MarkdownIt();
this.state = {
MarkdownContent: this.props.value || '',
isPreview: false
};
}
getCodeMirror() {
function mdReactFactory(options={}) {
const { onIterate, tags=DEFAULT_TAGS,
presetName, markdownOptions,
enableRules=[], disableRules=[], plugins=[],
onGenerateKey=(tag, index) => `mdrct-${tag}-${index}`,
className } = options;
let md = markdown(markdownOptions || presetName)
.enable(enableRules)
.disable(disableRules);
const convertRules = assign({}, DEFAULT_RULES, options.convertRules);
md = reduce(plugins, (m, plugin) =>
plugin.plugin ?
m.use(plugin.plugin, ...plugin.args) :
m.use(plugin),
md
);
function iterateTree(tree, level=0, index=0) {
let tag = tree.shift();
const key = onGenerateKey(tag, index);
componentWillMount() {
this.md = new MarkdownIt();
const { preset } = this.props;
switch (preset) {
case 'activationDescription': {
this.md.configure(activationDescriptionPreset).enable('linkify').enable(['link', 'list', 'emphasis']);
break;
}
default: {
this.md.enable('linkify');
}
}
const customRenderer = (tokens, idx, options, env, self) => self.renderToken(tokens, idx, options);
const Section = ({ headingLevel, title, description, children }) => {
const md = markdownIt({
html: true,
linkify: true
});
return (
<section>
<header>
<h2>
{ description &&
<div>
}
</div></h2></header>
<div>{children}</div>
</section>
)
};
document.addEventListener('DOMContentLoaded', () => {
const md = new MarkdownIt({
html: true,
breaks: true,
linkify: true,
langPrefix: 'language-'
})
md.use(MarkdownItEmoji).use(MarkdownItMention).use(MarkdownItTaskLists)
Array.from(document.querySelectorAll('.js-markdown-view'), e => {
e.style.display = 'block'
e.innerHTML = md.render(e.textContent)
})
})
return nUrl.resolve(imgFromUrl, link)
}
return nUrl.resolve(fromUrl, link)
},
highlight,
markdownItOptions
})
const mark = [taskList, emoji, preamble, replaceLink, headings]
.concat(transformers)
.reduce((main, plugin) => {
if (Array.isArray(plugin)) {
return main.use(plugin[0], plugin[1])
}
return main.use(plugin)
}, new Markdown(opts))
return mark.render(markdown)
}