@peaceroad/markdown-it-renderer-fence 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -470
- package/docs/README.md +37 -0
- package/docs/code-highlighting-design.md +321 -0
- package/docs/custom-highlight-styling-guide.md +210 -0
- package/package.json +25 -13
- package/src/custom-highlight/option-validator.js +5 -5
- package/src/custom-highlight/payload-utils.js +4 -9
- package/src/custom-highlight/{shiki-keyword-rules.js → shiki-role-rules.js} +249 -54
- package/src/custom-highlight/{shiki-keyword.js → shiki-role.js} +107 -99
- package/src/custom-highlight/shiki-theme-role.js +176 -0
- package/src/fence/line-notes.js +27 -9
- package/src/fence/render-api-constants.js +1 -1
- package/src/fence/render-api-provider.js +61 -53
- package/src/fence/render-api-renderer.js +26 -10
- package/src/fence/render-api-runtime.js +29 -10
- package/src/fence/render-api.js +20 -12
- package/src/fence/render-markup.js +34 -24
- package/src/fence/render-shared.js +150 -30
- package/src/utils/attr-utils.js +10 -0
- package/theme/_shared/rf-core.css +170 -0
- package/theme/line-notes.css +94 -0
- package/theme/line-number.css +64 -0
- package/theme/rf-basic/README.md +117 -0
- package/theme/rf-basic/api/highlightjs.css +71 -0
- package/theme/rf-basic/api/shiki.css +67 -0
- package/theme/rf-basic/base.css +5 -0
- package/theme/rf-basic/index.css +7 -0
- package/theme/rf-basic/index.js +164 -0
- package/theme/rf-basic/markup/highlightjs.css +77 -0
- package/theme/rf-basic/markup/shiki.css +11 -0
- package/theme/rf-monochrome/README.md +84 -0
- package/theme/rf-monochrome/base.css +5 -0
- package/theme/rf-monochrome/index.css +5 -0
- package/theme/rf-monochrome/index.js +71 -0
- package/theme/rf-monochrome/markup/highlightjs.css +150 -0
- package/theme/rf-monochrome/markup/shiki.css +38 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { rendererFenceShikiThemeScopeGroups } from '../../src/custom-highlight/shiki-theme-role.js'
|
|
2
|
+
|
|
3
|
+
const rfMonochromeThemeName = 'rf-monochrome'
|
|
4
|
+
const rfMonochromeShikiThemeName = rfMonochromeThemeName
|
|
5
|
+
|
|
6
|
+
const createTokenFontStyle = (scope, foreground, fontStyle) => ({
|
|
7
|
+
scope: Array.isArray(scope) ? scope.slice() : scope,
|
|
8
|
+
settings: { foreground, fontStyle },
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const rfMonochromeNormalScopeOverrides = Object.freeze([
|
|
12
|
+
'keyword.operator.or.regexp',
|
|
13
|
+
'keyword.operator.quantifier.regexp',
|
|
14
|
+
])
|
|
15
|
+
|
|
16
|
+
const rfMonochromeCommentScopeOverrides = Object.freeze([
|
|
17
|
+
'comment.block.documentation.js storage.type.class.jsdoc',
|
|
18
|
+
'comment.block.documentation.ts storage.type.class.jsdoc',
|
|
19
|
+
'comment.block.documentation.js entity.name.type.instance.jsdoc',
|
|
20
|
+
'comment.block.documentation.ts entity.name.type.instance.jsdoc',
|
|
21
|
+
'comment.block.documentation.js variable.other.jsdoc',
|
|
22
|
+
'comment.block.documentation.ts variable.other.jsdoc',
|
|
23
|
+
'comment.block.documentation.js punctuation.definition.block.tag.jsdoc',
|
|
24
|
+
'comment.block.documentation.ts punctuation.definition.block.tag.jsdoc',
|
|
25
|
+
'comment.block.documentation.js punctuation.definition.bracket.curly.begin.jsdoc',
|
|
26
|
+
'comment.block.documentation.ts punctuation.definition.bracket.curly.begin.jsdoc',
|
|
27
|
+
'comment.block.documentation.js punctuation.definition.bracket.curly.end.jsdoc',
|
|
28
|
+
'comment.block.documentation.ts punctuation.definition.bracket.curly.end.jsdoc',
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
const createRfMonochromeShikiTheme = ({
|
|
32
|
+
name = rfMonochromeShikiThemeName,
|
|
33
|
+
foreground = 'currentColor',
|
|
34
|
+
background = 'transparent',
|
|
35
|
+
commentFontStyle = 'italic',
|
|
36
|
+
structuralFontStyle = 'bold',
|
|
37
|
+
} = {}) => ({
|
|
38
|
+
name,
|
|
39
|
+
type: 'light',
|
|
40
|
+
colors: {
|
|
41
|
+
'editor.foreground': foreground,
|
|
42
|
+
'editor.background': background,
|
|
43
|
+
},
|
|
44
|
+
tokenColors: [
|
|
45
|
+
{ settings: { foreground, background } },
|
|
46
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.comment, foreground, commentFontStyle),
|
|
47
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.keyword, foreground, structuralFontStyle),
|
|
48
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.type, foreground, structuralFontStyle),
|
|
49
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.tag, foreground, structuralFontStyle),
|
|
50
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.title, foreground, ''),
|
|
51
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.string, foreground, ''),
|
|
52
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.number, foreground, ''),
|
|
53
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.literal, foreground, ''),
|
|
54
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.variable, foreground, ''),
|
|
55
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.attribute, foreground, ''),
|
|
56
|
+
createTokenFontStyle(rendererFenceShikiThemeScopeGroups.punctuation, foreground, ''),
|
|
57
|
+
createTokenFontStyle(rfMonochromeNormalScopeOverrides, foreground, ''),
|
|
58
|
+
createTokenFontStyle(rfMonochromeCommentScopeOverrides, foreground, commentFontStyle),
|
|
59
|
+
],
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const rfMonochromeShikiTheme = createRfMonochromeShikiTheme()
|
|
63
|
+
const rfMonochromeShikiThemeScopeGroups = rendererFenceShikiThemeScopeGroups
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
createRfMonochromeShikiTheme,
|
|
67
|
+
rfMonochromeShikiTheme,
|
|
68
|
+
rfMonochromeShikiThemeName,
|
|
69
|
+
rfMonochromeShikiThemeScopeGroups,
|
|
70
|
+
rfMonochromeThemeName,
|
|
71
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*! rf-monochrome highlightjs markup theme | MIT License */
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
--rf-monochrome-strong-font-weight: 700;
|
|
5
|
+
--rf-monochrome-normal-font-weight: 400;
|
|
6
|
+
--rf-monochrome-comment-font-style: italic;
|
|
7
|
+
--rf-monochrome-meta-font-style: normal;
|
|
8
|
+
--rf-monochrome-meta-font-weight: var(--rf-monochrome-normal-font-weight);
|
|
9
|
+
--rf-monochrome-doctag-font-weight: var(--rf-monochrome-normal-font-weight);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
pre {
|
|
13
|
+
--rf-monochrome-fg: var(--rf-code-fg);
|
|
14
|
+
--rf-monochrome-bg: var(--rf-code-bg);
|
|
15
|
+
color: var(--rf-monochrome-fg);
|
|
16
|
+
background: var(--rf-monochrome-bg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pre code,
|
|
20
|
+
pre samp,
|
|
21
|
+
.hljs {
|
|
22
|
+
color: var(--rf-monochrome-fg, var(--rf-code-fg));
|
|
23
|
+
background: transparent;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* `samp` represents terminal I/O. Keep the terminal surface inverted while
|
|
28
|
+
* suppressing per-token emphasis below, so command/output lines remain easy to
|
|
29
|
+
* distinguish from code.
|
|
30
|
+
*/
|
|
31
|
+
pre:has(> samp) {
|
|
32
|
+
--rf-monochrome-fg: var(--rf-samp-fg);
|
|
33
|
+
--rf-monochrome-bg: var(--rf-samp-bg);
|
|
34
|
+
color: var(--rf-monochrome-fg);
|
|
35
|
+
background: var(--rf-monochrome-bg);
|
|
36
|
+
border-color: var(--rf-samp-border);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.hljs-keyword,
|
|
40
|
+
.hljs-selector-tag,
|
|
41
|
+
.hljs-title.class_,
|
|
42
|
+
.hljs-section,
|
|
43
|
+
.hljs-name,
|
|
44
|
+
.hljs-type,
|
|
45
|
+
.hljs-strong {
|
|
46
|
+
color: var(--rf-monochrome-fg, var(--rf-code-fg));
|
|
47
|
+
font-weight: var(--rf-monochrome-strong-font-weight, 700);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.hljs-title,
|
|
51
|
+
.hljs-title.function_,
|
|
52
|
+
.hljs-built_in,
|
|
53
|
+
.hljs-function,
|
|
54
|
+
.hljs-class {
|
|
55
|
+
color: var(--rf-monochrome-fg, var(--rf-code-fg));
|
|
56
|
+
font-weight: var(--rf-monochrome-normal-font-weight, 400);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.hljs-comment,
|
|
60
|
+
.hljs-quote,
|
|
61
|
+
.hljs-emphasis {
|
|
62
|
+
color: var(--rf-monochrome-fg, var(--rf-code-fg));
|
|
63
|
+
/*
|
|
64
|
+
* Italic comments are useful in one-color Latin code samples, but CJK
|
|
65
|
+
* comments can become harder to read. Sites with many Japanese/Chinese/Korean
|
|
66
|
+
* comments can override --rf-monochrome-comment-font-style: normal.
|
|
67
|
+
*/
|
|
68
|
+
font-style: var(--rf-monochrome-comment-font-style, italic);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* CJK fonts rarely provide a true italic face. Let the inherited document or
|
|
73
|
+
* container language disable synthetic italics for comments automatically.
|
|
74
|
+
* `:lang(ja)` also matches language tags such as `ja-JP`.
|
|
75
|
+
*/
|
|
76
|
+
.hljs-comment:lang(ja),
|
|
77
|
+
.hljs-comment:lang(zh),
|
|
78
|
+
.hljs-comment:lang(ko) {
|
|
79
|
+
--rf-monochrome-comment-font-style: normal;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.hljs-meta,
|
|
83
|
+
.hljs-doctag {
|
|
84
|
+
color: var(--rf-monochrome-fg, var(--rf-code-fg));
|
|
85
|
+
font-style: var(--rf-monochrome-meta-font-style, normal);
|
|
86
|
+
font-weight: var(--rf-monochrome-meta-font-weight, 400);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.hljs-comment .hljs-doctag {
|
|
90
|
+
font-style: inherit;
|
|
91
|
+
font-weight: var(--rf-monochrome-doctag-font-weight, 400);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.hljs-comment .hljs-type,
|
|
95
|
+
.hljs-comment .hljs-variable {
|
|
96
|
+
font-style: inherit;
|
|
97
|
+
font-weight: var(--rf-monochrome-normal-font-weight, 400);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Keep terminal prompts one-color even when the color preset is loaded before
|
|
102
|
+
* this theme. The color preset intentionally gives `samp` prompts an accent
|
|
103
|
+
* color, and its selector is more specific than plain `.hljs-meta`.
|
|
104
|
+
*/
|
|
105
|
+
.hljs-meta.prompt_,
|
|
106
|
+
pre:has(> samp) .hljs-meta.prompt_ {
|
|
107
|
+
color: var(--rf-monochrome-fg, var(--rf-code-fg));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.hljs-string,
|
|
111
|
+
.hljs-regexp,
|
|
112
|
+
.hljs-number,
|
|
113
|
+
.hljs-literal,
|
|
114
|
+
.hljs-symbol,
|
|
115
|
+
.hljs-variable,
|
|
116
|
+
.hljs-template-variable,
|
|
117
|
+
.hljs-attr,
|
|
118
|
+
.hljs-attribute,
|
|
119
|
+
.hljs-selector-class,
|
|
120
|
+
.hljs-selector-id,
|
|
121
|
+
.hljs-property,
|
|
122
|
+
.hljs-params,
|
|
123
|
+
.hljs-subst,
|
|
124
|
+
.hljs-tag,
|
|
125
|
+
.hljs-punctuation,
|
|
126
|
+
.hljs-operator,
|
|
127
|
+
.hljs-bullet,
|
|
128
|
+
.hljs-link,
|
|
129
|
+
.hljs-addition,
|
|
130
|
+
.hljs-deletion {
|
|
131
|
+
color: var(--rf-monochrome-fg, var(--rf-code-fg));
|
|
132
|
+
font-style: normal;
|
|
133
|
+
font-weight: var(--rf-monochrome-normal-font-weight, 400);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.hljs-addition,
|
|
137
|
+
.hljs-deletion {
|
|
138
|
+
background: transparent;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* `samp` usually represents terminal I/O rather than source-code structure.
|
|
143
|
+
* Keep prompts and shell control words from becoming heavier than nearby
|
|
144
|
+
* commands/output; otherwise terminal snippets can look inconsistent.
|
|
145
|
+
*/
|
|
146
|
+
pre:has(> samp) [class^="hljs-"],
|
|
147
|
+
pre:has(> samp) [class*=" hljs-"] {
|
|
148
|
+
font-style: normal;
|
|
149
|
+
font-weight: var(--rf-monochrome-normal-font-weight, 400);
|
|
150
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*! rf-monochrome Shiki markup overrides | MIT License */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Shiki markup writes background/color as inline styles. The complete CSS
|
|
5
|
+
* preset maps monochrome source-code blocks to the shared code surface, while
|
|
6
|
+
* the standalone theme object can still be used as a currentColor theme.
|
|
7
|
+
*/
|
|
8
|
+
pre.rf-monochrome {
|
|
9
|
+
color: var(--rf-code-fg) !important;
|
|
10
|
+
background-color: var(--rf-code-bg) !important;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pre:has(> samp).rf-monochrome {
|
|
14
|
+
color: var(--rf-samp-fg) !important;
|
|
15
|
+
background-color: var(--rf-samp-bg) !important;
|
|
16
|
+
border-color: var(--rf-samp-border);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* Shiki also emits font-weight/font-style inline. Limit this important override
|
|
21
|
+
* to monochrome `samp` blocks so normal one-color source-code blocks can still
|
|
22
|
+
* use bold/italic as their only syntax cues.
|
|
23
|
+
*/
|
|
24
|
+
pre:has(> samp).rf-monochrome span[style] {
|
|
25
|
+
font-style: normal !important;
|
|
26
|
+
font-weight: var(--rf-monochrome-normal-font-weight, 400) !important;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* The rf-monochrome Shiki theme emits italic only for comment scopes by
|
|
31
|
+
* default. Normalize those inline styles when the inherited language is CJK;
|
|
32
|
+
* `!important` is required because Shiki writes font-style inline.
|
|
33
|
+
*/
|
|
34
|
+
pre.rf-monochrome span[style*="font-style"][style*="italic"]:lang(ja),
|
|
35
|
+
pre.rf-monochrome span[style*="font-style"][style*="italic"]:lang(zh),
|
|
36
|
+
pre.rf-monochrome span[style*="font-style"][style*="italic"]:lang(ko) {
|
|
37
|
+
font-style: normal !important;
|
|
38
|
+
}
|