diff options
Diffstat (limited to 'packages/bun-vscode/src/features/lockfile/lockfile.style.ts')
-rw-r--r-- | packages/bun-vscode/src/features/lockfile/lockfile.style.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/bun-vscode/src/features/lockfile/lockfile.style.ts b/packages/bun-vscode/src/features/lockfile/lockfile.style.ts new file mode 100644 index 000000000..7c4650497 --- /dev/null +++ b/packages/bun-vscode/src/features/lockfile/lockfile.style.ts @@ -0,0 +1,35 @@ +export function styleLockfile(preview: string) { + // Match all lines that don't start with a whitespace character + const lines = preview.split(/\n(?!\s)/); + + return lines.map(styleSection).join("\n"); +} + +function styleSection(section: string) { + const lines = section.split(/\n/); + + return lines.map(styleLine).join("\n"); +} + +function styleLine(line: string) { + if (line.startsWith("#")) { + return `<span class="mtk5">${line}</span>`; + } + + const parts = line.trim().split(" "); + if (line.startsWith(" ")) { + return `<span><span class="mtk1"> ${parts[0]} </span><span class="mtk16">${parts[1]}</span></span>`; + } + if (line.startsWith(" ")) { + const leftPart = `<span class="mtk6"> ${parts[0]} </span>`; + + if (parts.length === 1) return `<span>${leftPart}</span>`; + + if (parts[1].startsWith('"http://') || parts[1].startsWith('"https://')) + return `<span>${leftPart}<span class="mtk12 detected-link">${parts[1]}</span></span>`; + if (parts[1].startsWith('"')) return `<span>${leftPart}<span class="mtk16">${parts[1]}</span></span>`; + + return `<span>${leftPart}<span class="mtk6">${parts[1]}</span></span>`; + } + return `<span class="mtk1">${line} </span>`; +} |