import React from 'react'
//use markdown-it to render markdown
//alternately use markdown to jsx
const ShowMarkdown = (props) => {
return
{props.text ?
props.text:
props.diff ?
diffToPre(props.diff) :
null
}
}
export default ShowMarkdown
function diffToPre(diff) {
return diff.map(part => (
part.added ? {part.value}{ifNotNewlineSpace(part.value)} :
part.removed ? {part.value}{ifNotNewlineSpace(part.value)} :
{part.value}{ifNotNewlineSpace(part.value)}
))
}
const ifNotNewlineSpace = str => {
return !str.endsWith('\n') ? ' ' : ''
}