also looking at this
fix(layouts): fill @parent in a layout that extends another layout
#2103
2 files
+88
-1
| @@ -99,6 +99,22 @@ export { validateClientScript } from './script-validation' | ||
| 99 | 99 | */ |
| 100 | 100 | const PARENT_PLACEHOLDER = '<!--PARENT_CONTENT_PLACEHOLDER-->' |
| 101 | 101 | |
| 102 | /** | |
| 103 | * Mark the `@parent` in a section of a layout that extends another layout, as | |
| 104 | * the page's own sections are marked, so the layout it extends splices its | |
| 105 | * section in there. Layout source arrives raw, so `@@parent`, a longer word | |
| 106 | * (`a@parents.com`) and a `@parent` inside a comment stay text. | |
| 107 | */ | |
| 108 | function markLayoutParent(content: string): string { | |
| 109 | const visible = maskAtElementPosition( | |
| 110 | content.replace(/\{\{--[\s\S]*?--\}\}/g, comment => ' '.repeat(comment.length)), | |
| 111 | matchHtmlComment, | |
| 112 | comment => ' '.repeat(comment.length), | |
| 113 | ).output | |
| 114 | const at = visible.search(/(?<![\w@])@parent(?!\w)/) | |
| 115 | return at === -1 ? content : content.slice(0, at) + PARENT_PLACEHOLDER + content.slice(at + '@parent'.length) | |
| 116 | } | |
| 117 | ||
| 102 | 118 | function escapeHtmlAttribute(value: string): string { |
| 103 | 119 | return value |
| 104 | 120 | .replace(/&/g, '&') |
| @@ -1445,7 +1461,7 @@ async function processDirectivesInternal( | ||
| 1445 | 1461 | // Extract layout sections for parent content |
| 1446 | 1462 | const layoutSections: Record<string, string> = {} |
| 1447 | 1463 | const processedLayout = layoutContent.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g, (_, name, content) => { |
| 1448 | layoutSections[name] = content.trim() | |
| 1464 | layoutSections[name] = markLayoutParent(content.trim()) | |
| 1449 | 1465 | return '' // Remove the section from the template |
| 1450 | 1466 | }) |
| 1451 | 1467 | |