mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-11-17 07:49:05 +01:00
modify callout blocks dom
This commit is contained in:
parent
20a90eca56
commit
709b811ead
2 changed files with 51 additions and 1 deletions
|
@ -7,7 +7,8 @@
|
|||
"magicbook-codesplit",
|
||||
"magicbook-katex",
|
||||
"magicbook/plugins/relative-link.js",
|
||||
"magicbook/plugins/screenshot.js"
|
||||
"magicbook/plugins/screenshot.js",
|
||||
"magicbook/plugins/callout.js"
|
||||
],
|
||||
"destination": "build",
|
||||
"files": [
|
||||
|
|
49
magicbook/plugins/callout.js
Normal file
49
magicbook/plugins/callout.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
const through = require('through2');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const Plugin = function (registry) {
|
||||
registry.after(
|
||||
'markdown:convert',
|
||||
'callout:remove-web-only',
|
||||
this.removeWebOnlyBlocks,
|
||||
);
|
||||
|
||||
registry.after('markdown:convert', 'callout:add-heading-icons', this.addHeadingIcons);
|
||||
};
|
||||
|
||||
Plugin.prototype = {
|
||||
removeWebOnlyBlocks: function (config, stream, extras, callback) {
|
||||
stream = stream.pipe(
|
||||
through.obj(function (file, _, cb) {
|
||||
file.$el = file.$el || cheerio.load(file.contents.toString());
|
||||
|
||||
file.$el('div[data-type="web-only"]').remove();
|
||||
|
||||
cb(null, file);
|
||||
}),
|
||||
);
|
||||
|
||||
callback(null, config, stream, extras);
|
||||
},
|
||||
|
||||
addHeadingIcons: function(config, stream, extras, callback) {
|
||||
const icon = '😀';
|
||||
|
||||
stream = stream.pipe(
|
||||
through.obj(function (file, _, cb) {
|
||||
file.$el = file.$el || cheerio.load(file.contents.toString());
|
||||
|
||||
file.$el('div[data-type="exercise"] > h3').each((_, element) => {
|
||||
const currentHeading = file.$el(element);
|
||||
currentHeading.html(`${icon} ${currentHeading.text()}`);
|
||||
});
|
||||
|
||||
cb(null, file);
|
||||
}),
|
||||
);
|
||||
|
||||
callback(null, config, stream, extras);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Plugin;
|
Loading…
Reference in a new issue