Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
fix(embeds): remove dataEmbed nodes from mdast after detection
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Mar 10, 2020
1 parent 53c6d5c commit 0ab4dba
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 66 deletions.
169 changes: 107 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"fs-extra": "^8.1.0",
"github-slugger": "^1.2.1",
"js-yaml": "^3.13.1",
"jsdom": "16.2.0",
"jsdom": "^16.2.1",
"lodash": "^4.17.15",
"mdast-util-to-hast": "^8.0.0",
"mdast-util-to-string": "^1.0.6",
Expand All @@ -76,6 +76,7 @@
"strip-markdown": "^3.1.0",
"unified": "^8.3.2",
"unist-util-map": "^2.0.0",
"unist-util-remove": "^2.0.0",
"unist-util-select": "^3.0.0",
"unist-util-visit": "^2.0.0",
"uri-js": "^4.2.2",
Expand Down
6 changes: 3 additions & 3 deletions src/html/data-sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* governing permissions and limitations under the License.
*/
const { selectAll } = require('unist-util-select');
const remove = require('unist-util-remove');

/**
* Copied from 'unist-util-map' and promisified.
Expand Down Expand Up @@ -39,11 +40,9 @@ async function data({ content: { mdast } }, { downloader }) {
if (node.type === 'dataEmbed') {
const task = downloader.getTaskById(`dataEmbed:${node.url}`);
const downloadeddata = await task;
console.log('task data', downloadeddata);
// TODO: better error handling
const json = await downloadeddata.json();
console.log('data', json);
section.meta.embedData = json;
node.type = 'delete';
}
return node;
});
Expand All @@ -56,6 +55,7 @@ async function data({ content: { mdast } }, { downloader }) {
// extract data from the root node (in case there are no sections)
await extractData(mdast);
console.log('found data sections', dataSections.length);
remove(mdast, 'dataEmbed');
}

module.exports = data;

0 comments on commit 0ab4dba

Please sign in to comment.