Skip to content

Commit

Permalink
Implement proper handling for "tight" lists
Browse files Browse the repository at this point in the history
In the case of a "tight" list--meaning a markdown list with no
padding newline between entries--the inner paragraph generated by
the AST parser is now automatically stripped out as expected.
  • Loading branch information
Evan Jacobs committed Jun 28, 2016
1 parent e5b1453 commit ccbfdf8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ describe('markdown-to-jsx', () => {
});

describe('lists', () => {
/* disabled pending a fix from mdast: https://github.com/wooorm/mdast/issues/104 */
xit('should handle a tight list', () => {
it('should handle a tight list', () => {
const element = render(converter([
'- xyz',
'- abc',
Expand Down
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ export default function markdownToJSX(markdown, options = {}, overrides = {}) {
);
} /* Refers to fenced blocks, need to create a pre:code nested structure */

if (ast.type === 'list' && ast.loose === false) {
ast.children = ast.children.map(item => {
if (item.children.length === 1 && item.children[0].type === 'paragraph') {
return {
...item,
children: item.children[0].children,
};
}

return item;
});
} /* tight list, remove the paragraph wrapper just inside the listItem */

if (ast.type === 'listItem') {
if (ast.checked === true || ast.checked === false) {
return (
Expand Down

0 comments on commit ccbfdf8

Please sign in to comment.