@miragon/slidev-validator 0.4.0 → 0.5.1
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 +23 -8
- package/bin/index.mjs +23 -1
- package/package.json +2 -1
- package/src/index.mjs +1 -1
- package/src/rules/index.mjs +26 -10
- package/src/rules/rendered/measure.mjs +1 -14
- package/src/rules/rendered/safe-area/measure.mjs +2 -0
- package/src/rules/source/no-em-dash.mjs +44 -0
- package/src/rules/source/no-emoji.mjs +45 -0
- package/src/rules/source/no-inline-font.mjs +65 -0
- package/src/rules/source/no-nested-bullets.mjs +55 -0
- package/src/rules/source/no-restyled-bullets.mjs +64 -0
- package/src/rules/rendered/no-em-dash.mjs +0 -11
- package/src/rules/rendered/no-emoji.mjs +0 -11
- package/src/rules/rendered/no-inline-font.mjs +0 -13
- package/src/rules/rendered/no-nested-bullets.mjs +0 -13
- package/src/rules/rendered/no-restyled-bullets.mjs +0 -13
package/README.md
CHANGED
|
@@ -8,10 +8,20 @@ instead of a frozen copy — and each deck can tune or scope rules without forki
|
|
|
8
8
|
It runs two kinds of checks:
|
|
9
9
|
|
|
10
10
|
- **Source rules** — static checks over the deck's Markdown and `.excalidraw.svg`
|
|
11
|
-
sources. Fast, no browser
|
|
11
|
+
sources. Fast, no browser. Most guardrails live here, including the content rules
|
|
12
|
+
(em-dashes, emoji, nested bullets, inline font/list-style): anything an author can
|
|
13
|
+
only introduce through the source is checked here, not in the browser.
|
|
12
14
|
- **Rendered rules** — measured on the live, fully-revealed slide in headless
|
|
13
|
-
Chromium (booted against a Slidev dev server).
|
|
14
|
-
|
|
15
|
+
Chromium (booted against a Slidev dev server). Reserved for what the source truly
|
|
16
|
+
cannot show: real layout geometry (`element-overflow`, `overlay-safe-area`) and
|
|
17
|
+
colours resolved through the CSS cascade (`heading-black`, `card-white`). These
|
|
18
|
+
four require the server; every other guardrail runs without it.
|
|
19
|
+
|
|
20
|
+
The content rules moved from rendered to source with no loss of author-facing
|
|
21
|
+
coverage: Slidev does not enable the markdown-it `typographer` (no `---` → `—`) and
|
|
22
|
+
HTML entities are banned at source, so the source text matches the rendered text.
|
|
23
|
+
The source scans deliberately do not police the fixed toolkit's own internals — that
|
|
24
|
+
is the toolkit's test suite's job.
|
|
15
25
|
|
|
16
26
|
## Install
|
|
17
27
|
|
|
@@ -44,9 +54,14 @@ slidev-validator --config <path> # use a specific config file
|
|
|
44
54
|
slidev-validator --max-warnings 0 # fail if there are any warnings
|
|
45
55
|
slidev-validator init # write a starter slidev-validator.config.mjs
|
|
46
56
|
slidev-validator migrate # adopt the validator in an existing deck
|
|
57
|
+
slidev-validator rules # list every rule id, type, category, default severity
|
|
58
|
+
slidev-validator rules --format json # the same catalog, machine-readable
|
|
47
59
|
slidev-validator --version # print validator + resolved toolkit versions
|
|
48
60
|
```
|
|
49
61
|
|
|
62
|
+
`rules` prints the catalog of stable rule ids you configure (`off` | `warn` |
|
|
63
|
+
`error`, overrides, exceptions) — the same ids listed under [Rules](#rules) below.
|
|
64
|
+
|
|
50
65
|
Exit code is non-zero on any **error**-severity violation, an **expired exception**,
|
|
51
66
|
a **config error**, or warnings above `--max-warnings`.
|
|
52
67
|
|
|
@@ -116,16 +131,16 @@ config, so a report — and a CI log — is self-describing.
|
|
|
116
131
|
| `no-raw-html` | source | required | error |
|
|
117
132
|
| `no-html-entities` | source | required | error |
|
|
118
133
|
| `content-heading` | source | required | error |
|
|
134
|
+
| `no-em-dash` | source | required | error |
|
|
135
|
+
| `no-emoji` | source | required | error |
|
|
136
|
+
| `no-nested-bullets` | source | recommended | warn |
|
|
137
|
+
| `no-inline-font` | source | recommended | error |
|
|
138
|
+
| `no-restyled-bullets` | source | recommended | error |
|
|
119
139
|
| `excalidraw-committed-light` | source | recommended | error |
|
|
120
140
|
| `excalidraw-built-transparent` | source | recommended | warn |
|
|
121
141
|
| `element-overflow` | rendered | recommended | error |
|
|
122
|
-
| `no-em-dash` | rendered | required | error |
|
|
123
|
-
| `no-emoji` | rendered | required | error |
|
|
124
142
|
| `heading-black` | rendered | required | error |
|
|
125
143
|
| `card-white` | rendered | required | error |
|
|
126
|
-
| `no-inline-font` | rendered | recommended | error |
|
|
127
|
-
| `no-restyled-bullets` | rendered | recommended | error |
|
|
128
|
-
| `no-nested-bullets` | rendered | recommended | warn |
|
|
129
144
|
| `overlay-safe-area` | rendered | required | error |
|
|
130
145
|
|
|
131
146
|
`content-heading` has a per-slide opt-out (`allowMultilineHeading: true` in the
|
package/bin/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* slidev-validator --rendered also boot Slidev + Chromium and run rendered rules
|
|
7
7
|
* slidev-validator init write a starter slidev-validator.config.mjs
|
|
8
8
|
* slidev-validator migrate adopt the validator in an existing deck (config + scripts)
|
|
9
|
+
* slidev-validator rules list every rule id, type, category, and default severity
|
|
9
10
|
*
|
|
10
11
|
* Flags: --pages "4-6", --port 3030, --format json, --config <path>,
|
|
11
12
|
* --max-warnings <n>, -v/--version, -h/--help.
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
18
19
|
import { join } from 'node:path'
|
|
19
20
|
import { parseArgs } from 'node:util'
|
|
20
|
-
import { validate, ConfigError, selfInfo, resolvedToolkitVersion } from '../src/index.mjs'
|
|
21
|
+
import { validate, ConfigError, selfInfo, resolvedToolkitVersion, ruleCatalog } from '../src/index.mjs'
|
|
21
22
|
import { formatText, toJson } from '../src/report.mjs'
|
|
22
23
|
|
|
23
24
|
const STARTER_CONFIG = `// Miragon Slidev validator config. See @miragon/slidev-validator.
|
|
@@ -44,6 +45,7 @@ Commands:
|
|
|
44
45
|
(default) run the validator over ./deck (source rules)
|
|
45
46
|
init write a starter slidev-validator.config.mjs
|
|
46
47
|
migrate adopt the validator in an existing deck (config + scripts)
|
|
48
|
+
rules list every rule id, type, category, and default severity
|
|
47
49
|
|
|
48
50
|
Options:
|
|
49
51
|
--rendered also run the rendered (browser) checks
|
|
@@ -122,6 +124,25 @@ function cmdMigrate() {
|
|
|
122
124
|
return 0
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
/** List the rule catalog so authors can discover the ids they configure. */
|
|
128
|
+
function cmdRules(values) {
|
|
129
|
+
const catalog = ruleCatalog()
|
|
130
|
+
if (values.format === 'json') {
|
|
131
|
+
console.log(JSON.stringify(catalog, null, 2))
|
|
132
|
+
return 0
|
|
133
|
+
}
|
|
134
|
+
const idW = Math.max(...catalog.map((r) => r.id.length), 'ID'.length)
|
|
135
|
+
const typeW = Math.max(...catalog.map((r) => r.type.length), 'TYPE'.length)
|
|
136
|
+
const catW = Math.max(...catalog.map((r) => r.category.length), 'CATEGORY'.length)
|
|
137
|
+
const sevW = Math.max(...catalog.map((r) => r.default.length), 'DEFAULT'.length)
|
|
138
|
+
const row = (id, type, cat, sev, title) => ` ${id.padEnd(idW)} ${type.padEnd(typeW)} ${cat.padEnd(catW)} ${sev.padEnd(sevW)} ${title}`
|
|
139
|
+
console.log(`${catalog.length} rules — configure any by id in slidev-validator.config.mjs (off | warn | error):\n`)
|
|
140
|
+
console.log(row('ID', 'TYPE', 'CATEGORY', 'DEFAULT', 'DESCRIPTION'))
|
|
141
|
+
for (const r of catalog) console.log(row(r.id, r.type, r.category, r.default, r.title))
|
|
142
|
+
console.log('\n[required] rules cannot be lowered below error in `rules`; suppress them deliberately via an `exceptions` entry.')
|
|
143
|
+
return 0
|
|
144
|
+
}
|
|
145
|
+
|
|
125
146
|
async function cmdRun(values) {
|
|
126
147
|
try {
|
|
127
148
|
const { results, summary, meta } = await validate({
|
|
@@ -162,6 +183,7 @@ async function main() {
|
|
|
162
183
|
}
|
|
163
184
|
if (command === 'init') return cmdInit()
|
|
164
185
|
if (command === 'migrate') return cmdMigrate()
|
|
186
|
+
if (command === 'rules') return cmdRules(values)
|
|
165
187
|
if (command && command !== 'run') {
|
|
166
188
|
console.error(`Unknown command: ${command}\n`)
|
|
167
189
|
console.log(USAGE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miragon/slidev-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Miragon Slidev deck validator: a configurable design-system linter (stable rule IDs, off/warn/error severities, extends/overrides/exceptions) shipped as a versioned CLI so central guardrail improvements reach decks over npm instead of a frozen copy.",
|
|
6
6
|
"keywords": [
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@slidev/parser": "52.18.0",
|
|
37
|
+
"markdown-it": "14.2.0",
|
|
37
38
|
"playwright-chromium": "1.62.1"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
package/src/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { slideSourceFiles, excalidrawSvgFiles } from './helpers.mjs'
|
|
|
15
15
|
import { selfInfo, resolvedToolkitVersion, compat } from './versions.mjs'
|
|
16
16
|
|
|
17
17
|
export { loadConfig, ConfigError } from './config.mjs'
|
|
18
|
-
export { allRules, sourceRules, renderedRules, ruleById, knownRuleIds } from './rules/index.mjs'
|
|
18
|
+
export { allRules, sourceRules, renderedRules, ruleById, knownRuleIds, ruleCatalog } from './rules/index.mjs'
|
|
19
19
|
export { formatText, toJson } from './report.mjs'
|
|
20
20
|
export { selfInfo, resolvedToolkitVersion, compat } from './versions.mjs'
|
|
21
21
|
|
package/src/rules/index.mjs
CHANGED
|
@@ -12,17 +12,17 @@ import { sanctionedLayout } from './source/sanctioned-layout.mjs'
|
|
|
12
12
|
import { noRawHtml } from './source/no-raw-html.mjs'
|
|
13
13
|
import { noHtmlEntities } from './source/no-html-entities.mjs'
|
|
14
14
|
import { contentHeading } from './source/content-heading.mjs'
|
|
15
|
+
import { noEmDash } from './source/no-em-dash.mjs'
|
|
16
|
+
import { noEmoji } from './source/no-emoji.mjs'
|
|
17
|
+
import { noNestedBullets } from './source/no-nested-bullets.mjs'
|
|
18
|
+
import { noInlineFont } from './source/no-inline-font.mjs'
|
|
19
|
+
import { noRestyledBullets } from './source/no-restyled-bullets.mjs'
|
|
15
20
|
import { excalidrawCommittedLight } from './source/excalidraw-committed-light.mjs'
|
|
16
21
|
import { excalidrawBuiltTransparent } from './source/excalidraw-built-transparent.mjs'
|
|
17
22
|
|
|
18
23
|
import { elementOverflow } from './rendered/element-overflow.mjs'
|
|
19
|
-
import { noEmDash } from './rendered/no-em-dash.mjs'
|
|
20
|
-
import { noEmoji } from './rendered/no-emoji.mjs'
|
|
21
24
|
import { headingBlack } from './rendered/heading-black.mjs'
|
|
22
25
|
import { cardWhite } from './rendered/card-white.mjs'
|
|
23
|
-
import { noInlineFont } from './rendered/no-inline-font.mjs'
|
|
24
|
-
import { noRestyledBullets } from './rendered/no-restyled-bullets.mjs'
|
|
25
|
-
import { noNestedBullets } from './rendered/no-nested-bullets.mjs'
|
|
26
26
|
import { overlaySafeArea } from './rendered/overlay-safe-area.mjs'
|
|
27
27
|
|
|
28
28
|
/** Every rule, source then rendered, in report order. */
|
|
@@ -31,16 +31,16 @@ export const allRules = [
|
|
|
31
31
|
noRawHtml,
|
|
32
32
|
noHtmlEntities,
|
|
33
33
|
contentHeading,
|
|
34
|
+
noEmDash,
|
|
35
|
+
noEmoji,
|
|
36
|
+
noNestedBullets,
|
|
37
|
+
noInlineFont,
|
|
38
|
+
noRestyledBullets,
|
|
34
39
|
excalidrawCommittedLight,
|
|
35
40
|
excalidrawBuiltTransparent,
|
|
36
41
|
elementOverflow,
|
|
37
|
-
noEmDash,
|
|
38
|
-
noEmoji,
|
|
39
42
|
headingBlack,
|
|
40
43
|
cardWhite,
|
|
41
|
-
noInlineFont,
|
|
42
|
-
noRestyledBullets,
|
|
43
|
-
noNestedBullets,
|
|
44
44
|
overlaySafeArea,
|
|
45
45
|
]
|
|
46
46
|
|
|
@@ -56,3 +56,19 @@ export function ruleById(id) {
|
|
|
56
56
|
export function knownRuleIds() {
|
|
57
57
|
return new Set(allRules.map((r) => r.id))
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The rule catalog: every rule as a plain, report-ordered row for tooling, docs,
|
|
62
|
+
* and the `slidev-validator rules` command. Lets deck authors discover the stable
|
|
63
|
+
* ids they configure (off/warn/error, overrides, exceptions) without reading the
|
|
64
|
+
* source. Stable shape: { id, type, category, default, title }.
|
|
65
|
+
*/
|
|
66
|
+
export function ruleCatalog() {
|
|
67
|
+
return allRules.map((r) => ({
|
|
68
|
+
id: r.id,
|
|
69
|
+
type: r.type,
|
|
70
|
+
category: r.meta.category,
|
|
71
|
+
default: r.meta.default,
|
|
72
|
+
title: r.title,
|
|
73
|
+
}))
|
|
74
|
+
}
|
|
@@ -41,12 +41,6 @@ export function measureSlide(n) {
|
|
|
41
41
|
right = Math.round(Math.max(right, layout.scrollWidth))
|
|
42
42
|
contentBottom = Math.round(contentBottom)
|
|
43
43
|
|
|
44
|
-
// --- Text rules ---
|
|
45
|
-
const text = layout.innerText || ''
|
|
46
|
-
const emDash = text.includes('—')
|
|
47
|
-
const pictographic = '\\p{Extended' + '_Pictographic}'
|
|
48
|
-
const emoji = new RegExp(pictographic, 'u').test(text)
|
|
49
|
-
|
|
50
44
|
// --- Headings must be black, never blue ---
|
|
51
45
|
const blueHeads = [...layout.querySelectorAll('h1, h2')].filter((h) => isBlue(rgb(getComputedStyle(h).color))).length
|
|
52
46
|
|
|
@@ -65,12 +59,5 @@ export function measureSlide(n) {
|
|
|
65
59
|
return false
|
|
66
60
|
}).length
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
const inlineFonts = all.filter((el) => el.style && el.style.fontFamily && !el.closest('svg, pre, code, button')).length
|
|
70
|
-
|
|
71
|
-
// --- Bullets: layout owns the marker; no per-slide list-style override; max 1 nesting level ---
|
|
72
|
-
const listOverrides = [...layout.querySelectorAll('ul, li')].filter((el) => el.style && (el.style.listStyle || el.style.listStyleType)).length
|
|
73
|
-
const nestedLists = layout.querySelectorAll('ul ul, ul ol, ol ul, ol ol').length
|
|
74
|
-
|
|
75
|
-
return { cw, ch, right, contentBottom, emDash, emoji, blueHeads, badCards, inlineFonts, listOverrides, nestedLists }
|
|
62
|
+
return { cw, ch, right, contentBottom, blueHeads, badCards }
|
|
76
63
|
}
|
|
@@ -72,6 +72,8 @@ export function measureSafeArea({ n, overlaySel, canvas }) {
|
|
|
72
72
|
const cs = getComputedStyle(el)
|
|
73
73
|
if (cs.visibility === 'hidden' || cs.display === 'none' || parseFloat(cs.opacity) < 0.05) continue
|
|
74
74
|
if (cs.position === 'fixed') continue // the overlays themselves / other chrome
|
|
75
|
+
if (cs.pointerEvents === 'none') continue
|
|
76
|
+
if (el.getAttribute('aria-hidden') === 'true' || el.closest('[aria-hidden="true"]')) continue
|
|
75
77
|
const c = toCanvas(r)
|
|
76
78
|
const nearBottom = c.bottom > canvas.height - 80
|
|
77
79
|
const nearTop = c.top < 80
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { toRel } from '../../helpers.mjs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* No em-dashes in slide content. Use commas, periods, parentheses, or colons.
|
|
6
|
+
*
|
|
7
|
+
* This is a pure source scan and it is deckungsgleich with the old rendered check:
|
|
8
|
+
* Slidev does NOT enable the markdown-it `typographer` (no `---` → `—` conversion),
|
|
9
|
+
* and HTML entities are already banned at source (`no-html-entities`), so a literal
|
|
10
|
+
* `—` in the source is the only way one can reach the DOM. Speaker-note comments
|
|
11
|
+
* (`<!-- … -->`) are exempt: notes may be in another language and use em-dashes.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Replace `<!-- … -->` comments with blanks, preserving newlines so line numbers stay true. */
|
|
15
|
+
const blankComments = (text) => text.replace(/<!--[\s\S]*?-->/g, (m) => m.replace(/[^\n]/g, ' '))
|
|
16
|
+
|
|
17
|
+
/** Pure core (fixture-free, testable): 1-based line numbers of every em-dash outside speaker notes. */
|
|
18
|
+
export function findEmDashes(source) {
|
|
19
|
+
const lines = []
|
|
20
|
+
blankComments(source).split('\n').forEach((line, i) => {
|
|
21
|
+
if (line.includes('—')) lines.push(i + 1)
|
|
22
|
+
})
|
|
23
|
+
return lines
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const noEmDash = {
|
|
27
|
+
id: 'no-em-dash',
|
|
28
|
+
type: 'source',
|
|
29
|
+
title: 'no em-dashes',
|
|
30
|
+
message: 'Slide content must not contain an em-dash (—)',
|
|
31
|
+
meta: { category: 'required', default: 'error' },
|
|
32
|
+
check({ sourceFiles = [] } = {}) {
|
|
33
|
+
const offenders = []
|
|
34
|
+
for (const file of sourceFiles) {
|
|
35
|
+
const rel = toRel(file)
|
|
36
|
+
const src = readFileSync(file, 'utf8')
|
|
37
|
+
const byLine = src.split('\n')
|
|
38
|
+
for (const line of findEmDashes(src)) {
|
|
39
|
+
offenders.push({ file: rel, line, message: `contains an em-dash (—). Use commas, periods, parentheses, or colons. → ${byLine[line - 1].trim()}` })
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return offenders
|
|
43
|
+
},
|
|
44
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { toRel } from '../../helpers.mjs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* No emoji icons in slide content. Use inline SVG or Iconify (`i-*`) classes.
|
|
6
|
+
*
|
|
7
|
+
* Pure source scan, deckungsgleich with the old rendered check: an emoji can only
|
|
8
|
+
* reach the DOM as a literal code point in the source (HTML entities are banned by
|
|
9
|
+
* `no-html-entities`). Same `\p{Extended_Pictographic}` test as before. Speaker-note
|
|
10
|
+
* comments are exempt.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const EMOJI = /\p{Extended_Pictographic}/u
|
|
14
|
+
|
|
15
|
+
/** Replace `<!-- … -->` comments with blanks, preserving newlines so line numbers stay true. */
|
|
16
|
+
const blankComments = (text) => text.replace(/<!--[\s\S]*?-->/g, (m) => m.replace(/[^\n]/g, ' '))
|
|
17
|
+
|
|
18
|
+
/** Pure core (fixture-free, testable): 1-based line numbers of every emoji outside speaker notes. */
|
|
19
|
+
export function findEmojis(source) {
|
|
20
|
+
const lines = []
|
|
21
|
+
blankComments(source).split('\n').forEach((line, i) => {
|
|
22
|
+
if (EMOJI.test(line)) lines.push(i + 1)
|
|
23
|
+
})
|
|
24
|
+
return lines
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const noEmoji = {
|
|
28
|
+
id: 'no-emoji',
|
|
29
|
+
type: 'source',
|
|
30
|
+
title: 'no emoji icons',
|
|
31
|
+
message: 'Slide content must not contain emoji',
|
|
32
|
+
meta: { category: 'required', default: 'error' },
|
|
33
|
+
check({ sourceFiles = [] } = {}) {
|
|
34
|
+
const offenders = []
|
|
35
|
+
for (const file of sourceFiles) {
|
|
36
|
+
const rel = toRel(file)
|
|
37
|
+
const src = readFileSync(file, 'utf8')
|
|
38
|
+
const byLine = src.split('\n')
|
|
39
|
+
for (const line of findEmojis(src)) {
|
|
40
|
+
offenders.push({ file: rel, line, message: `contains an emoji. Use inline SVG or Iconify (i-*) icon classes instead. → ${byLine[line - 1].trim()}` })
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return offenders
|
|
44
|
+
},
|
|
45
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { toRel } from '../../helpers.mjs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Layouts own typography: no inline `font-family` in author slide content.
|
|
6
|
+
*
|
|
7
|
+
* The only way an author can set an inline font is a `style=` / `:style=` attribute
|
|
8
|
+
* on a component (the sanctioned escape hatch is spacing/layout only) or raw HTML
|
|
9
|
+
* (already banned by `no-raw-html`). Both are visible in the source, so this is a
|
|
10
|
+
* pure source scan. Fenced code, comments, and inline code are blanked first so an
|
|
11
|
+
* illustrative `style="font-family: …"` inside a code sample is not flagged.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Replace a matched region with blanks, preserving newlines so line numbers stay true. */
|
|
15
|
+
const blank = (text, re) => text.replace(re, (m) => m.replace(/[^\n]/g, ' '))
|
|
16
|
+
|
|
17
|
+
/** Blank fenced code blocks, speaker-note comments, and inline code spans. */
|
|
18
|
+
function sanitize(src) {
|
|
19
|
+
src = blank(src, /```[\s\S]*?```/g)
|
|
20
|
+
src = blank(src, /<!--[\s\S]*?-->/g)
|
|
21
|
+
src = blank(src, /`[^`\n]*`/g)
|
|
22
|
+
return src
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* An inline `style` / `:style` attribute, single- or double-quoted; group 2 is its
|
|
27
|
+
* value. The look-behind keeps `data-style` / `x-style` fragments from matching.
|
|
28
|
+
*/
|
|
29
|
+
const STYLE_ATTR = /(?<![-\w]):?style\s*=\s*(['"])([\s\S]*?)\1/gi
|
|
30
|
+
|
|
31
|
+
/** Pure core (fixture-free, testable): 1-based line numbers of inline `font-family` in author content. */
|
|
32
|
+
export function findInlineFonts(source) {
|
|
33
|
+
const lines = []
|
|
34
|
+
sanitize(source).split('\n').forEach((line, i) => {
|
|
35
|
+
STYLE_ATTR.lastIndex = 0
|
|
36
|
+
let m
|
|
37
|
+
while ((m = STYLE_ATTR.exec(line))) {
|
|
38
|
+
if (/font-family/i.test(m[2])) {
|
|
39
|
+
lines.push(i + 1)
|
|
40
|
+
break
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
return lines
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const noInlineFont = {
|
|
48
|
+
id: 'no-inline-font',
|
|
49
|
+
type: 'source',
|
|
50
|
+
title: 'typography not overridden',
|
|
51
|
+
message: 'Slide content must not set font-family inline',
|
|
52
|
+
meta: { category: 'recommended', default: 'error' },
|
|
53
|
+
check({ sourceFiles = [] } = {}) {
|
|
54
|
+
const offenders = []
|
|
55
|
+
for (const file of sourceFiles) {
|
|
56
|
+
const rel = toRel(file)
|
|
57
|
+
const src = readFileSync(file, 'utf8')
|
|
58
|
+
const byLine = src.split('\n')
|
|
59
|
+
for (const line of findInlineFonts(src)) {
|
|
60
|
+
offenders.push({ file: rel, line, message: `sets font-family inline. Let the layout own typography. → ${byLine[line - 1].trim()}` })
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return offenders
|
|
64
|
+
},
|
|
65
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { parseSync } from '@slidev/parser'
|
|
3
|
+
import MarkdownIt from 'markdown-it'
|
|
4
|
+
import { toRel } from '../../helpers.mjs'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Keep bullet lists to one level. Split the slide instead of sub-bullets.
|
|
8
|
+
*
|
|
9
|
+
* Nesting is authored in the markdown body (indented list items), so it is fully
|
|
10
|
+
* visible in the source — no browser needed. Each slide body is tokenised with
|
|
11
|
+
* markdown-it (Node, no server) and a `*_list_open` that fires while already inside
|
|
12
|
+
* a list is a nested level, mirroring the old rendered selector `ul ul, ul ol, …`.
|
|
13
|
+
* Only the body is scanned (frontmatter YAML lists are component props, not bullets).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const md = new MarkdownIt({ html: true })
|
|
17
|
+
|
|
18
|
+
/** Pure core (fixture-free, testable): how many list levels open while already inside a list. */
|
|
19
|
+
export function countNestedLists(content) {
|
|
20
|
+
if (typeof content !== 'string' || !content.trim()) return 0
|
|
21
|
+
let depth = 0
|
|
22
|
+
let nested = 0
|
|
23
|
+
for (const t of md.parse(content, {})) {
|
|
24
|
+
if (/(?:bullet|ordered)_list_open/.test(t.type)) {
|
|
25
|
+
depth++
|
|
26
|
+
if (depth >= 2) nested++
|
|
27
|
+
} else if (/(?:bullet|ordered)_list_close/.test(t.type)) {
|
|
28
|
+
depth--
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return nested
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const noNestedBullets = {
|
|
35
|
+
id: 'no-nested-bullets',
|
|
36
|
+
type: 'source',
|
|
37
|
+
title: 'no nested bullets',
|
|
38
|
+
message: 'Bullet lists must stay at one level',
|
|
39
|
+
meta: { category: 'recommended', default: 'warn' },
|
|
40
|
+
check({ sourceFiles = [] } = {}) {
|
|
41
|
+
const offenders = []
|
|
42
|
+
for (const file of sourceFiles) {
|
|
43
|
+
const rel = toRel(file)
|
|
44
|
+
const parsed = parseSync(readFileSync(file, 'utf8'), file)
|
|
45
|
+
for (const s of parsed.slides) {
|
|
46
|
+
if (s.frontmatter?.src) continue // import stub — the body lives in the imported file
|
|
47
|
+
const n = countNestedLists(s.content)
|
|
48
|
+
if (n > 0) {
|
|
49
|
+
offenders.push({ file: rel, line: (s.start ?? 0) + 1, message: `${n} nested list(s). Keep to one level; split the slide instead of sub-bullets.` })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return offenders
|
|
54
|
+
},
|
|
55
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { toRel } from '../../helpers.mjs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Bullets: the layout owns the marker; no per-slide inline list-style override.
|
|
6
|
+
*
|
|
7
|
+
* Like `no-inline-font`, an author can only override bullet styling through a
|
|
8
|
+
* `style=` / `:style=` attribute or raw HTML (banned by `no-raw-html`), both visible
|
|
9
|
+
* in the source. Pure source scan. Fenced code, comments, and inline code are
|
|
10
|
+
* blanked first so an illustrative `style="list-style: …"` in a sample is not flagged.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Replace a matched region with blanks, preserving newlines so line numbers stay true. */
|
|
14
|
+
const blank = (text, re) => text.replace(re, (m) => m.replace(/[^\n]/g, ' '))
|
|
15
|
+
|
|
16
|
+
/** Blank fenced code blocks, speaker-note comments, and inline code spans. */
|
|
17
|
+
function sanitize(src) {
|
|
18
|
+
src = blank(src, /```[\s\S]*?```/g)
|
|
19
|
+
src = blank(src, /<!--[\s\S]*?-->/g)
|
|
20
|
+
src = blank(src, /`[^`\n]*`/g)
|
|
21
|
+
return src
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An inline `style` / `:style` attribute, single- or double-quoted; group 2 is its
|
|
26
|
+
* value. The look-behind keeps `data-style` / `x-style` fragments from matching.
|
|
27
|
+
*/
|
|
28
|
+
const STYLE_ATTR = /(?<![-\w]):?style\s*=\s*(['"])([\s\S]*?)\1/gi
|
|
29
|
+
|
|
30
|
+
/** Pure core (fixture-free, testable): 1-based line numbers of inline `list-style` in author content. */
|
|
31
|
+
export function findRestyledBullets(source) {
|
|
32
|
+
const lines = []
|
|
33
|
+
sanitize(source).split('\n').forEach((line, i) => {
|
|
34
|
+
STYLE_ATTR.lastIndex = 0
|
|
35
|
+
let m
|
|
36
|
+
while ((m = STYLE_ATTR.exec(line))) {
|
|
37
|
+
if (/list-style/i.test(m[2])) {
|
|
38
|
+
lines.push(i + 1)
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
return lines
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const noRestyledBullets = {
|
|
47
|
+
id: 'no-restyled-bullets',
|
|
48
|
+
type: 'source',
|
|
49
|
+
title: 'bullets not restyled',
|
|
50
|
+
message: 'Slide content must not override bullet styling inline',
|
|
51
|
+
meta: { category: 'recommended', default: 'error' },
|
|
52
|
+
check({ sourceFiles = [] } = {}) {
|
|
53
|
+
const offenders = []
|
|
54
|
+
for (const file of sourceFiles) {
|
|
55
|
+
const rel = toRel(file)
|
|
56
|
+
const src = readFileSync(file, 'utf8')
|
|
57
|
+
const byLine = src.split('\n')
|
|
58
|
+
for (const line of findRestyledBullets(src)) {
|
|
59
|
+
offenders.push({ file: rel, line, message: `overrides bullet styling inline. Use plain <ul>/<li>; the layout provides the marker. → ${byLine[line - 1].trim()}` })
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return offenders
|
|
63
|
+
},
|
|
64
|
+
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** No em-dashes in rendered slide content. Use commas, periods, parentheses, or colons. */
|
|
2
|
-
export const noEmDash = {
|
|
3
|
-
id: 'no-em-dash',
|
|
4
|
-
type: 'rendered',
|
|
5
|
-
title: 'no em-dashes',
|
|
6
|
-
message: 'Slide content must not contain an em-dash (—)',
|
|
7
|
-
meta: { category: 'required', default: 'error' },
|
|
8
|
-
evaluate(m, ctx) {
|
|
9
|
-
return m.emDash ? [{ file: ctx.file, slide: ctx.slide, message: 'contains an em-dash (—). Use commas, periods, parentheses, or colons.' }] : []
|
|
10
|
-
},
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** No emoji icons in rendered slide content. Use inline SVG or Iconify (i-*) classes. */
|
|
2
|
-
export const noEmoji = {
|
|
3
|
-
id: 'no-emoji',
|
|
4
|
-
type: 'rendered',
|
|
5
|
-
title: 'no emoji icons',
|
|
6
|
-
message: 'Slide content must not contain emoji',
|
|
7
|
-
meta: { category: 'required', default: 'error' },
|
|
8
|
-
evaluate(m, ctx) {
|
|
9
|
-
return m.emoji ? [{ file: ctx.file, slide: ctx.slide, message: 'contains an emoji. Use inline SVG or Iconify (i-*) icon classes instead.' }] : []
|
|
10
|
-
},
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Layouts own typography: no inline font-family in author slide content. */
|
|
2
|
-
export const noInlineFont = {
|
|
3
|
-
id: 'no-inline-font',
|
|
4
|
-
type: 'rendered',
|
|
5
|
-
title: 'typography not overridden',
|
|
6
|
-
message: 'Slide content must not set font-family inline',
|
|
7
|
-
meta: { category: 'recommended', default: 'error' },
|
|
8
|
-
evaluate(m, ctx) {
|
|
9
|
-
return m.inlineFonts > 0
|
|
10
|
-
? [{ file: ctx.file, slide: ctx.slide, message: `${m.inlineFonts} element(s) set font-family inline. Let the layout own typography.` }]
|
|
11
|
-
: []
|
|
12
|
-
},
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Keep bullet lists to one level. Split the slide instead of sub-bullets. */
|
|
2
|
-
export const noNestedBullets = {
|
|
3
|
-
id: 'no-nested-bullets',
|
|
4
|
-
type: 'rendered',
|
|
5
|
-
title: 'no nested bullets',
|
|
6
|
-
message: 'Bullet lists must stay at one level',
|
|
7
|
-
meta: { category: 'recommended', default: 'warn' },
|
|
8
|
-
evaluate(m, ctx) {
|
|
9
|
-
return m.nestedLists > 0
|
|
10
|
-
? [{ file: ctx.file, slide: ctx.slide, message: `${m.nestedLists} nested list(s). Keep to one level; split the slide instead of sub-bullets.` }]
|
|
11
|
-
: []
|
|
12
|
-
},
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Bullets: the layout owns the marker; no per-slide inline list-style override. */
|
|
2
|
-
export const noRestyledBullets = {
|
|
3
|
-
id: 'no-restyled-bullets',
|
|
4
|
-
type: 'rendered',
|
|
5
|
-
title: 'bullets not restyled',
|
|
6
|
-
message: 'Slide content must not override bullet styling inline',
|
|
7
|
-
meta: { category: 'recommended', default: 'error' },
|
|
8
|
-
evaluate(m, ctx) {
|
|
9
|
-
return m.listOverrides > 0
|
|
10
|
-
? [{ file: ctx.file, slide: ctx.slide, message: `${m.listOverrides} list element(s) override bullet styling inline. Use plain <ul>/<li>; the layout provides the marker.` }]
|
|
11
|
-
: []
|
|
12
|
-
},
|
|
13
|
-
}
|