How to use the simple-markdown.defaultRules 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 JetBrains / youtrack-mobile / src / components / wiki / wiki__list-rule.js View on Github external
//
//  * 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 {
github TediCross / TediCross / src / discord2telegram / md2html.js View on Github external
["list", "heading"].forEach((type) => {
	simpleMarkdown.defaultRules[type] = {
		order: Number.POSITIVE_INFINITY,
		match: () => null	// Never match anything in order to ignore this rule
	};
});
github artsy / emission / src / lib / Components / Bidding / Components / MarkdownRenderer.tsx View on Github external
}
      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"))
github leovoel / embed-visualizer / src / components / markdown.jsx View on Github external
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) {
github artsy / emission / src / lib / utils / renderMarkdown.tsx View on Github external
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))
github apiko-dev / GitterMobile / libs / gitter-md-react-native / index.js View on Github external
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'));
  },
github JetBrains / youtrack-mobile / src / components / wiki / wiki__rules.js View on Github external
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,

    /**
github synzen / Discord.RSS / src / web / client / src / js / components / ControlPanel / utils / textParser.js View on Github external
parse: capture => {
      return {
        content: capture[1]
      }
    },
    react: (node, recurseOutput, state) =&gt; <br>
  },
  paragraph: SimpleMarkdown.defaultRules.paragraph,
  escape: SimpleMarkdown.defaultRules.escape,
  link: SimpleMarkdown.defaultRules.link,
  autolink: {
    ...SimpleMarkdown.defaultRules.autolink,
    match: SimpleMarkdown.inlineRegex(/^&lt;(https?:\/\/[^ &gt;]+)&gt;/)
  },
  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) {
github artsy / emission / src / lib / utils / renderMarkdown.tsx View on Github external
)
      },
    },

    inlineCode: {
      react: (node, output, state) =&gt; {
        return (
          
            {output(node.content, state)}
          
        )
      },
    },

    heading: {
      ...SimpleMarkdown.defaultRules.heading,
      react: (node, output, state) =&gt; {
        const map = {
          1: "8",
          2: "6",
          3: "5t",
          4: "5",
        }
        const size = map[node.level] || "4"
        return (
          
            {output(node.content, state)}
          
        )
      },
    },
  }
github nurdism / neko / client / src / components / markdown.ts View on Github external
},
        ],
        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)
    },
  },