-
Notifications
You must be signed in to change notification settings - Fork 66.6k
Expand file tree
/
Copy pathcodeql-cli-transformer.ts
More file actions
49 lines (41 loc) · 1.72 KB
/
codeql-cli-transformer.ts
File metadata and controls
49 lines (41 loc) · 1.72 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
import type { Context, Page } from '@/types'
import type { PageTransformer } from './types'
import { renderContent } from '@/content-render/index'
import { loadTemplate } from '@/article-api/lib/load-template'
import { stripHtmlCommentsAndNormalizeWhitespace } from '@/article-api/lib/strip-html-comments'
/**
* Transformer for CodeQL CLI reference pages.
* Renders autogenerated CodeQL CLI documentation pages as markdown using a Liquid template.
* Sets `markdownRequested` to true in the context to ensure the page is rendered as markdown,
* bypassing the default article type check.
*/
export class CodeQLCliTransformer implements PageTransformer {
templateName = 'codeql-cli-page.template.md'
canTransform(page: Page): boolean {
return page.autogenerated === 'codeql-cli'
}
async transform(page: Page, _pathname: string, context: Context): Promise<string> {
// CodeQL CLI pages are fully generated markdown files in the repo.
// We render them with markdownRequested=true to get the markdown output.
context.markdownRequested = true
const content = await page.render(context)
const intro = page.intro ? await page.renderProp('intro', context, { textOnly: true }) : ''
// Prepare template data
const templateData: Record<string, unknown> = {
page: {
title: page.title,
intro,
},
content,
}
// Load and render template
const templateContent = loadTemplate(this.templateName)
const result = await renderContent(templateContent, {
...context,
...templateData,
markdownRequested: true,
})
// Strip HTML comments (e.g., markdownlint-disable comments) from the output
return stripHtmlCommentsAndNormalizeWhitespace(result)
}
}