Skip to content

Commit a9abf1c

Browse files
committed
remove text and inline elements and rely on block property from token.
#39
1 parent 37a2d96 commit a9abf1c

File tree

8 files changed

+16
-13
lines changed

8 files changed

+16
-13
lines changed

example/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const routes = {
9696

9797
if (token.content === name) {
9898
const newToken = new Token(name, '', token.nesting);
99+
99100
newToken.content = token.content;
100101
block.children = md.utils.arrayReplaceAt(block.children, j, [newToken]);
101102
}

example/react-native-markdown-renderer/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export default class Markdown extends Component {
5151
let invalidProps = [];
5252
const prop = props[propName];
5353

54-
5554
if (!prop) {
5655
return;
5756
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export default class Token {
33
this.type = type;
44
this.nesting = nesting;
55
this.children = children;
6+
this.block = false;
67
}
78
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function cleanupTokens(tokens) {
1515
if (token.type === 'link' && token.nesting === 1) {
1616
stack.push(token);
1717
} else if (stack.length > 0 && token.type === 'link' && token.nesting === -1) {
18-
if (stack.some(stackToken => !getIsTextType(stackToken.type))) {
18+
if (stack.some(stackToken => stackToken.block)) {
1919
stack[0].type = 'blocklink';
2020
token.type = 'blocklink';
2121
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import getIsTextType from './getIsTextType';
1+
// import getIsTextType from './getIsTextType';
22
import Token from './Token';
3-
import getIsInlineTextType from './getIsInlineTextType';
3+
// import getIsInlineTextType from './getIsInlineTextType';
44

55
export default function groupTextTokens(tokens) {
66
const result = [];
77

88
let hasGroup = false;
99
tokens.forEach((token, index) => {
10-
if (getIsTextType(token.type) && !hasGroup) {
10+
if (!token.block && !hasGroup) {
1111
hasGroup = true;
1212
result.push(new Token('textgroup', 1));
1313
result.push(token);
14-
} else if (getIsTextType(token.type) && !getIsInlineTextType(token.type) && hasGroup) {
14+
} else if (!token.block && hasGroup) {
1515
hasGroup = false;
1616
result.push(token);
1717
result.push(new Token('textgroup', -1));
18-
} else if (!getIsTextType(token.type) && hasGroup) {
18+
} else if (token.block && hasGroup) {
1919
hasGroup = false;
2020
result.push(new Token('textgroup', -1));
2121
result.push(token);

src/lib/util/Token.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ export default class Token {
33
this.type = type;
44
this.nesting = nesting;
55
this.children = children;
6+
this.block = false;
7+
68
}
79
}

src/lib/util/cleanupTokens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function cleanupTokens(tokens) {
1515
if (token.type === 'link' && token.nesting === 1) {
1616
stack.push(token);
1717
} else if (stack.length > 0 && token.type === 'link' && token.nesting === -1) {
18-
if (stack.some(stackToken => !getIsTextType(stackToken.type))) {
18+
if (stack.some(stackToken => stackToken.block)) {
1919
stack[0].type = 'blocklink';
2020
token.type = 'blocklink';
2121
}

src/lib/util/groupTextTokens.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import getIsTextType from './getIsTextType';
1+
// import getIsTextType from './getIsTextType';
22
import Token from './Token';
3-
import getIsInlineTextType from './getIsInlineTextType';
3+
// import getIsInlineTextType from './getIsInlineTextType';
44

55
export default function groupTextTokens(tokens) {
66
const result = [];
77

88
let hasGroup = false;
99
tokens.forEach((token, index) => {
10-
if (getIsTextType(token.type) && !hasGroup) {
10+
if (!token.block && !hasGroup) {
1111
hasGroup = true;
1212
result.push(new Token('textgroup', 1));
1313
result.push(token);
14-
} else if (getIsTextType(token.type) && !getIsInlineTextType(token.type) && hasGroup) {
14+
} else if (!token.block && hasGroup) {
1515
hasGroup = false;
1616
result.push(token);
1717
result.push(new Token('textgroup', -1));
18-
} else if (!getIsTextType(token.type) && hasGroup) {
18+
} else if (token.block && hasGroup) {
1919
hasGroup = false;
2020
result.push(new Token('textgroup', -1));
2121
result.push(token);

0 commit comments

Comments
 (0)