diff --git a/src/lib/renderRules.js b/src/lib/renderRules.js index 6f2ed8d4..0342cc8b 100644 --- a/src/lib/renderRules.js +++ b/src/lib/renderRules.js @@ -13,6 +13,24 @@ import hasParents from './util/hasParents'; import textStyleProps from './data/textStyleProps'; +function renderText(node, inheritedStyles, styles) { + // we trim new lines off the end of code blocks because the parser sends an extra one. + let {content} = node; + + if ( + typeof node.content === 'string' && + node.content.charAt(node.content.length - 1) === '\n' + ) { + content = node.content.substring(0, node.content.length - 1); + } + + return ( + + {content} + + ); +} + const renderRules = { // when unknown elements are introduced, so it wont break unknown: (node, children, parent, styles) => null, @@ -177,38 +195,10 @@ const renderRules = { ), code_block: (node, children, parent, styles, inheritedStyles = {}) => { - // we trim new lines off the end of code blocks because the parser sends an extra one. - let {content} = node; - - if ( - typeof node.content === 'string' && - node.content.charAt(node.content.length - 1) === '\n' - ) { - content = node.content.substring(0, node.content.length - 1); - } - - return ( - - {content} - - ); + return renderText(node, inheritedStyles, styles); }, fence: (node, children, parent, styles, inheritedStyles = {}) => { - // we trim new lines off the end of code blocks because the parser sends an extra one. - let {content} = node; - - if ( - typeof node.content === 'string' && - node.content.charAt(node.content.length - 1) === '\n' - ) { - content = node.content.substring(0, node.content.length - 1); - } - - return ( - - {content} - - ); + return renderText(node, inheritedStyles, styles); }, // Tables diff --git a/src/lib/util/cleanupTokens.js b/src/lib/util/cleanupTokens.js index 621b761d..7f0840b7 100644 --- a/src/lib/util/cleanupTokens.js +++ b/src/lib/util/cleanupTokens.js @@ -25,7 +25,7 @@ export function cleanupTokens(tokens) { * nested non text tokens breaks component */ const stack = []; - tokens = tokens.reduce((acc, token, index) => { + tokens = tokens.reduce((acc, token) => { if (token.type === 'link' && token.nesting === 1) { stack.push(token); } else if ( diff --git a/src/lib/util/convertAdditionalStyles.js b/src/lib/util/convertAdditionalStyles.js index 3cf4e40e..7e2af315 100644 --- a/src/lib/util/convertAdditionalStyles.js +++ b/src/lib/util/convertAdditionalStyles.js @@ -19,7 +19,5 @@ export default function convertAdditionalStyles(style) { return x != null; }); - const conv = cssToReactNative(tuples); - - return conv; + return cssToReactNative(tuples); } diff --git a/src/lib/util/groupTextTokens.js b/src/lib/util/groupTextTokens.js index fb38e3d1..f6d564d1 100644 --- a/src/lib/util/groupTextTokens.js +++ b/src/lib/util/groupTextTokens.js @@ -5,7 +5,7 @@ export default function groupTextTokens(tokens) { let hasGroup = false; - tokens.forEach((token, index) => { + tokens.forEach((token) => { if (!token.block && !hasGroup) { hasGroup = true; result.push(new Token('textgroup', 1)); diff --git a/src/lib/util/renderInlineAsText.js b/src/lib/util/renderInlineAsText.js index 274efae9..3d5d3170 100644 --- a/src/lib/util/renderInlineAsText.js +++ b/src/lib/util/renderInlineAsText.js @@ -1,7 +1,7 @@ export default function renderInlineAsText(tokens) { - var result = ''; + let result = ''; - for (var i = 0, len = tokens.length; i < len; i++) { + for (let i = 0, len = tokens.length; i < len; i++) { if (tokens[i].type === 'text') { result += tokens[i].content; } else if (tokens[i].type === 'image') {