Skip to content

Commit

Permalink
remark headers
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwhall committed Jun 21, 2018
1 parent 0258e87 commit b5fa924
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ When automatically warming up an IP, SendGrid limits the amount of email sent th
Automated IP warmup hourly send schedule
{% endanchor %}


<table class="table table-striped table-bordered">
<tr>
<td>
Expand Down
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
'gatsby-remark-copy-linked-files',
// 'gatsby-remark-autolink-headers',
'sendgrid-remark-headers',
'sendgrid-remark-tables',
],
},
},
Expand Down
31 changes: 31 additions & 0 deletions plugins/sendgrid-remark-tables/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const visit = require('unist-util-visit');
const cheerio = require('cheerio');

module.exports = ({ markdownAST }) => {
visit(markdownAST, 'html', (node) => {
const $ = cheerio.load(node.value);
const table = $('table');

if (table.length) {
const rawHTML = `
<div class="table-wrap">
${table}
</div>
`;

node.data = {
hChildren: [{ type: 'raw', value: rawHTML }],
// Set type to unknown so mdast-util-to-hast will treat this node as a
// div not an iframe — it gets quite confused otherwise.
}; node.type = 'unknown';

// Also apparently, for html node types, you have to delete the value
// in order for mdast-util-to-hast to use hChildren. If even if
// you change the node type to unknown...
delete node.value;
}
});

return markdownAST;
};

1 change: 1 addition & 0 deletions plugins/sendgrid-remark-tables/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit b5fa924

Please sign in to comment.