Skip to content

Commit f91ecb8

Browse files
authored
Merge pull request #104 from abirchall/style_lists
This is good, sorry it took so long to merge!
2 parents 40fd9fc + d43173f commit f91ecb8

File tree

3 files changed

+31
-41
lines changed

3 files changed

+31
-41
lines changed

src/lib/parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import tokensToAST from './util/tokensToAST';
22
import {stringToTokens} from './util/stringToTokens';
33
import {cleanupTokens} from './util/cleanupTokens';
44
import groupTextTokens from './util/groupTextTokens';
5+
import omitListItemParagraph from './util/omitListItemParagraph';
56

67
/**
78
*
@@ -18,6 +19,7 @@ export default function parser(source, renderer, markdownIt) {
1819
let tokens = stringToTokens(source, markdownIt);
1920
tokens = cleanupTokens(tokens);
2021
tokens = groupTextTokens(tokens);
22+
tokens = omitListItemParagraph(tokens);
2123

2224
const astTree = tokensToAST(tokens);
2325

src/lib/styles.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,6 @@ export const styles = {
6868
bullet_list_icon: {
6969
marginLeft: 10,
7070
marginRight: 10,
71-
...Platform.select({
72-
android: {
73-
marginTop: 5,
74-
},
75-
ios: {
76-
marginTop: 0,
77-
},
78-
default: {
79-
marginTop: 0,
80-
},
81-
}),
82-
...Platform.select({
83-
ios: {
84-
lineHeight: 36,
85-
},
86-
android: {
87-
lineHeight: 30,
88-
},
89-
default: {
90-
lineHeight: 36,
91-
},
92-
}),
9371
},
9472
// @pseudo class, does not have a unique render rule
9573
bullet_list_content: {
@@ -100,25 +78,6 @@ export const styles = {
10078
ordered_list_icon: {
10179
marginLeft: 10,
10280
marginRight: 10,
103-
...Platform.select({
104-
android: {
105-
marginTop: 4,
106-
},
107-
default: {
108-
marginTop: 0,
109-
},
110-
}),
111-
...Platform.select({
112-
ios: {
113-
lineHeight: 36,
114-
},
115-
android: {
116-
lineHeight: 30,
117-
},
118-
default: {
119-
lineHeight: 36,
120-
},
121-
}),
12281
},
12382
// @pseudo class, does not have a unique render rule
12483
ordered_list_content: {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export default function omitListItemParagraph(tokens) {
2+
// used to ensure that we remove the correct ending paragraph token
3+
let depth = null;
4+
return tokens.filter((token, index) => {
5+
// update depth if we've already removed a starting paragraph token
6+
if (depth !== null) {
7+
depth = depth + token.nesting;
8+
}
9+
10+
// check for a list_item token followed by paragraph token (to remove)
11+
if (token.type === 'list_item' && token.nesting === 1 && depth === null) {
12+
const next = index + 1 in tokens ? tokens[index + 1] : null;
13+
if (next && next.type === 'paragraph' && next.nesting === 1) {
14+
depth = 0;
15+
return true;
16+
}
17+
} else if (token.type === 'paragraph') {
18+
if (token.nesting === 1 && depth === 1) {
19+
// remove the paragraph token immediately after the list_item token
20+
return false;
21+
} else if (token.nesting === -1 && depth === 0) {
22+
// remove the ending paragraph token; reset depth
23+
depth = null;
24+
return false;
25+
}
26+
}
27+
return true;
28+
});
29+
}

0 commit comments

Comments
 (0)