Skip to content

Commit 76d02f9

Browse files
committed
adding grouping of text, this fixed issue #4 tested.
1 parent 45c27a3 commit 76d02f9

File tree

8 files changed

+95
-365
lines changed

8 files changed

+95
-365
lines changed

bin/astTester.js

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

example/App.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ With a reference later in the document defining the URL location:
162162
163163
[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"
164164
`;
165+
166+
const markdownText2 = ` # Syntax Support
167+
168+
__Advertisement :)__
169+
170+
This is a text. Click [here](https://google.com) to open a link. Let's add some more text to see how this behaves.`;
171+
165172
/**
166173
* i'm overriding the default h1 render function.
167174
*/

example/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "example",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"devDependencies": {
6-
"react-native-scripts": "0.0.50",
76
"jest-expo": "~18.0.0",
7+
"react-native-scripts": "0.0.50",
88
"react-test-renderer": "16.0.0-alpha.12"
99
},
1010
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
@@ -22,6 +22,6 @@
2222
"expo": "^18.0.3",
2323
"react": "16.0.0-alpha.12",
2424
"react-native": "^0.45.1",
25-
"react-native-markdown-renderer": "^1.3.3"
25+
"react-native-markdown-renderer": "git+https://github.com/mientjan/react-native-markdown-renderer.git#feature/grouping-of-text-nodes"
2626
}
2727
}

lib/util/createToken.js

Whitespace-only changes.

lib/util/getIsTextType.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const textTypes = [
55
'a',
66
's',
77
'em',
8-
'h1',
9-
'h2',
10-
'h3',
11-
'h4',
12-
'h5',
13-
'h6',
14-
'h7',
15-
'h8',
16-
'h9',
8+
// 'h1',
9+
// 'h2',
10+
// 'h3',
11+
// 'h4',
12+
// 'h5',
13+
// 'h6',
14+
// 'h7',
15+
// 'h8',
16+
// 'h9',
1717
'br',
1818
];
1919

@@ -22,6 +22,6 @@ const textTypes = [
2222
* @param node
2323
* @return {boolean}
2424
*/
25-
function getIsTextType(type) {
25+
export default function getIsTextType(type) {
2626
return textTypes.indexOf(type) > -1;
2727
}

lib/util/groupTextTokens.js

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import getIsTextType from './getIsTextType';
2-
import Token from "./Token";
2+
import Token from './Token';
33

44
class Stack {
55
constructor() {
@@ -16,45 +16,20 @@ class Stack {
1616
export default function groupTextTokens(tokens) {
1717
const result = [];
1818

19-
if (!tokens) {
20-
return result;
21-
}
22-
23-
let currentStack = new Stack();
24-
const stacks = [];
25-
26-
for (var i = 0; i < tokens.length; i++) {
27-
const token = tokens[i];
28-
29-
if (getIsTextType(token.tag || token.type)) {
30-
if (token.nesting === 1) {
31-
currentStack.add(token);
32-
stacks.push(currentStack);
33-
currentStack = new Stack();
34-
} else if (token.nesting === -1) {
35-
currentStack.add(token);
36-
currentStack = stacks.pop();
37-
} else if (token.nesting === 0) {
38-
currentStack.add(token);
39-
}
40-
} else {
41-
if (currentStack.count > 1) {
42-
result.push(new Token('textgroup', 1));
43-
44-
while (currentStack.data.length) {
45-
result.push(currentStack.data.shift());
46-
}
47-
48-
result.push(new Token('textgroup', -1));
49-
} else if (currentStack.count === 1) {
50-
while (currentStack.data.length) {
51-
result.push(currentStack.data.shift());
52-
}
53-
}
19+
let hasGroup = false;
20+
tokens.forEach(token => {
21+
if (getIsTextType(token.tag || token.type) && !hasGroup) {
22+
hasGroup = true;
23+
result.push(new Token('textgroup', 1));
24+
}
5425

55-
result.push(token);
26+
if (!getIsTextType(token.tag || token.type) && hasGroup) {
27+
hasGroup = false;
28+
result.push(new Token('textgroup', -1));
5629
}
57-
}
30+
31+
result.push(token);
32+
});
5833

5934
return result;
6035
}

0 commit comments

Comments
 (0)