fix(renderer): extend _al_stash to include <img> tags, preventing autolink from mangling src= URLs
Bug: the autolink pass stashed <a> tags (via _al_stash) before running, but did not stash <img> tags. When  was converted to an <img> tag by the image pass, the subsequent autolink regex matched the URL inside src="..." and wrapped it in <a href="...">url</a>, producing src="<a href="...">url</a>" — a completely broken image source. Fix: extend the _al_stash regex from: (<a\b[^>]*>[\s\S]*?<\/a>) to: (<a\b[^>]*>[\s\S]*?<\/a>|<img\b[^>]*>) This stashes both <a> and self-closing <img> tags before autolink runs, then restores them after, so the URL inside src= is never touched. Adds 7 regression tests in tests/test_issue487b.py.
This commit is contained in:
@@ -552,7 +552,7 @@ function renderMd(raw){
|
||||
// Autolink: convert plain URLs to clickable links.
|
||||
// Stash existing <a> tags first so we never re-link a URL already inside href="...".
|
||||
const _al_stash=[];
|
||||
s=s.replace(/(<a\b[^>]*>[\s\S]*?<\/a>)/g,m=>{_al_stash.push(m);return `\x00B${_al_stash.length-1}\x00`;});
|
||||
s=s.replace(/(<a\b[^>]*>[\s\S]*?<\/a>|<img\b[^>]*>)/g,m=>{_al_stash.push(m);return `\x00B${_al_stash.length-1}\x00`;});
|
||||
s=s.replace(/(https?:\/\/[^\s<>"'\)\]]+)/g,(url)=>{
|
||||
// Strip trailing punctuation that was likely not part of the URL
|
||||
const trail=url.match(/[.,;:!?)]$/)?url.slice(-1):'';
|
||||
|
||||
Reference in New Issue
Block a user