MCPcopy
hub / github.com/htmlhint/HTMLHint / getRuleMarkdown

Function getRuleMarkdown

src/cli/formatters/sarif.ts:20–109  ·  view source on GitHub ↗

* Get rule documentation markdown content * @param ruleId The ID of the rule * @returns Markdown content for the rule or undefined if not found

(ruleId: string)

Source from the content-addressed store, hash-verified

18 * @returns Markdown content for the rule or undefined if not found
19 */
20function getRuleMarkdown(ruleId: string): string | undefined {
21 // Try multiple possible locations for the rule documentation
22 const possiblePaths = [
23 // Standard path from process.cwd()
24 path.join(
25 process.cwd(),
26 'website',
27 'src',
28 'content',
29 'docs',
30 'rules',
31 `${ruleId}.mdx`
32 ),
33 // Absolute path based on module location
34 path.join(
35 path.dirname(require.resolve('../../../package.json')),
36 'website',
37 'src',
38 'content',
39 'docs',
40 'rules',
41 `${ruleId}.mdx`
42 ),
43 // Handle case where we're in the website directory
44 path.join(
45 process.cwd(),
46 'src',
47 'content',
48 'docs',
49 'rules',
50 `${ruleId}.mdx`
51 ),
52 ]
53
54 // Try each path until we find one that exists
55 for (const mdxFilePath of possiblePaths) {
56 try {
57 if (existsSync(mdxFilePath)) {
58 const content = readFileSync(mdxFilePath, 'utf8')
59
60 // Extract content after frontmatter
61 const frontmatterEnd = content.indexOf('---', 4) + 3
62 if (frontmatterEnd > 3) {
63 // Skip the frontmatter and extract the actual markdown content
64 const markdown = content.substring(frontmatterEnd).trim()
65
66 // Process the content line by line for better control
67 const lines = markdown.split(/\r?\n/)
68
69 // Remove the import line
70 const filteredLines = lines.filter(
71 (line) =>
72 !line.includes(
73 "import { Badge } from '@astrojs/starlight/components';"
74 )
75 )
76
77 // Join the lines back together

Callers 1

sarifFormatterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected