Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
// * but this is not part of the same item
const LIST_ITEM_R = new RegExp(
LIST_ITEM_PREFIX +
'[^\\n]*(?:\\n' +
`(?!\\1${LIST_BULLET} )[^\\n]*)*(\n|$)`,
'gm'
);
const BLOCK_END_R = /\n{2,}$/;
// recognize the end of a paragraph block inside a list item:
// two or more newlines at end end of the item
const LIST_BLOCK_END_R = BLOCK_END_R;
const LIST_ITEM_END_R = / *\n+$/;
const rule = {
...SimpleMarkdown.defaultRules.list,
match: function (source, state, prevCapture) {
// We only want to break into a list if we are at the start of a
// line. This is to avoid parsing "hi * there" with "* there"
// becoming a part of a list.
// You might wonder, "but that's inline, so of course it wouldn't
// start a list?". You would be correct! Except that some of our
// lists can be inline, because they might be inside another list,
// in which case we can parse with inline scope, but need to allow
// nested lists inside this inline scope.
const isStartOfLine = LIST_LOOKBEHIND_R.test(prevCapture);
if (isStartOfLine) {
return LIST_R.exec(source);
} else {
["list", "heading"].forEach((type) => {
simpleMarkdown.defaultRules[type] = {
order: Number.POSITIVE_INFINITY,
match: () => null // Never match anything in order to ignore this rule
};
});
}
return (
openUrl(node.target)} ref={el => (element = el)}>
{output(node.content, state)}
)
},
},
text: {
...SimpleMarkdown.defaultRules.text,
react: (node, _output, state) => {
return
},
},
paragraph: {
...SimpleMarkdown.defaultRules.paragraph,
react: (node, output, state) => {
return (
{output(node.content, state)}
)
},
},
}
// Markdown parser setup
const rawBuiltParser = SimpleMarkdown.parserFor(rules)
const parser = source => {
const blockSource = source + "\n\n"
return rawBuiltParser(blockSource, { inline: false })
}
const reactOutput = SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(rules, "react"))
const surrogates = Object.keys(EMOJI_TO_NAME)
.sort(surrogate => -surrogate.length)
.map(surrogate => escape(surrogate))
.join('|');
return new RegExp('(' + surrogates + ')', 'g');
})();
function translateSurrogatesToInlineEmoji(surrogates) {
return surrogates.replace(replacer, (_, match) => convertSurrogateToName(match));
}
// i am not sure why are these rules split like this.
const baseRules = {
newline: SimpleMarkdown.defaultRules.newline,
paragraph: SimpleMarkdown.defaultRules.paragraph,
escape: SimpleMarkdown.defaultRules.escape,
link: SimpleMarkdown.defaultRules.link,
autolink: {
...SimpleMarkdown.defaultRules.autolink,
match: SimpleMarkdown.inlineRegex(/^<(https?:\/\/[^ >]+)>/)
},
url: SimpleMarkdown.defaultRules.url,
strong: SimpleMarkdown.defaultRules.strong,
em: SimpleMarkdown.defaultRules.em,
u: SimpleMarkdown.defaultRules.u,
br: SimpleMarkdown.defaultRules.br,
inlineCode: SimpleMarkdown.defaultRules.inlineCode,
emoticon: {
order: SimpleMarkdown.defaultRules.text.order,
match: function(source) {
export function defaultRules(modal: boolean = false) {
return {
...SimpleMarkdown.defaultRules,
link: {
...SimpleMarkdown.defaultRules.link,
react: (node, output, state) => {
state.withinText = true
let element
const openUrl = url => {
if (node.target.startsWith("mailto:")) {
Linking.canOpenURL(url)
.then(supported => {
if (!supported) {
console.log("Unable to handle URL: " + url)
} else {
return Linking.openURL(url)
}
})
.catch(err => console.error("An error occurred", err))
componentWillMount: function() {
var mergedStyles = _.merge({}, styles, this.props.style);
var rules = require('./rules')(mergedStyles);
rules = _.merge({}, SimpleMarkdown.defaultRules, rules);
var parser = SimpleMarkdown.parserFor(rules);
this.parse = function(source) {
var blockSource = source + '\n\n';
return parser(blockSource, {inline: false});
};
this.renderer = SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(rules, 'react'));
},
export default function (actions, imageHeaders: ?Object = null) {
return {
/**
* Basic rules
*/
newline: {
...SimpleMarkdown.defaultRules.newline,
react: (node, output, state) => {
return ;
}
},
paragraph: {
...SimpleMarkdown.defaultRules.paragraph,
react: (node, output, state) => {
const isFirstParagraph = state.key === 0;
return ;
}
},
text: SimpleMarkdown.defaultRules.text,
/**
parse: capture => {
return {
content: capture[1]
}
},
react: (node, recurseOutput, state) => <br>
},
paragraph: SimpleMarkdown.defaultRules.paragraph,
escape: SimpleMarkdown.defaultRules.escape,
link: SimpleMarkdown.defaultRules.link,
autolink: {
...SimpleMarkdown.defaultRules.autolink,
match: SimpleMarkdown.inlineRegex(/^<(https?:\/\/[^ >]+)>/)
},
url: SimpleMarkdown.defaultRules.url,
strong: SimpleMarkdown.defaultRules.strong,
em: SimpleMarkdown.defaultRules.em,
u: SimpleMarkdown.defaultRules.u,
br: SimpleMarkdown.defaultRules.br,
inlineCode: SimpleMarkdown.defaultRules.inlineCode,
emoticon: {
order: SimpleMarkdown.defaultRules.text.order,
match: function (source) {
return /^(¯\\_\(ツ\)_\/¯)/.exec(source)
},
parse: function (capture) {
return { type: 'text', content: capture[1] }
}
},
mention: {
order: SimpleMarkdown.defaultRules.text.order,
match: function (source) {
)
},
},
inlineCode: {
react: (node, output, state) => {
return (
{output(node.content, state)}
)
},
},
heading: {
...SimpleMarkdown.defaultRules.heading,
react: (node, output, state) => {
const map = {
1: "8",
2: "6",
3: "5t",
4: "5",
}
const size = map[node.level] || "4"
return (
{output(node.content, state)}
)
},
},
}
},
],
target: capture[1],
}
},
html(node, output, state) {
return htmlTag(
'a',
output(node.content, state),
{ href: md.sanitizeUrl(node.target) as string, target: '_blank' },
state,
)
},
},
strike: {
order: md.defaultRules.text.order,
match: md.inlineRegex(/^~~([\s\S]+?)~~(?!_)/),
parse(capture) {
return {
content: [
{
type: 'text',
content: capture[1],
},
],
target: capture[1],
}
},
html(node, output, state) {
return htmlTag('s', output(node.content, state), {}, state)
},
},