|
| 1 | +// @ts-ignore - markdownlint-rule-helpers doesn't provide TypeScript declarations |
1 | 2 | import { addError, filterTokens } from 'markdownlint-rule-helpers' |
2 | 3 |
|
3 | | -import { getFrontmatter } from '../helpers/utils' |
| 4 | +import { getFrontmatter } from '@/content-linter/lib/helpers/utils' |
| 5 | +import type { RuleParams, RuleErrorCallback, MarkdownToken } from '@/content-linter/types' |
| 6 | + |
| 7 | +interface Frontmatter { |
| 8 | + layout?: string |
| 9 | + [key: string]: any |
| 10 | +} |
4 | 11 |
|
5 | 12 | export const codeAnnotations = { |
6 | 13 | names: ['GHD007', 'code-annotations'], |
7 | 14 | description: |
8 | 15 | 'Code annotations defined in Markdown must contain a specific layout frontmatter property', |
9 | 16 | tags: ['code', 'feature', 'annotate', 'frontmatter'], |
10 | | - parser: 'markdownit', |
11 | | - function: (params, onError) => { |
12 | | - filterTokens(params, 'fence', (token) => { |
13 | | - if (!token.info.includes('annotate')) return |
14 | | - const fm = getFrontmatter(params.frontMatterLines) |
| 17 | + parser: 'markdownit' as const, |
| 18 | + function: (params: RuleParams, onError: RuleErrorCallback) => { |
| 19 | + filterTokens(params, 'fence', (token: MarkdownToken) => { |
| 20 | + if (!token.info?.includes('annotate')) return |
| 21 | + const fm: Frontmatter | null = getFrontmatter(params.frontMatterLines) |
15 | 22 | if (!fm || (fm.layout && fm.layout === 'inline')) return |
16 | 23 |
|
17 | 24 | addError( |
|
0 commit comments