UNPKG

sarif-explorer

Version:

A modern SARIF report viewer that converts SARIF files into interactive, shareable HTML reports with file explorer, collapsible issue lists, and code snippets.

55 lines (53 loc) 1.55 kB
import { readFileSync } from 'fs'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); /** * Generate the complete HTML document with embedded styles and scripts */ export function generateHtmlDocument(bodyHtml) { try { const stylesPath = join(__dirname, 'styles.css'); const scriptsPath = join(__dirname, 'scripts.js'); // Read the CSS and JS files const styles = readFileSync(stylesPath, 'utf8'); const scripts = readFileSync(scriptsPath, 'utf8'); return `<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>SARIF Report Viewer</title> <style> ${styles} </style> </head> <body> <div id="root">${bodyHtml}</div> <script> ${scripts} </script> </body> </html>`; } catch (error) { console.error('Error reading CSS or JS files:', error); // Fallback: return HTML without embedded styles and scripts return `<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>SARIF Report Viewer</title> </head> <body> <div id="root">${bodyHtml}</div> <script> console.error('JavaScript not loaded due to file reading error'); </script> </body> </html>`; } } //# sourceMappingURL=html-template.js.map