Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion HTMLView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var PARAGRAPH_BREAK = '\n\n'
var BULLET = ' \u2022 '

function htmlToElement(rawHtml, opts, done) {

function domToElement(dom, parent) {
if (!dom) return null

Expand All @@ -23,7 +24,7 @@ function htmlToElement(rawHtml, opts, done) {

if (node.type == 'text') {
return (
<Text key={index} style={parent ? opts.styles[parent.name] : null}>
<Text key={index} style={parent ? inheritedStyle(parent) : null}>
{entities.decodeHTML(node.data)}
</Text>
)
Expand All @@ -49,6 +50,11 @@ function htmlToElement(rawHtml, opts, done) {
})
}

function inheritedStyle(parent) {
var style = [opts.styles[parent.name] || {}];
return parent.parent ? style.concat(inheritedStyle(parent.parent)) : style;
}

var handler = new htmlparser.DomHandler(function (err, dom) {
if (err) done(err)
done(null, domToElement(dom))
Expand Down