1.0.0 • Published 8 months ago

@grin-rnd/simple-markdown-parser v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Simple Markdown Parser

A simple markdown parser for React and React-native

Install

npm i simple-markdown-parser

How to use

The library exposes a MarkdownParser component which expects a text and a dictionary of renderers.
It parses the text and renders it based on the renderers, this way it can be used in both react and react-native.

Currently only bold and underline are supported. The delimiters are ** and __ accordingly. The empty renderer is applied to all texts, and the bold and underline are applied on top of each other.

React

import { MarkdownParser } from 'simple-markdown-parser'

<div style={{ whiteSpace: 'pre' }}>
  <Markdown
    text={'**Hello __world__**'}
    renderers={{
      empty: text => <span>{text}</span>,
      bold: text => <span style={{ fontWeight: 'bold' }}>{text}</span>,
      underline: text => <span style={{ textDecoration: 'underline' }}>{text}</span>
    }}
  />
</div>

React Native

import { MarkdownParser } from 'simple-markdown-parser'

<Text>
  <Markdown
    text={'**Hello __world__**'}
    renderers={{
      empty: text => <Text>{text}</Text>,
      bold: text => <Text style={{ fontWeight: 'bold' }}>{text}</Text>,
      underline: text => <Text style={{ textDecorationLine: 'underline' }}>{text}</Text>
    }}
  />
</Text>
1.0.0

8 months ago