-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmdc.config.ts
More file actions
76 lines (74 loc) · 2.98 KB
/
Copy pathmdc.config.ts
File metadata and controls
76 lines (74 loc) · 2.98 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize'
// This file is loaded as a real ES module by @nuxtjs/mdc (not JSON-serialised),
// so RegExp values in the rehype-sanitize schema survive intact.
//
// The rehype-sanitize options in nuxt.config.ts are passed through
// JSON.stringify when generating .nuxt/mdc-imports.mjs, which silently
// converts every RegExp to {} - causing the iframe src allow-list to
// accept nothing and stripping all YouTube embeds. Defining the plugin
// here bypasses that serialisation step entirely.
export default {
rehype: {
plugins: {
'rehype-sanitize': {
instance: rehypeSanitize,
options: {
...defaultSchema,
tagNames: [
...(defaultSchema.tagNames ?? []),
'iframe',
// Uploaded media embeds (processVideoDirectives / processAudioDirectives).
// <audio> is mapped to the AudioPlayer component by MarkdownRendererInner.
'video',
'audio',
// KaTeX emits <svg>, <path>, <line>, <use> for some output modes
'svg',
'path',
'line',
'use',
],
attributes: {
...defaultSchema.attributes,
// span: allow class (KaTeX uses many class names) and style
// restricted to color only (processColorTags emits inline color).
'span': [
...(defaultSchema.attributes?.span ?? []),
'className',
'style',
'ariaHidden',
],
// div: allow class and style for KaTeX block wrappers
'div': [
...(defaultSchema.attributes?.div ?? []),
'className',
'style',
],
// iframe: locked to YouTube nocookie embeds only.
// The RegExp here is the reason this config must live in
// mdc.config.ts rather than nuxt.config.ts - JSON.stringify
// turns RegExp into {} which makes every src value fail the check.
'iframe': [
['src', /^https:\/\/www\.youtube-nocookie\.com\/embed\//],
'width',
'height',
'frameborder',
'allow',
'allowfullscreen',
'className',
],
// Uploaded media embeds: keep src (and the rendering hints) intact.
'video': ['src', 'controls', 'className'],
'audio': ['src', 'controls', 'className'],
// SVG elements for KaTeX
'svg': ['xmlns', 'width', 'height', 'viewBox', 'className', 'style', 'ariaHidden', 'focusable'],
'path': ['d', 'stroke', 'strokeWidth', 'fill', 'className'],
'line': ['x1', 'y1', 'x2', 'y2', 'stroke', 'strokeWidth', 'className'],
'use': [['href', /^#/], ['xlinkHref', /^#/], 'className'],
// Allow class on any element for KaTeX and highlight.js
'*': ['className'],
},
},
},
},
},
}