-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremark-image-light.js
More file actions
37 lines (34 loc) · 1002 Bytes
/
remark-image-light.js
File metadata and controls
37 lines (34 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// @ts-nocheck
/**
* Remark plugin that transforms :::image-light container directives into
* a <div class="doc-image-light"> wrapper.
*
* Usage in MDX:
*
* :::image-light
* 
* :::
*
* The wrapper applies a light background to images in dark mode AND light mode,
* which is useful for diagrams with transparent backgrounds.
*
* Requires `remark-directive` to be registered before this plugin.
*/
const { visit } = require('unist-util-visit');
/** @type {import('unified').Plugin} */
function remarkImageLight() {
return (tree) => {
visit(tree, (node) => {
if (node.type === 'containerDirective' && node.name === 'image-light') {
const data = node.data || (node.data = {});
// Render as a <div> with the CSS class
data.hName = 'div';
data.hProperties = {
className: ['doc-image-light'],
...(node.attributes || {}),
};
}
});
};
}
module.exports = remarkImageLight;