How to use the simple-markdown.reactFor 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 CharlesMangwa / react-native-simple-markdown / src / index.js View on Github external
_.merge(
          {},
          SimpleMarkdown.defaultRules,
          initialRules(mergedStyles),
          this.props.rules,
        ),
      )
      const child = Array.isArray(this.props.children)
        ? this.props.children.join('')
        : this.props.children
      // @TODO: Add another \n?
      const blockSource = `${child}\n`
      const tree = SimpleMarkdown.parserFor(rules)(blockSource, {
        inline: false,
      })
      return SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(rules, 'react'))(
        tree,
      )
    }
    catch (errors) {
      this.props.errorHandler
        ? this.props.errorHandler(errors, children)
        : console.error(errors)
    }
    return null
  }
github artsy / emission / src / lib / Components / Bidding / Components / MarkdownRenderer.tsx View on Github external
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"))

export const toReact = md => {
  const syntaxTree = parser(md)
  return reactOutput(syntaxTree)
}

interface NativeMarkdownProps {
  md: string
}

export class MarkdownRenderer extends React.Component {
  render() {
    return 
  }
}
github keybase / client / shared / common-adapters / markdown / react.js View on Github external
key={state.key}
          allowFontScaling={state.allowFontScaling}
        />
      )
    },
    paragraph: (node, output, state) => (
      
    ),
  })
)

// TODO: Fix the typing here. Can ast actually be a non-object? Can
// output actually only return strings?
const previewOutput = SimpleMarkdown.reactFor(
  (ast: SingleASTNode, output: Output, state: State): ReactElements => {
    // leaf node is just the raw value, so it has no ast.type
    if (typeof ast !== 'object') {
      return ast
    }

    switch (ast.type) {
      case 'emoji':
        return reactComponentsForMarkdownType.emoji(ast, output, state)
      case 'newline':
        return ' '
      case 'blockQuote':
        return '> ' + output(ast.content, state)
      case 'codeBlock':
        return ' ' + output(ast.content, state)
      default:
github synzen / Discord.RSS / src / web / client / src / js / components / ControlPanel / utils / textParser.js View on Github external
function parserFor (rules, returnAst) {
  const parser = SimpleMarkdown.parserFor(rules)
  const renderer = SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(rules, 'react'))
  return function (input = '', inline = true, state = {}, transform = null) {
    if (!inline) {
      input += '\n\n'
    }

    let ast = parser(input, { inline, ...state })
    ast = flattenAst(ast)
    if (transform) {
      ast = transform(ast)
    }

    if (returnAst) {
      return ast
    }

    return renderer(ast)
github leovoel / embed-visualizer / src / components / markdown.jsx View on Github external
function parserFor(rules, returnAst) {
  const parser = SimpleMarkdown.parserFor(rules);
  const renderer = SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(rules, 'react'));
  return function(input='', inline=true, state={}, transform=null) {
    if (!inline) {
      input += '\n\n';
    }

    let ast = parser(input, { inline, ...state });
    ast = flattenAst(ast);
    if (transform) {
      ast = transform(ast);
    }

    if (returnAst) {
      return ast;
    }

    return renderer(ast);
github Benjamin-Dobell / react-native-markdown-view / MarkdownView.js View on Github external
render() {
    const {rules = {}, styles = {}, onLinkPress} = this.props

    const mergedStyles = mergeStyles(DefaultStyles, styles)
    const mergedRules = mergeRules(SimpleMarkdown.defaultRules, simpleMarkdownRules(mergeRules(DefaultRules, rules), mergedStyles))

    const markdown = (Array.isArray(this.props.children) ? this.props.children.join('') : this.props.children) + '\n\n'

    const ast = SimpleMarkdown.parserFor(mergedRules)(markdown, {inline: false})
    const render = SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(mergedRules, 'react'))
    const initialRenderState = {onLinkPress: onLinkPress}

    return (
      
    )
  }
}
github Khan / perseus / src / perseus-markdown.jsx View on Github external
* Markdown markup and widget references are ignored.
 */
var characterCount = (source) => {
    var ast = parse(source);
    var content = getContent(ast).join('');
    return content.length;
};

module.exports = {
    characterCount: characterCount,
    traverseContent: traverseContent,
    parse: parse,
    parseInline: inlineParser,
    reactFor: SimpleMarkdown.reactFor,
    ruleOutput: SimpleMarkdown.ruleOutput(rules, "react"),
    basicOutput: SimpleMarkdown.reactFor(
        SimpleMarkdown.ruleOutput(rules, "react")
    ),
    sanitizeUrl: SimpleMarkdown.sanitizeUrl,
};
github keybase / client / shared / common-adapters / markdown / react.js View on Github external
switch (ast.type) {
      case 'emoji':
        return reactComponentsForMarkdownType.emoji(ast, output, state)
      case 'newline':
        return ' '
      case 'blockQuote':
        return '> ' + output(ast.content, state)
      case 'codeBlock':
        return ' ' + output(ast.content, state)
      default:
        return output(ast.content, state)
    }
  }
)

const reactOutput = SimpleMarkdown.reactFor(ruleOutput(reactComponentsForMarkdownType))

export {EmojiIfExists, bigEmojiOutput, markdownStyles, previewOutput, reactOutput}
github andangrd / react-native-markdown-package / index.js View on Github external
onLink: props.onLink,
      bgImage: props.bgImage,
      onImageOpen: props.onImageOpen,
      onImageClose: props.onImageClose,
    };

    const mergedStyles = merge({}, styles, props.styles);
    var rules = require('./rules')(mergedStyles, opts);
    rules = merge({}, SimpleMarkdown.defaultRules, rules);

    const parser = SimpleMarkdown.parserFor(rules);
    this.parse = function (source) {
      const blockSource = source + '\n\n';
      return parser(blockSource, {inline: false});
    };
    this.renderer = SimpleMarkdown.reactFor(SimpleMarkdown.ruleOutput(rules, 'react'));
  }