@troshab/slidev-theme-troshab 0.1.12 → 0.1.14
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/CLAUDE.md +1 -0
- package/package.json +1 -1
- package/setup/mermaid.ts +12 -0
- package/setup/preparser.ts +71 -0
package/CLAUDE.md
CHANGED
|
@@ -181,6 +181,7 @@ Theme automatically applies matching colors via `setup/mermaid.ts` (reads CSS va
|
|
|
181
181
|
2. **Limit nodes** — max 6-8 for flowcharts
|
|
182
182
|
3. **No titles in xychart** — causes overflow
|
|
183
183
|
4. **Use abbreviations** — `LB` not `Load Balancer`
|
|
184
|
+
5. **Labels render as SVG `<text>`** — `setup/mermaid.ts` sets `htmlLabels: false`, fixing the foreignObject width=0 off-centre bug in Slidev's shadow-DOM render. Single- and multi-line node labels both centre correctly (`<br/>` for line breaks). No special handling needed.
|
|
184
185
|
|
|
185
186
|
### Limits by type
|
|
186
187
|
|
package/package.json
CHANGED
package/setup/mermaid.ts
CHANGED
|
@@ -60,6 +60,18 @@ export default defineMermaidSetup(() => {
|
|
|
60
60
|
return {
|
|
61
61
|
theme: 'base',
|
|
62
62
|
darkMode: isDark,
|
|
63
|
+
|
|
64
|
+
// Labels as native SVG <text> (centred via text-anchor) instead of
|
|
65
|
+
// htmlLabels (<p> in <foreignObject>). Slidev renders Mermaid into a SHADOW
|
|
66
|
+
// DOM where the foreignObject label is measured as width=0, and
|
|
67
|
+
// MermaidChart.vue's unlockSvg sets overflow:visible — so the text spilled
|
|
68
|
+
// out of the zero-width box ~15px right of centre. SVG <text> centres
|
|
69
|
+
// geometrically and is immune to that. Must be TOP-LEVEL (per-diagram
|
|
70
|
+
// `flowchart.htmlLabels` is deprecated/ignored). Single- AND multi-line
|
|
71
|
+
// labels both centre correctly (verified: offset 0px, symmetric gaps on
|
|
72
|
+
// each line) — the old mermaid#1177 tspan left-align no longer reproduces.
|
|
73
|
+
htmlLabels: false,
|
|
74
|
+
|
|
63
75
|
themeVariables: {
|
|
64
76
|
// Background
|
|
65
77
|
background: colors.bg,
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render markdown inside block-level theme components.
|
|
3
|
+
*
|
|
4
|
+
* markdown-it (and MDC) treat text flush against a custom block tag
|
|
5
|
+
* (<Callout>, <Card>, <StyledList>, ...) as a raw HTML block, so inline
|
|
6
|
+
* markdown inside it (**bold**, `code`, [links]) is NOT parsed. CommonMark
|
|
7
|
+
* needs a blank line after the opening tag and before the closing tag for the
|
|
8
|
+
* inner content to be parsed as markdown.
|
|
9
|
+
*
|
|
10
|
+
* This normalizes ANY PascalCase component used as a block (tag alone on its
|
|
11
|
+
* own line). Inline usage (<UPN>x</UPN> inside a sentence) is left untouched,
|
|
12
|
+
* and fenced code regions are skipped so component examples in code blocks are
|
|
13
|
+
* not rewritten.
|
|
14
|
+
*
|
|
15
|
+
* LOADING: Slidev loads preparser setups from the project and from ADDONS only,
|
|
16
|
+
* never from a theme root. So a deck must list this theme as an addon to pick
|
|
17
|
+
* this up:
|
|
18
|
+
*
|
|
19
|
+
* ---
|
|
20
|
+
* theme: "@troshab/slidev-theme-troshab"
|
|
21
|
+
* addons: ["@troshab/slidev-theme-troshab"]
|
|
22
|
+
* ---
|
|
23
|
+
*
|
|
24
|
+
* (The deck-scaffolding skill emits both lines.) Until a deck does that, an
|
|
25
|
+
* identical copy can live in the deck's own setup/preparser.ts.
|
|
26
|
+
*
|
|
27
|
+
* definePreparserSetup is an identity helper; we export the raw function to
|
|
28
|
+
* avoid importing @slidev/types (which jiti's CJS interop can choke on at the
|
|
29
|
+
* preparser stage).
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const OPEN_ALONE = /^\s*<[A-Z][A-Za-z0-9]*\b[^>]*?>\s*$/
|
|
33
|
+
const CLOSE_ALONE = /^\s*<\/[A-Z][A-Za-z0-9]*>\s*$/
|
|
34
|
+
const SELF_CLOSE = /\/>\s*$/
|
|
35
|
+
const FENCE = /^\s*(```|~~~)/
|
|
36
|
+
|
|
37
|
+
export default () => [
|
|
38
|
+
{
|
|
39
|
+
name: 'troshab:md-in-components',
|
|
40
|
+
transformRawLines(lines: string[]) {
|
|
41
|
+
// Mark fenced code regions so we never rewrite inside them.
|
|
42
|
+
const inCode: boolean[] = new Array(lines.length).fill(false)
|
|
43
|
+
let fence = false
|
|
44
|
+
for (let i = 0; i < lines.length; i++) {
|
|
45
|
+
if (FENCE.test(lines[i])) {
|
|
46
|
+
inCode[i] = true // the fence line itself
|
|
47
|
+
fence = !fence
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
inCode[i] = fence
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Insert blank lines bottom-up so splices don't shift unprocessed indices.
|
|
54
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
55
|
+
if (inCode[i]) continue
|
|
56
|
+
const line = lines[i]
|
|
57
|
+
|
|
58
|
+
if (CLOSE_ALONE.test(line)) {
|
|
59
|
+
if (i > 0 && lines[i - 1].trim() !== '') lines.splice(i, 0, '')
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (OPEN_ALONE.test(line) && !SELF_CLOSE.test(line)) {
|
|
64
|
+
if (i + 1 < lines.length && lines[i + 1].trim() !== '') {
|
|
65
|
+
lines.splice(i + 1, 0, '')
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
]
|