feat: src 속성 URL 해결 함수 추가하여 assetBaseUrl 적용
This commit is contained in:
@@ -254,6 +254,23 @@
|
||||
return html
|
||||
})
|
||||
|
||||
// src 속성에 http/https가 없으면 assetBaseUrl 붙이기
|
||||
const resolveHtmlSrcUrls = (html: string): string => {
|
||||
const base = assetBaseUrl.value || ''
|
||||
if (!base) return html
|
||||
|
||||
return html.replace(
|
||||
/(<[^>]+\s)src\s*=\s*(["'])([^"']+)\2/gi,
|
||||
(_match, prefix: string, quote: string, srcValue: string) => {
|
||||
if (/^https?:\/\//i.test(srcValue)) {
|
||||
return `${prefix}src=${quote}${srcValue}${quote}`
|
||||
}
|
||||
const resolvedUrl = base + srcValue.replace(/^\//, '')
|
||||
return `${prefix}src=${quote}${resolvedUrl}${quote}`
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// 렌더링용 HTML
|
||||
// - link/script는 head/body로 별도 주입 (렌더 위치에 남기지 않음)
|
||||
// - style은 "그 자리에 그대로" 렌더링하되, 적용 안정성을 위해 head에도 복제 주입함
|
||||
@@ -261,11 +278,15 @@
|
||||
const html = customContentsRaw.value
|
||||
if (!html) return ''
|
||||
|
||||
return html
|
||||
let result = html
|
||||
// link 태그 제거
|
||||
.replace(/<link\b[^>]*>/gi, '')
|
||||
// script 블록 제거
|
||||
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, '')
|
||||
|
||||
result = resolveHtmlSrcUrls(result)
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
type OrderedAsset =
|
||||
|
||||
Reference in New Issue
Block a user