mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-11-17 07:49:05 +01:00
support pdf-only
and web-only
blocks
This commit is contained in:
parent
f0ce98063b
commit
0bdda2ec59
5 changed files with 47 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
import { unified } from 'unified';
|
||||
import { visit } from 'unist-util-visit';
|
||||
import { remove } from 'unist-util-remove';
|
||||
import rehypeParse from 'rehype-parse';
|
||||
import rehypeSlug from 'rehype-slug';
|
||||
import rehypeKatex from 'rehype-katex';
|
||||
|
@ -11,6 +12,10 @@ import { rehypeCodesplit } from './codesplit.mjs';
|
|||
export function parseContent(html) {
|
||||
const replaceMedia = () => (tree) => {
|
||||
visit(tree, { tagName: 'div' }, (node) => {
|
||||
if (node.properties.dataType === 'pdf-only') {
|
||||
remove(tree, node);
|
||||
}
|
||||
|
||||
if (
|
||||
node.properties.dataType === 'embed' &&
|
||||
node.properties.dataExamplePath
|
||||
|
|
|
@ -277,6 +277,10 @@ section {
|
|||
clear: both;
|
||||
}
|
||||
|
||||
div[data-type="web-only"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// 9. Grouping content / Images
|
||||
figure {
|
||||
|
|
25
package-lock.json
generated
25
package-lock.json
generated
|
@ -44,6 +44,7 @@
|
|||
"rehype-slug": "^5.0.1",
|
||||
"tailwindcss": "^3.1.6",
|
||||
"unified": "^10.1.2",
|
||||
"unist-util-remove": "^3.1.0",
|
||||
"unist-util-visit": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -22260,6 +22261,20 @@
|
|||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/unist-util-remove": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-remove/-/unist-util-remove-3.1.0.tgz",
|
||||
"integrity": "sha512-rO/sIghl13eN8irs5OBN2a4RC10MsJdiePCfwrvnzGtgIbHcDXr2REr0qi9F2r/CIb1r9FyyFmcMRIGs+EyUFw==",
|
||||
"dependencies": {
|
||||
"@types/unist": "^2.0.0",
|
||||
"unist-util-is": "^5.0.0",
|
||||
"unist-util-visit-parents": "^5.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/unist-util-remove-position": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-remove-position/-/unist-util-remove-position-4.0.1.tgz",
|
||||
|
@ -40035,6 +40050,16 @@
|
|||
"resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-5.1.1.tgz",
|
||||
"integrity": "sha512-F5CZ68eYzuSvJjGhCLPL3cYx45IxkqXSetCcRgUXtbcm50X2L9oOWQlfUfDdAf+6Pd27YDblBfdtmsThXmwpbQ=="
|
||||
},
|
||||
"unist-util-remove": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-remove/-/unist-util-remove-3.1.0.tgz",
|
||||
"integrity": "sha512-rO/sIghl13eN8irs5OBN2a4RC10MsJdiePCfwrvnzGtgIbHcDXr2REr0qi9F2r/CIb1r9FyyFmcMRIGs+EyUFw==",
|
||||
"requires": {
|
||||
"@types/unist": "^2.0.0",
|
||||
"unist-util-is": "^5.0.0",
|
||||
"unist-util-visit-parents": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"unist-util-remove-position": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-remove-position/-/unist-util-remove-position-4.0.1.tgz",
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
"rehype-slug": "^5.0.1",
|
||||
"tailwindcss": "^3.1.6",
|
||||
"unified": "^10.1.2",
|
||||
"unist-util-remove": "^3.1.0",
|
||||
"unist-util-visit": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -50,6 +50,18 @@ function transformCallout(block) {
|
|||
h('h3', plainTextTitle),
|
||||
]);
|
||||
|
||||
// Web-only content
|
||||
case '🌐':
|
||||
return h('div', { dataType: 'web-only' }, [
|
||||
h('p', block.callout.rich_text.map(transformRichText)),
|
||||
]);
|
||||
|
||||
// PDF-only content
|
||||
case '📖':
|
||||
return h('div', { dataType: 'pdf-only' }, [
|
||||
h('p', block.callout.rich_text.map(transformRichText)),
|
||||
]);
|
||||
|
||||
default:
|
||||
console.warn('missing handler for callout:', block.callout.icon.emoji);
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue