Skip to content

Commit

Permalink
Update to remark 4.x
Browse files Browse the repository at this point in the history
Remark removed the `tableHeader` definition, so had to make a slight
modification to table handling logic to properly convert the first
"row" back into the header so it would be emitted with the proper
semantics.
  • Loading branch information
Evan Jacobs committed Mar 21, 2016
1 parent ca7271b commit cfa4946
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export default function markdownToJSX(markdown, options = {}, overrides = {}) {
case 'heading':
return `h${node.depth}`;

case 'horizontalRule':
return 'hr';

case 'html':
return 'div';

Expand Down Expand Up @@ -63,6 +60,9 @@ export default function markdownToJSX(markdown, options = {}, overrides = {}) {
case 'tableCell':
return 'td';

case 'thematicBreak':
return 'hr';

case 'definition':
case 'footnoteDefinition':
case 'yaml':
Expand All @@ -86,29 +86,29 @@ export default function markdownToJSX(markdown, options = {}, overrides = {}) {
...props,
title: ast.title,
alt: ast.alt,
src: ast.src,
src: ast.url,
};

case 'imageReference':
return {
...props,
title: definitions[ast.identifier].title,
alt: ast.alt,
src: definitions[ast.identifier].link,
src: definitions[ast.identifier].url,
};

case 'link':
return {
...props,
title: ast.title,
href: ast.href,
href: ast.url,
};

case 'linkReference':
return {
...props,
title: definitions[ast.identifier].title,
href: definitions[ast.identifier].link,
href: definitions[ast.identifier].url,
};

case 'list':
Expand Down Expand Up @@ -189,8 +189,10 @@ export default function markdownToJSX(markdown, options = {}, overrides = {}) {
if (ast.type === 'table') {
const tbody = {type: 'tbody', children: []};

ast.children = ast.children.reduce((children, child) => {
if (child.type === 'tableHeader') {
ast.children = ast.children.reduce((children, child, index) => {
if (index === 0) {
/* manually marking the first row as tableHeader since that was removed in remark@4.x; it's important semantically. */
child.type = 'tableHeader';
children.unshift(
seekCellsAndAlignThemIfNecessary(child, ast.align)
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"react-dom": "^0.14.0"
},
"dependencies": {
"remark": "^3.0.0"
"remark": "^4.0.0"
},
"peerDependencies": {
"react": "^0.14.0"
Expand Down

0 comments on commit cfa4946

Please sign in to comment.