[READ-ONLY] a fast, modern browser for the npm registry

fix: add missing whitespace before `import` keyword in code previews (#432)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Mikołaj Misztal
autofix-ci[bot]
and committed by
GitHub
e690e38b c9fb2628

+13 -4
+1 -1
server/api/registry/file/[...pkg].get.ts
··· 6 6 ERROR_PACKAGE_VERSION_AND_FILE_FAILED, 7 7 } from '#shared/utils/constants' 8 8 9 - const CACHE_VERSION = 2 9 + const CACHE_VERSION = 3 10 10 11 11 // Maximum file size to fetch and highlight (500KB) 12 12 const MAX_FILE_SIZE = 500 * 1024
+12 -3
server/utils/code-highlight.ts
··· 220 220 // or: <span>import</span><span>(</span><span>'module'</span> 221 221 // Note: require often has a leading space in the span from Shiki 222 222 result = result.replace( 223 - /(<span[^>]*>)\s*(require|import)(<\/span>)(<span[^>]*>\(<\/span>)(<span[^>]*>)(['"][^'"]+['"])<\/span>/g, 224 - (match, spanOpen, keyword, spanClose, parenSpan, stringSpanOpen, moduleSpecifier) => { 223 + /(<span[^>]*>)(\s*)(require|import)(<\/span>)(<span[^>]*>\(<\/span>)(<span[^>]*>)(['"][^'"]+['"])<\/span>/g, 224 + ( 225 + match, 226 + spanOpen, 227 + whitespace, 228 + keyword, 229 + spanClose, 230 + parenSpan, 231 + stringSpanOpen, 232 + moduleSpecifier, 233 + ) => { 225 234 const href = getHref(moduleSpecifier) 226 235 if (!href) return match 227 - return `${spanOpen}${keyword}${spanClose}${parenSpan}${stringSpanOpen}<a href="${href}" class="import-link">${moduleSpecifier}</a></span>` 236 + return `${spanOpen}${whitespace}${keyword}${spanClose}${parenSpan}${stringSpanOpen}<a href="${href}" class="import-link">${moduleSpecifier}</a></span>` 228 237 }, 229 238 ) 230 239