Skip to content

Commit e690e38

Browse files
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>
1 parent c9fb262 commit e690e38

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

server/api/registry/file/[...pkg].get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ERROR_PACKAGE_VERSION_AND_FILE_FAILED,
77
} from '#shared/utils/constants'
88

9-
const CACHE_VERSION = 2
9+
const CACHE_VERSION = 3
1010

1111
// Maximum file size to fetch and highlight (500KB)
1212
const MAX_FILE_SIZE = 500 * 1024

server/utils/code-highlight.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,20 @@ function linkifyImports(html: string, options?: LinkifyOptions): string {
220220
// or: <span>import</span><span>(</span><span>'module'</span>
221221
// Note: require often has a leading space in the span from Shiki
222222
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+
) => {
225234
const href = getHref(moduleSpecifier)
226235
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>`
228237
},
229238
)
230239

0 commit comments

Comments
 (0)