Skip to content

Commit 7945541

Browse files
author
Inder Dhir
committed
Clean up code
1 parent e143043 commit 7945541

File tree

5 files changed

+25
-37
lines changed

5 files changed

+25
-37
lines changed

src/lib/renderRules.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ import hasParents from './util/hasParents';
1313

1414
import textStyleProps from './data/textStyleProps';
1515

16+
function renderText(node, inheritedStyles, styles) {
17+
// we trim new lines off the end of code blocks because the parser sends an extra one.
18+
let {content} = node;
19+
20+
if (
21+
typeof node.content === 'string' &&
22+
node.content.charAt(node.content.length - 1) === '\n'
23+
) {
24+
content = node.content.substring(0, node.content.length - 1);
25+
}
26+
27+
return (
28+
<Text key={node.key} style={[inheritedStyles, styles.code_block]}>
29+
{content}
30+
</Text>
31+
);
32+
}
33+
1634
const renderRules = {
1735
// when unknown elements are introduced, so it wont break
1836
unknown: (node, children, parent, styles) => null,
@@ -177,38 +195,10 @@ const renderRules = {
177195
</Text>
178196
),
179197
code_block: (node, children, parent, styles, inheritedStyles = {}) => {
180-
// we trim new lines off the end of code blocks because the parser sends an extra one.
181-
let {content} = node;
182-
183-
if (
184-
typeof node.content === 'string' &&
185-
node.content.charAt(node.content.length - 1) === '\n'
186-
) {
187-
content = node.content.substring(0, node.content.length - 1);
188-
}
189-
190-
return (
191-
<Text key={node.key} style={[inheritedStyles, styles.code_block]}>
192-
{content}
193-
</Text>
194-
);
198+
return renderText(node, inheritedStyles, styles);
195199
},
196200
fence: (node, children, parent, styles, inheritedStyles = {}) => {
197-
// we trim new lines off the end of code blocks because the parser sends an extra one.
198-
let {content} = node;
199-
200-
if (
201-
typeof node.content === 'string' &&
202-
node.content.charAt(node.content.length - 1) === '\n'
203-
) {
204-
content = node.content.substring(0, node.content.length - 1);
205-
}
206-
207-
return (
208-
<Text key={node.key} style={[inheritedStyles, styles.fence]}>
209-
{content}
210-
</Text>
211-
);
201+
return renderText(node, inheritedStyles, styles);
212202
},
213203

214204
// Tables

src/lib/util/cleanupTokens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function cleanupTokens(tokens) {
2525
* nested non text tokens breaks component
2626
*/
2727
const stack = [];
28-
tokens = tokens.reduce((acc, token, index) => {
28+
tokens = tokens.reduce((acc, token) => {
2929
if (token.type === 'link' && token.nesting === 1) {
3030
stack.push(token);
3131
} else if (

src/lib/util/convertAdditionalStyles.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ export default function convertAdditionalStyles(style) {
1919
return x != null;
2020
});
2121

22-
const conv = cssToReactNative(tuples);
23-
24-
return conv;
22+
return cssToReactNative(tuples);
2523
}

src/lib/util/groupTextTokens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function groupTextTokens(tokens) {
55

66
let hasGroup = false;
77

8-
tokens.forEach((token, index) => {
8+
tokens.forEach((token) => {
99
if (!token.block && !hasGroup) {
1010
hasGroup = true;
1111
result.push(new Token('textgroup', 1));

src/lib/util/renderInlineAsText.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function renderInlineAsText(tokens) {
2-
var result = '';
2+
let result = '';
33

4-
for (var i = 0, len = tokens.length; i < len; i++) {
4+
for (let i = 0, len = tokens.length; i < len; i++) {
55
if (tokens[i].type === 'text') {
66
result += tokens[i].content;
77
} else if (tokens[i].type === 'image') {

0 commit comments

Comments
 (0)