-
Notifications
You must be signed in to change notification settings - Fork 68.3k
Expand file tree
/
Copy pathstrip-html-comments.ts
More file actions
105 lines (75 loc) · 2.59 KB
/
Copy pathstrip-html-comments.ts
File metadata and controls
105 lines (75 loc) · 2.59 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { describe, expect, test } from 'vitest'
import {
stripHtmlComments,
stripHtmlCommentsAndNormalizeWhitespace,
} from '@/article-api/lib/strip-html-comments'
describe('stripHtmlComments', () => {
test('removes single-line HTML comments', () => {
const input = '<!-- markdownlint-disable GHD053 -->'
const expected = ''
expect(stripHtmlComments(input)).toBe(expected)
})
test('removes multiple HTML comments', () => {
const input = '<!-- comment 1 -->\nSome content\n<!-- comment 2 -->'
const expected = 'Some content'
expect(stripHtmlComments(input)).toBe(expected)
})
test('removes inline HTML comments', () => {
const input = 'Text before <!-- comment --> text after'
const expected = 'Text before text after'
expect(stripHtmlComments(input)).toBe(expected)
})
test('preserves content without HTML comments', () => {
const input = 'Just regular markdown content'
const expected = 'Just regular markdown content'
expect(stripHtmlComments(input)).toBe(expected)
})
test('handles multiple comments on same line', () => {
const input = '<!-- comment 1 --> text <!-- comment 2 -->'
const expected = 'text'
expect(stripHtmlComments(input)).toBe(expected)
})
})
describe('stripHtmlCommentsAndNormalizeWhitespace', () => {
test('removes HTML comments and normalizes blank lines', () => {
const input = `<!-- markdownlint-disable GHD053 -->
<!-- markdownlint-disable GHD030 -->
Content here`
const expected = 'Content here'
expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected)
})
test('normalizes multiple blank lines to at most two', () => {
const input = `Line 1
Line 2`
const expected = `Line 1
Line 2`
expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected)
})
test('handles real CodeQL CLI content pattern', () => {
const input = `# database analyze
Analyze a database, producing meaningful results
<!-- markdownlint-disable GHD053 -->
<!-- markdownlint-disable GHD030 -->
<!-- Content after this section is automatically generated -->
## Synopsis
\`\`\`shell
codeql database analyze
\`\`\``
const expected = `# database analyze
Analyze a database, producing meaningful results
## Synopsis
\`\`\`shell
codeql database analyze
\`\`\``
expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected)
})
test('preserves intentional double line breaks', () => {
const input = `# Title
Paragraph 1
Paragraph 2`
const expected = `# Title
Paragraph 1
Paragraph 2`
expect(stripHtmlCommentsAndNormalizeWhitespace(input)).toBe(expected)
})
})