AAO-React-Native icon indicating copy to clipboard operation
AAO-React-Native copied to clipboard

Replace Markdown component with HTML renderer

Open hawkrives opened this issue 6 years ago • 7 comments

I found https://github.com/jsdf/react-native-htmlview/ today; I would like to replace our custom-ish Markdown component with a combination of a normal Markdown-to-HTML converter, which is then piped to react-native-htmlview to be rendered.

hawkrives avatar Aug 15 '19 00:08 hawkrives

@hawkrives what do you mean "combination of a normal Markdown-to-HTML converter" -- meaning something that's not currently in the app?

drewvolz avatar Sep 21 '19 00:09 drewvolz

I can't speak for @hawkrives, but I imagine the idea is to have something JS-y that converts from Markdown to HTML, and then having something React-Native-y that renders HTML instead of Markdown. Technically, it's an additional step, but the two legs in this new approach seem like far more likely places to find well-maintained packages rather than one full markdown-to-native renderer, if that makes sense.

rye avatar Sep 21 '19 00:09 rye

Yep

hawkrives avatar Sep 21 '19 02:09 hawkrives

I'd think showdown might give us what we'd want.

drewvolz avatar Sep 22 '19 02:09 drewvolz

Experimenting with showdown and react-native-htmlview.

I tweaked modules/markdown/markdown.js to look more like this:

import HTMLView from 'react-native-htmlview'
import showdown from 'showdown'

let {styles = {}, source} = this.props
var converter = new showdown.Converter()
converter.setFlavor('github')
var html = converter.makeHtml(source)

return <HTMLView value={html} stylesheet={styles} />

it doesn't look too bad. This is without any additional custom styles!

📸 Screenshots
~ ~
Screen Shot 2019-09-21 at 7 52 41 PM Screen Shot 2019-09-21 at 7 53 00 PM
Screen Shot 2019-09-21 at 7 55 29 PM Screen Shot 2019-09-21 at 7 55 58 PM

drewvolz avatar Sep 22 '19 03:09 drewvolz

I'd like to request marked (https://marked.js.org/#/README.md#README.md, https://github.com/markedjs/marked) as our Markdown parsing library.

Marked has more contributors and has had more development (and is faster), even though Showdown is a bit older. https://npm-stat.com/charts.html?package=marked&package=showdown&from=2015-09-20&to=2019-09-20

We should be able to do something like this to use marked:

import HTMLView from 'react-native-htmlview'
import marked from 'marked'

let {styles = {}, source} = this.props
let html = marked(source, {gfm: true})

return <HTMLView value={html} stylesheet={styles} />

hawkrives avatar Sep 22 '19 04:09 hawkrives

Thanks @hawkrives. I've swapped out showdown for marked and progress has started on the better-markdown branch.

drewvolz avatar Sep 29 '19 20:09 drewvolz