Skip to content

Commit 74c873f

Browse files
authored
Merge branch 'main' into main
2 parents ae1a60d + e331d86 commit 74c873f

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

app/components/Readme.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function handleClick(event: MouseEvent) {
8989
min-width: 0;
9090
/* Contain all children z-index values inside this container */
9191
isolation: isolate;
92+
contain: layout paint;
9293
}
9394
9495
/* README headings - styled by visual level (data-level), not semantic level */

app/composables/useSelectedPackageManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export const useSelectedPackageManager = createSharedComposable(
1212

1313
// Sync to data-pm attribute on the client
1414
if (import.meta.client) {
15+
const queryPM = new URLSearchParams(window.location.search).get('pm')
16+
if (queryPM && packageManagers.some(pm => pm.id === queryPM)) {
17+
pm.value = queryPM as PackageManagerId
18+
}
1519
// Watch for changes and update the attribute
1620
watch(
1721
pm,

app/utils/prehydrate.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,28 @@ export function initPreferencesOnPrehydrate() {
3939
document.documentElement.dataset.bgTheme = preferredBackgroundTheme
4040
}
4141

42-
// Read and apply package manager preference
43-
const storedPM = localStorage.getItem('npmx-pm')
44-
// Parse the stored value (it's stored as a JSON string by useLocalStorage)
4542
let pm = 'npm'
46-
if (storedPM) {
47-
try {
48-
const parsed = JSON.parse(storedPM)
49-
if (validPMs.has(parsed)) {
50-
pm = parsed
51-
}
52-
} catch {
53-
// If parsing fails, check if it's a plain string (legacy format)
54-
if (validPMs.has(storedPM)) {
55-
pm = storedPM
43+
44+
// Support package manager preference in query string (for example, ?pm=pnpm)
45+
const queryPM = new URLSearchParams(window.location.search).get('pm')
46+
if (queryPM && validPMs.has(queryPM)) {
47+
pm = queryPM
48+
localStorage.setItem('npmx-pm', pm)
49+
} else {
50+
// Read and apply package manager preference
51+
const storedPM = localStorage.getItem('npmx-pm')
52+
// Parse the stored value (it's stored as a JSON string by useLocalStorage)
53+
if (storedPM) {
54+
try {
55+
const parsed = JSON.parse(storedPM)
56+
if (validPMs.has(parsed)) {
57+
pm = parsed
58+
}
59+
} catch {
60+
// If parsing fails, check if it's a plain string (legacy format)
61+
if (validPMs.has(storedPM)) {
62+
pm = storedPM
63+
}
5664
}
5765
}
5866
}

server/utils/readme.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ const ALLOWED_ATTR: Record<string, string[]> = {
198198
'blockquote': ['data-callout'],
199199
'details': ['open'],
200200
'code': ['class'],
201-
'pre': ['class', 'style'],
201+
'pre': ['class'],
202202
'span': ['class', 'style'],
203-
'div': ['class', 'style', 'align'],
203+
'div': ['class', 'align'],
204204
'p': ['align'],
205205
}
206206

@@ -609,8 +609,8 @@ ${html}
609609
// Resolve image URLs (with GitHub blob → raw conversion)
610610
renderer.image = ({ href, title, text }: Tokens.Image) => {
611611
const resolvedHref = resolveImageUrl(href, packageName, repoInfo)
612-
const titleAttr = title ? ` title="${title}"` : ''
613-
const altAttr = text ? ` alt="${text}"` : ''
612+
const titleAttr = title ? ` title="${escapeHtml(title)}"` : ''
613+
const altAttr = text ? ` alt="${escapeHtml(text)}"` : ''
614614
return `<img src="${resolvedHref}"${altAttr}${titleAttr}>`
615615
}
616616

@@ -687,6 +687,13 @@ ${html}
687687
allowedTags: ALLOWED_TAGS,
688688
allowedAttributes: ALLOWED_ATTR,
689689
allowedSchemes: ['http', 'https', 'mailto'],
690+
// disallow styles other than the ones shiki emits
691+
allowedStyles: {
692+
span: {
693+
'color': [/^#[0-9a-f]{3,8}$/i],
694+
'--shiki-light': [/^#[0-9a-f]{3,8}$/i],
695+
},
696+
},
690697
// Transform img src URLs (GitHub blob → raw, relative → GitHub raw)
691698
transformTags: {
692699
// Headings are already processed to correct semantic levels by processHeading()

0 commit comments

Comments
 (0)