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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"generate-dark-theme": "tsx scripts/generate-dark-theme.ts",
"validate-tutorials": "tsx scripts/validate-tutorials.ts",
"lint:tutorial-markdown": "tsx scripts/lint-tutorial-markdown.ts",
"scan-tutorial-markdown": "tsx scripts/scan-markdown-source.ts",
"publish-content": "tsx scripts/publish-content.ts",
"backfill-images": "tsx scripts/backfill-images.ts",
"preflight:ai-quiz-smoke": "tsx scripts/preflight-ai-quiz-smoke.ts",
Expand Down
36 changes: 24 additions & 12 deletions scripts/parsers/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ export interface ImageResolveOpts {
rewriteImages?: boolean
}

/**
* Strip the authoring directive comment (`<!-- border -->`, `<!-- size:540px -->`,
* or any combination like `<!-- border; size:540px -->`) that prefixes an image.
*
* If this comment survives into the body, goldmark treats the leading `<!--` as
* the start of an HTML block and consumes the trailing `![…]` as raw HTML text,
* so the image never renders (#1137). The directives may appear in either order,
* separated by `;` and/or whitespace. Only comments composed solely of these
* known directives are stripped — unrelated comments are left intact.
*
* Extracted from `resolveImageURLs` so the source-markdown scanner (issue #1963)
* and this in-flight pre-processor share ONE detection/transform and can never
* disagree. Pure, idempotent, and independent of repo/branch/URL context — the
* only part of image handling that is a genuine *source* fix (the URL rewrite is
* render-time and stays here, not in the scanner).
*/
export function stripImageDirectiveComments(content: string): string {
return content.replace(
/<!--\s*(?:border|size:\s*\d+px)(?:\s*;?\s*(?:border|size:\s*\d+px))*\s*-->\s*(!\[)/g,
'$1'
)
}

export function resolveImageURLs(content: string, opts: ImageResolveOpts): string {
const { repo, branch, slug, rewriteImages = true } = opts
let result = content
Expand All @@ -24,16 +47,5 @@ export function resolveImageURLs(content: string, opts: ImageResolveOpts): strin
)
}

// Strip the authoring directive comment (`<!-- border -->`, `<!-- size:540px -->`,
// or any combination like `<!-- border; size:540px -->`) that prefixes an image.
// If this comment survives into the body, goldmark treats the leading `<!--` as
// the start of an HTML block and consumes the trailing `![…]` as raw HTML text,
// so the image never renders (#1137). The directives may appear in either order,
// separated by `;` and/or whitespace. Only comments composed solely of these
// known directives are stripped — unrelated comments are left intact.
result = result.replace(
/<!--\s*(?:border|size:\s*\d+px)(?:\s*;?\s*(?:border|size:\s*\d+px))*\s*-->\s*(!\[)/g,
'$1'
)
return result
return stripImageDirectiveComments(result)
}
Loading
Loading