Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
- [Twemoji](https://github.com/twitter/twemoji)
- [lodash](https://lodash.com)
- [Tachyons](http://tachyons.io)
[discordapp]: https://discordapp.com/
[discord-docs]: https://discordapp.com/developers/docs/intro
[embed-docs]: https://discordapp.com/developers/docs/resources/channel#embed-object
`;
const rules = {
...SimpleMarkdown.defaultRules,
center: {
// really naive but we'll be ok
match: SimpleMarkdown.blockRegex(/^-= (.*?) =-/),
order: SimpleMarkdown.defaultRules.paragraph.order,
parse(capture, recurseParse, state) {
return { content: SimpleMarkdown.parseInline(recurseParse, capture[1], state) };
},
react(node, recurseOutput, state) {
return <div>{recurseOutput(node.content, state)}</div>;
}
},
paragraph: {
...SimpleMarkdown.defaultRules.paragraph,
react(node, recurseOutput, state) {
return <p>{recurseOutput(node.content, state)}</p>;
},
},
},
newline: {
// handle newlines, keep this to handle \n w/ other matchers
...SimpleMarkdown.defaultRules.newline,
// original
// match: blockRegex(/^(?:\n *)*\n/),
// ours: handle \n inside text also
match: SimpleMarkdown.anyScopeRegex(/^\n/),
},
paragraph: {
...SimpleMarkdown.defaultRules.paragraph,
// original:
// match: SimpleMarkdown.blockRegex(/^((?:[^\n]|\n(?! *\n))+)(?:\n *)+\n/),
// ours: allow simple empty blocks, stop before a block quote or a code block (aka fence)
match: SimpleMarkdown.blockRegex(/^((?:[^\n`]|(?:`(?!``))|\n(?!(?: *\n| *>)))+)\n?/),
parse: (capture, parse, state) => {
// Remove a trailing newline because sometimes it sneaks in from when we add the newline to create the initial block
const content = Styles.isMobile ? capture[1].replace(/\n$/, '') : capture[1]
return {
content: SimpleMarkdown.parseInline(parse, content, {...state, inParagraph: true}),
}
},
},
quotedFence: {
// The ``` code blocks in a quote block >
// i.e.
// > They wrote ```
// foo = true
// ```
// It's much easier and cleaner to make this a separate rule
...SimpleMarkdown.defaultRules.fence,
},
em: {
react: function (node, output, {...state}) {
state.withinText = true;
state.style = {
...(state.style || {}),
...styles.em
};
return React.createElement(Text, {
key: state.key,
style: styles.em,
}, output(node.content, state));
},
},
heading: {
match: SimpleMarkdown.blockRegex(/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n *)+/),
react: function (node, output, {...state}) {
// const newState = {...state};
state.withinText = true;
state.withinHeading = true;
state.style = {
...(state.style || {}),
...styles['heading' + node.level]
};
const ret = React.createElement(Text, {
key: state.key,
style: state.style,
}, output(node.content, state));
return ret;
},
// we didn't find a closing `$`
return null;
};
var mathMatch = (source, state) => mathMatcher(source, state, false);
var blockMathMatch = (source, state) => mathMatcher(source, state, true);
var TITLED_TABLE_REGEX = new RegExp(
"^\\|\\| +(.*) +\\|\\| *\\n" +
"(" +
// The simple-markdown nptable regex, without
// the leading `^`
SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +
")"
);
var crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\n\s*\n/);
var rules = _.extend({}, SimpleMarkdown.defaultRules, {
// NOTE: basically ignored by JIPT. wraps everything at the outer layer
columns: {
order: -2,
match: SimpleMarkdown.blockRegex(/^([\s\S]*\n\n)={5,}\n\n([\s\S]*)/),
parse: (capture, parse, state) => {
return {
col1: parse(capture[1], state),
col2: parse(capture[2], state),
};
},
react: (node, output, state) => {
return <div>
<div>
{output(node.col1, state)}</div></div>
return null;
}
},
parse: (capture, parse, state) => ({ id: capture[1] }),
react: (node, output, state) => node.id,
},
// This is pretty much horrible, but we have a regex here to capture an
// entire table + a title. capture[1] is the title. capture[2] of the
// regex is a copy of the simple-markdown nptable regex. Then we turn
// our capture[2] into tableCapture[0], and any further captures in
// our table regex into tableCapture[1..], and we pass tableCapture to
// our nptable regex
titledTable: {
// process immediately before nptables
order: SimpleMarkdown.defaultRules.nptable.order - 0.5,
match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX),
parse: (capture, parse, state) => {
var title = SimpleMarkdown.parseInline(parse, capture[1], state);
// Remove our [0] and [1] captures, and pass the rest to
// the nptable parser
var tableCapture = _.rest(capture, 2);
var table = SimpleMarkdown.defaultRules.nptable.parse(
tableCapture,
parse,
state
);
return {
title: title,
table: table,
};
},
var TITLED_TABLE_REGEX = new RegExp(
"^\\|\\| +(.*) +\\|\\| *\\n" +
"(" +
// The simple-markdown nptable regex, without
// the leading `^`
SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +
")"
);
var crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\n\s*\n/);
var rules = _.extend({}, SimpleMarkdown.defaultRules, {
// NOTE: basically ignored by JIPT. wraps everything at the outer layer
columns: {
order: -2,
match: SimpleMarkdown.blockRegex(/^([\s\S]*\n\n)={5,}\n\n([\s\S]*)/),
parse: (capture, parse, state) => {
return {
col1: parse(capture[1], state),
col2: parse(capture[2], state),
};
},
react: (node, output, state) => {
return <div>
<div>
{output(node.col1, state)}
</div>
<div>
{output(node.col2, state)}
{/* HACK(#sat) This is a cheap way to allow hints to be
* displayed in two-column items in the SAT mission. The
* hint renderer will be rendered into this div. Do not</div></div>
)
},
},
text: {
...SimpleMarkdown.defaultRules.text,
text: {
react: node => {
return node.content
},
},
},
paragraph: {
...SimpleMarkdown.defaultRules.paragraph,
match: SimpleMarkdown.blockRegex(/^((?:[^\n]|\n(?! *\n))+)(?:\n *)/),
react: (node, output, state) => {
return (
{output(node.content, state)}
)
},
},
strong: {
...SimpleMarkdown.defaultRules.strong,
react: (node, output, state) => {
return (
{output(node.content, state)}
const onClick = (ev) => {
ev.preventDefault()
remote.shell.openExternal(node.content)
}
return <a href="{node.content}">{node.content}</a>
}
},
newlinePlus: {
order: 19,
match: blockRegex(/^(?:\n *){2,}\n/),
parse: ignoreCapture,
react: function (node, output, state) { return <div> }
},
newline: {
order: 20,
match: blockRegex(/^(?:\n *)\n/),
parse: ignoreCapture,
react: function (node, output, state) { return <div> }
}
}, previewRules)
module.exports = {
previewRules,
rules
}
</div></div>
order: 18,
match: anyScopeRegex(/^(https?:\/\/[^\s<]+[^<>.,:;"')\]\s])/),
parse: function (capture, recurseParse, state) {
return { content: capture[1] }
},
react: function (node, output, state) {
const onClick = (ev) => {
ev.preventDefault()
remote.shell.openExternal(node.content)
}
return <a href="{node.content}">{node.content}</a>
}
},
newlinePlus: {
order: 19,
match: blockRegex(/^(?:\n *){2,}\n/),
parse: ignoreCapture,
react: function (node, output, state) { return <div> }
},
newline: {
order: 20,
match: blockRegex(/^(?:\n *)\n/),
parse: ignoreCapture,
react: function (node, output, state) { return <div> }
}
}, previewRules)
module.exports = {
previewRules,
rules
}
</div></div>