Skip to content

Commit 136d1be

Browse files
committed
cleaup of code, removing on used code #39
1 parent 099416b commit 136d1be

File tree

10 files changed

+32
-128
lines changed

10 files changed

+32
-128
lines changed

example/react-native-markdown-renderer/lib/parser.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,6 @@ import groupTextTokens from './util/groupTextTokens';
1414
*/
1515
export function parser(source, renderer, markdownIt) {
1616
let tokens = stringToTokens(source, markdownIt);
17-
18-
tokens = tokens.reduce((acc, curr) => {
19-
if (curr.children && curr.children.length > 0) {
20-
console.log(curr);
21-
// acc.push({
22-
// ...curr,
23-
// children: null,
24-
// nesting: 1,
25-
// });
26-
27-
while (curr.children.length) {
28-
acc.push(curr.children.shift());
29-
}
30-
31-
// acc.push({
32-
// ...curr,
33-
// children: null,
34-
// nesting: -1,
35-
// });
36-
} else {
37-
acc.push(curr);
38-
}
39-
40-
return acc;
41-
}, []);
42-
43-
console.log(tokens);
44-
4517
tokens = cleanupTokens(tokens);
4618
tokens = groupTextTokens(tokens);
4719

example/react-native-markdown-renderer/lib/util/cleanupTokens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import getTokenTypeByToken from './getTokenTypeByToken';
2-
import removeInlineTokens from './removeInlineTokens';
2+
import flattenTokens from './flattenTokens';
33

44
export function cleanupTokens(tokens) {
5-
tokens = removeInlineTokens(tokens);
5+
tokens = flattenTokens(tokens);
66
tokens.forEach(token => {
77
token.type = getTokenTypeByToken(token);
88

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function flattenTokens(tokens) {
2+
return tokens.reduce((acc, curr) => {
3+
if (curr.children && curr.children.length > 0) {
4+
const children = flattenTokens(curr.children);
5+
while (children.length) {
6+
acc.push(children.shift());
7+
}
8+
} else {
9+
acc.push(curr);
10+
}
11+
12+
return acc;
13+
}, []);
14+
}

example/react-native-markdown-renderer/lib/util/getIsInlineTextType.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

example/react-native-markdown-renderer/lib/util/getIsTextType.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

example/react-native-markdown-renderer/lib/util/removeInlineTokens.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/lib/parser.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,6 @@ import groupTextTokens from './util/groupTextTokens';
1414
*/
1515
export function parser(source, renderer, markdownIt) {
1616
let tokens = stringToTokens(source, markdownIt);
17-
18-
tokens = tokens.reduce((acc, curr) => {
19-
if (curr.children && curr.children.length > 0) {
20-
console.log(curr);
21-
// acc.push({
22-
// ...curr,
23-
// children: null,
24-
// nesting: 1,
25-
// });
26-
27-
while (curr.children.length) {
28-
acc.push(curr.children.shift());
29-
}
30-
31-
// acc.push({
32-
// ...curr,
33-
// children: null,
34-
// nesting: -1,
35-
// });
36-
} else {
37-
acc.push(curr);
38-
}
39-
40-
return acc;
41-
}, []);
42-
43-
console.log(tokens);
44-
4517
tokens = cleanupTokens(tokens);
4618
tokens = groupTextTokens(tokens);
4719

src/lib/util/cleanupTokens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import getTokenTypeByToken from './getTokenTypeByToken';
2-
import removeInlineTokens from './removeInlineTokens';
2+
import flattenTokens from './flattenTokens';
33

44
export function cleanupTokens(tokens) {
5-
tokens = removeInlineTokens(tokens);
5+
tokens = flattenTokens(tokens);
66
tokens.forEach(token => {
77
token.type = getTokenTypeByToken(token);
88

src/lib/util/flattenTokens.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function flattenTokens(tokens) {
2+
return tokens.reduce((acc, curr) => {
3+
if (curr.children && curr.children.length > 0) {
4+
const children = flattenTokens(curr.children);
5+
while (children.length) {
6+
acc.push(children.shift());
7+
}
8+
} else {
9+
acc.push(curr);
10+
}
11+
12+
return acc;
13+
}, []);
14+
}

src/lib/util/removeInlineTokens.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)