Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/api/registry/file/[...pkg].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ERROR_PACKAGE_VERSION_AND_FILE_FAILED,
} from '#shared/utils/constants'

const CACHE_VERSION = 2
const CACHE_VERSION = 3

// Maximum file size to fetch and highlight (500KB)
const MAX_FILE_SIZE = 500 * 1024
Expand Down
15 changes: 12 additions & 3 deletions server/utils/code-highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,20 @@ function linkifyImports(html: string, options?: LinkifyOptions): string {
// or: <span>import</span><span>(</span><span>'module'</span>
// Note: require often has a leading space in the span from Shiki
result = result.replace(
/(<span[^>]*>)\s*(require|import)(<\/span>)(<span[^>]*>\(<\/span>)(<span[^>]*>)(['"][^'"]+['"])<\/span>/g,
(match, spanOpen, keyword, spanClose, parenSpan, stringSpanOpen, moduleSpecifier) => {
/(<span[^>]*>)(\s*)(require|import)(<\/span>)(<span[^>]*>\(<\/span>)(<span[^>]*>)(['"][^'"]+['"])<\/span>/g,
(
match,
spanOpen,
whitespace,
keyword,
spanClose,
parenSpan,
stringSpanOpen,
moduleSpecifier,
) => {
const href = getHref(moduleSpecifier)
if (!href) return match
return `${spanOpen}${keyword}${spanClose}${parenSpan}${stringSpanOpen}<a href="${href}" class="import-link">${moduleSpecifier}</a></span>`
return `${spanOpen}${whitespace}${keyword}${spanClose}${parenSpan}${stringSpanOpen}<a href="${href}" class="import-link">${moduleSpecifier}</a></span>`
},
)

Expand Down
Loading