How to use the simple-markdown.blockRegex function in simple-markdown

To help you get started, we’ve selected a few simple-markdown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leovoel / embed-visualizer / src / components / aboutmodal.jsx View on Github external
- [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>;
    },
github keybase / client / shared / common-adapters / markdown / shared.js View on Github external
},
  },
  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,
github andangrd / react-native-markdown-package / rules.js View on Github external
},
    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;
      },
github Khan / perseus / src / perseus-markdown.jsx View on Github external
// we didn't find a closing `$`
    return null;
};
var mathMatch = (source, state) =&gt; mathMatcher(source, state, false);
var blockMathMatch = (source, state) =&gt; 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) =&gt; {
            return {
                col1: parse(capture[1], state),
                col2: parse(capture[2], state),
            };
        },
        react: (node, output, state) =&gt; {
            return <div>
                <div>
                    {output(node.col1, state)}</div></div>
github Khan / perseus / src / perseus-markdown.jsx View on Github external
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,
            };
        },
github Khan / perseus / src / perseus-markdown.jsx View on Github external
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) =&gt; {
            return {
                col1: parse(capture[1], state),
                col2: parse(capture[2], state),
            };
        },
        react: (node, output, state) =&gt; {
            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>
github artsy / emission / src / lib / utils / renderMarkdown.tsx View on Github external
)
      },
    },

    text: {
      ...SimpleMarkdown.defaultRules.text,
      text: {
        react: node =&gt; {
          return node.content
        },
      },
    },

    paragraph: {
      ...SimpleMarkdown.defaultRules.paragraph,
      match: SimpleMarkdown.blockRegex(/^((?:[^\n]|\n(?! *\n))+)(?:\n *)/),
      react: (node, output, state) =&gt; {
        return (
          
            {output(node.content, state)}
          
        )
      },
    },

    strong: {
      ...SimpleMarkdown.defaultRules.strong,
      react: (node, output, state) =&gt; {
        return (
          
            {output(node.content, state)}
github deltachat / deltachat-desktop / src / renderer / components / message / MessageMarkdown.js View on Github external
const onClick = (ev) =&gt; {
        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>
github deltachat / deltachat-desktop / src / renderer / components / message / MessageMarkdown.js View on Github external
order: 18,
    match: anyScopeRegex(/^(https?:\/\/[^\s&lt;]+[^&lt;&gt;.,:;"')\]\s])/),
    parse: function (capture, recurseParse, state) {
      return { content: capture[1] }
    },
    react: function (node, output, state) {
      const onClick = (ev) =&gt; {
        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>