Skip to content

Commit b0843f4

Browse files
committed
fixed issue where you could not set a general fontSize fo all copy. #17
1 parent a7cd2ec commit b0843f4

File tree

8 files changed

+46
-31
lines changed

8 files changed

+46
-31
lines changed

example/src/copyAllCheckboxPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const markdownText = `
2-
# Syntax Support
2+
# Syntax __Support__
33
44
__Advertisement :)__
55

example/src/customMarkdownStyle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const customMarkdownStyle = StyleSheet.create({
1717
},
1818
heading: {},
1919
heading1: {
20-
fontSize: 32,
20+
fontSize: 50,
2121
backgroundColor: "#FFCC00"
2222
},
23-
text: {},
23+
text: {fontSize: 80,},
2424
strikethrough: {
2525
textDecorationLine: 'line-through',
2626
color: '#FF0000'

src/lib/parser.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,8 @@ import tokensToAST from "./util/tokensToAST";
44
import removeInlineTokens from "./util/removeInlineTokens";
55
import groupTextTokens from "./util/groupTextTokens";
66
import getTokenTypeByToken from "./util/getTokenTypeByToken";
7-
8-
export function stringToTokens(source, markdownIt) {
9-
let result = [];
10-
try {
11-
result = markdownIt.parse(source, {});
12-
} catch (err) {
13-
console.warn(err);
14-
}
15-
16-
result.forEach(token => (token.type = getTokenTypeByToken(token)));
17-
18-
return result;
19-
}
7+
import { stringToTokens } from "./util/stringToTokens";
8+
import { cleanupTokens } from "./util/cleanupTokens";
209

2110
/**
2211
*
@@ -26,10 +15,7 @@ export function stringToTokens(source, markdownIt) {
2615
* @return {View}
2716
*/
2817
export function parser(source, renderer, markdownIt) {
29-
const tokens = groupTextTokens(
30-
removeInlineTokens(stringToTokens(source, markdownIt))
18+
return renderer(
19+
tokensToAST(cleanupTokens(stringToTokens(source, markdownIt)))
3120
);
32-
const asttree = tokensToAST(tokens);
33-
34-
return renderer(asttree);
3521
}

src/lib/renderRules.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ const renderRules = {
1717
},
1818

1919
textgroup: (node, children, parent, styles) => {
20-
return <Text key={node.key}>{children}</Text>;
20+
return <Text key={node.key} style={styles.text}>{children}</Text>;
2121
},
2222
inline: (node, children, parent, styles) => {
2323
return <Text key={node.key}>{children}</Text>;
2424
},
2525

2626
text: (node, children, parent, styles) => {
2727
return (
28-
<Text key={node.key} style={styles.text}>
28+
<Text key={node.key}>
2929
{node.content}
3030
</Text>
3131
);

src/lib/util/cleanupTokens.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import getTokenTypeByToken from "./getTokenTypeByToken";
2+
import groupTextTokens from "./groupTextTokens";
3+
import removeInlineTokens from "./removeInlineTokens";
4+
5+
export function cleanupTokens(tokens){
6+
7+
tokens = removeInlineTokens(tokens);
8+
tokens.forEach(token => token.type = getTokenTypeByToken(token))
9+
10+
tokens = groupTextTokens(tokens);
11+
12+
console.log('tokens', tokens);
13+
14+
return tokens;
15+
}

src/lib/util/getIsTextType.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const textTypes = [
99
'a',
1010
's',
1111
'em',
12-
// 'h1',
13-
// 'h2',
14-
// 'h3',
15-
// 'h4',
16-
// 'h5',
17-
// 'h6',
12+
'heading1',
13+
'heading2',
14+
'heading3',
15+
'heading4',
16+
'heading5',
17+
'heading6',
1818
// 'h7',
1919
// 'h8',
2020
// 'h9',

src/lib/util/groupTextTokens.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ class Stack {
1616
export default function groupTextTokens(tokens) {
1717
const result = [];
1818

19+
console.log(tokens);
20+
1921
let hasGroup = false;
2022
tokens.forEach(token => {
21-
if (getIsTextType(token.tag || token.type) && !hasGroup) {
23+
if (getIsTextType(token.type) && !hasGroup) {
2224
hasGroup = true;
2325
result.push(new Token('textgroup', 1));
2426
}
2527

26-
if (!getIsTextType(token.tag || token.type) && hasGroup) {
28+
if (!getIsTextType(token.type) && hasGroup) {
2729
hasGroup = false;
2830
result.push(new Token('textgroup', -1));
2931
}

src/lib/util/stringToTokens.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function stringToTokens(source, markdownIt) {
2+
let result = [];
3+
try {
4+
result = markdownIt.parse(source, {});
5+
} catch (err) {
6+
console.warn(err);
7+
}
8+
9+
console.log('result', result);
10+
11+
return result;
12+
}

0 commit comments

Comments
 (0)