Skip to content

Commit

Permalink
Merge pull request #104 from abirchall/style_lists
Browse files Browse the repository at this point in the history
This is good, sorry it took so long to merge!
  • Loading branch information
iamacup authored Oct 16, 2020
2 parents 40fd9fc + d43173f commit f91ecb8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import tokensToAST from './util/tokensToAST';
import {stringToTokens} from './util/stringToTokens';
import {cleanupTokens} from './util/cleanupTokens';
import groupTextTokens from './util/groupTextTokens';
import omitListItemParagraph from './util/omitListItemParagraph';

/**
*
Expand All @@ -18,6 +19,7 @@ export default function parser(source, renderer, markdownIt) {
let tokens = stringToTokens(source, markdownIt);
tokens = cleanupTokens(tokens);
tokens = groupTextTokens(tokens);
tokens = omitListItemParagraph(tokens);

const astTree = tokensToAST(tokens);

Expand Down
41 changes: 0 additions & 41 deletions src/lib/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,6 @@ export const styles = {
bullet_list_icon: {
marginLeft: 10,
marginRight: 10,
...Platform.select({
android: {
marginTop: 5,
},
ios: {
marginTop: 0,
},
default: {
marginTop: 0,
},
}),
...Platform.select({
ios: {
lineHeight: 36,
},
android: {
lineHeight: 30,
},
default: {
lineHeight: 36,
},
}),
},
// @pseudo class, does not have a unique render rule
bullet_list_content: {
Expand All @@ -100,25 +78,6 @@ export const styles = {
ordered_list_icon: {
marginLeft: 10,
marginRight: 10,
...Platform.select({
android: {
marginTop: 4,
},
default: {
marginTop: 0,
},
}),
...Platform.select({
ios: {
lineHeight: 36,
},
android: {
lineHeight: 30,
},
default: {
lineHeight: 36,
},
}),
},
// @pseudo class, does not have a unique render rule
ordered_list_content: {
Expand Down
29 changes: 29 additions & 0 deletions src/lib/util/omitListItemParagraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default function omitListItemParagraph(tokens) {
// used to ensure that we remove the correct ending paragraph token
let depth = null;
return tokens.filter((token, index) => {
// update depth if we've already removed a starting paragraph token
if (depth !== null) {
depth = depth + token.nesting;
}

// check for a list_item token followed by paragraph token (to remove)
if (token.type === 'list_item' && token.nesting === 1 && depth === null) {
const next = index + 1 in tokens ? tokens[index + 1] : null;
if (next && next.type === 'paragraph' && next.nesting === 1) {
depth = 0;
return true;
}
} else if (token.type === 'paragraph') {
if (token.nesting === 1 && depth === 1) {
// remove the paragraph token immediately after the list_item token
return false;
} else if (token.nesting === -1 && depth === 0) {
// remove the ending paragraph token; reset depth
depth = null;
return false;
}
}
return true;
});
}

0 comments on commit f91ecb8

Please sign in to comment.