Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Add detailed comments to explain image regex pattern
Co-authored-by: sacOO7 <16723785+sacOO7@users.noreply.github.com>
  • Loading branch information
Copilot and sacOO7 committed Dec 6, 2025
commit 0e83b148e2fd72b5e9d9b30916ad2d3f404a9798
15 changes: 12 additions & 3 deletions data/onPostBuild/transpileMdxToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,18 @@ function convertImagePathsToGitHub(content: string): string {
const imageExtPattern = imageExtensions.join('|');

// Regex to match Markdown images with images/ path and valid image extension
// Handles escaped brackets in alt text and parentheses in URL
// Alt text: allows any character, including escaped brackets
// URL: matches images/ path, allows parentheses in the path, and ends with valid extension
// Pattern breakdown:
// - !\[ - Image markdown syntax start
// - ((?:[^\]\\]|\\.)*) - Alt text: matches any char except unescaped ], allows escaped chars
// - \]\( - End alt text, start URL
// - ((?:\.\.\/)+)? - Optional: one or more ../ patterns (relative paths)
// - \/? - Optional: leading slash (absolute paths)
// - (images\/ - Required: images/ directory
// - (?:[^)\s]|\([^)]*\))+? - Path: allows any char except ) and whitespace, or matched parentheses
// - \.(?:${imageExtPattern}) - Required: file extension from allowed list
// - )
// - (?:\s+"[^"]*")? - Optional: title attribute in quotes
// - \) - Close markdown image syntax
const imageRegex = new RegExp(
String.raw`!\[((?:[^\]\\]|\\.)*)\]\(((?:\.\.\/)+)?\/?(images\/(?:[^)\s]|\([^)]*\))+?\.(?:${imageExtPattern}))(?:\s+"[^"]*")?\)`,
'g',
Expand Down