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

Function htmlFormatter

src/cli/formatters/html.ts:17–74  ·  view source on GitHub ↗
(formatter)

Source from the content-addressed store, hash-verified

15 .replace(/'/g, ''')
16
17const htmlFormatter: FormatterCallback = function (formatter) {
18 formatter.on('end', (event) => {
19 let fileContent = '<!DOCTYPE html>\n'
20 fileContent += '<html lang="en">\n'
21 fileContent += '<head>\n'
22 fileContent += '<meta charset="utf-8">\n'
23 fileContent +=
24 '<meta name="viewport" content="width=device-width, initial-scale=1">\n'
25 fileContent += '<title>HTML Hint Violation Report</title>\n'
26 fileContent += '<meta name="generator" content="HTMLHint">\n'
27 fileContent += '<meta name="color-scheme" content="light dark">\n'
28 fileContent +=
29 '<meta name="description" content="HTMLHint Violation Report">\n'
30 fileContent +=
31 '<style>body{font-family:Arial,helvetica,sans-serif;} footer{margin-top:20px;text-align:center;opacity:0.5;}</style>\n'
32 fileContent +=
33 '<style>table{border-collapse:collapse;width:100%;} th,td{border:1px solid rgb(128,128,128,0.4);padding:8px;text-align:left;} th{background-color:rgb(128,128,128,0.2);}</style>\n'
34 fileContent +=
35 '<style>@media (prefers-color-scheme: dark) {body {background-color:#333;color-scheme: dark;color:#fff;}}</style>\n'
36 fileContent += '</head>\n'
37 fileContent += '<body>\n'
38 fileContent += '<h1>Violation Report</h1>\n'
39 fileContent += '<main>\n'
40 fileContent += '<table>\n'
41 fileContent +=
42 '<tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr>\n'
43
44 let totalMessages = 0
45 for (const { messages } of event.arrAllMessages) {
46 totalMessages += messages.length
47 }
48
49 let messageCount = 0
50 for (const { file, messages } of event.arrAllMessages) {
51 messages.forEach(({ line, message }) => {
52 messageCount++
53 const isLastMessage = messageCount === totalMessages
54
55 if (isLastMessage) {
56 // Last message - add the table closing tag right after it (no newline)
57 fileContent += `<tr><td>${messageCount}</td><td>${file}</td><td>${line}</td><td>${formatMessage(message)}</td></tr></table>\n`
58 } else {
59 fileContent += `<tr><td>${messageCount}</td><td>${file}</td><td>${line}</td><td>${formatMessage(message)}</td></tr>\n`
60 }
61 })
62 }
63
64 // Table closing tag is now included with the last message
65 // fileContent += '</table>\n'
66 fileContent +=
67 '<footer><small>Generated by <a href="https://htmlhint.com" target="_blank" rel="noopener">HTMLHint</a></small></footer>\n'
68 fileContent += '</main>\n'
69 fileContent += '</body>\n'
70 fileContent += '</html>'
71 console.log(fileContent)
72 writeFileSync('report.html', fileContent)
73 })
74}

Callers

nothing calls this directly

Calls 2

formatMessageFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected