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
1 change: 1 addition & 0 deletions app/components/Readme.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function handleClick(event: MouseEvent) {
min-width: 0;
/* Contain all children z-index values inside this container */
isolation: isolate;
contain: layout paint;
}

/* README headings - styled by visual level (data-level), not semantic level */
Expand Down
15 changes: 11 additions & 4 deletions server/utils/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@
'blockquote': ['data-callout'],
'details': ['open'],
'code': ['class'],
'pre': ['class', 'style'],
'pre': ['class'],
'span': ['class', 'style'],
'div': ['class', 'style', 'align'],
'div': ['class', 'align'],
'p': ['align'],
}

Expand Down Expand Up @@ -558,7 +558,7 @@
return `<h${semanticLevel} id="${id}" data-level="${depth}"${preservedAttrs}><a href="#${id}">${displayHtml}</a></h${semanticLevel}>\n`
}

const anchorTokenRegex = /^<a(\s.+)?\/?>$/

Check warning on line 561 in server/utils/readme.ts

View workflow job for this annotation

GitHub Actions / 🤖 Autofix code

regexp(no-unused-capturing-group)

Capturing group number 1 is defined but never used.

Check warning on line 561 in server/utils/readme.ts

View workflow job for this annotation

GitHub Actions / 🔠 Lint project

regexp(no-unused-capturing-group)

Capturing group number 1 is defined but never used.
renderer.heading = function ({ tokens, depth }: Tokens.Heading) {
const isAnchorHeading =
anchorTokenRegex.test(tokens[0]?.raw ?? '') && tokens[tokens.length - 1]?.raw === '</a>'
Expand Down Expand Up @@ -609,8 +609,8 @@
// Resolve image URLs (with GitHub blob → raw conversion)
renderer.image = ({ href, title, text }: Tokens.Image) => {
const resolvedHref = resolveImageUrl(href, packageName, repoInfo)
const titleAttr = title ? ` title="${title}"` : ''
const altAttr = text ? ` alt="${text}"` : ''
const titleAttr = title ? ` title="${escapeHtml(title)}"` : ''
const altAttr = text ? ` alt="${escapeHtml(text)}"` : ''
return `<img src="${resolvedHref}"${altAttr}${titleAttr}>`
}

Expand Down Expand Up @@ -687,6 +687,13 @@
allowedTags: ALLOWED_TAGS,
allowedAttributes: ALLOWED_ATTR,
allowedSchemes: ['http', 'https', 'mailto'],
// disallow styles other than the ones shiki emits
allowedStyles: {
span: {
'color': [/^#[0-9a-f]{3,8}$/i],
'--shiki-light': [/^#[0-9a-f]{3,8}$/i],
},
},
// Transform img src URLs (GitHub blob → raw, relative → GitHub raw)
transformTags: {
// Headings are already processed to correct semantic levels by processHeading()
Expand Down
Loading