|
6 | 6 | {{ with .Params.description }} |
7 | 7 | > {{ . }} |
8 | 8 | {{ end }} |
9 | | -{{ .RawContent -}} |
| 9 | + |
| 10 | +{{- /* Initialize scratchpad */ -}} |
| 11 | +{{- $.Scratch.Set "content" .RawContent -}} |
| 12 | + |
| 13 | +{{/* ========================================================= |
| 14 | + STAGE 1: EXPAND NESTED INCLUDES (RECURSIVE & SCOPE-SAFE) |
| 15 | + ========================================================= */}} |
| 16 | +{{- range seq 10 -}} |
| 17 | + {{- $currentContent := $.Scratch.Get "content" -}} |
| 18 | + {{- if in $currentContent "{{< include \"" -}} |
| 19 | + {{- $chunks := split $currentContent "{{< include \"" -}} |
| 20 | + {{- $.Scratch.Set "finalContent" (index $chunks 0) -}} |
| 21 | + |
| 22 | + {{- range $idx, $chunk := $chunks -}} |
| 23 | + {{- if gt $idx 0 -}} |
| 24 | + {{- $parts := split $chunk "\" >}}" -}} |
| 25 | + {{- $path := index $parts 0 -}} |
| 26 | + {{- $restOfText := index $parts 1 -}} |
| 27 | + |
| 28 | + {{- $includePage := $.Site.GetPage $path -}} |
| 29 | + {{- $injectedContent := "" -}} |
| 30 | + {{- if $includePage -}} |
| 31 | + {{- $injectedContent = $includePage.RawContent -}} |
| 32 | + {{- else -}} |
| 33 | + {{- $cleanPath := replace $path "/partials/" "" -}} |
| 34 | + {{- if templates.Exists (printf "partials/%s" $cleanPath) -}} |
| 35 | + {{- $injectedContent = partial $cleanPath $ -}} |
| 36 | + {{- end -}} |
| 37 | + {{- end -}} |
| 38 | + |
| 39 | + {{- $runningContent := $.Scratch.Get "finalContent" -}} |
| 40 | + {{- $.Scratch.Set "finalContent" (printf "%s%s%s" $runningContent $injectedContent $restOfText) -}} |
| 41 | + {{- end -}} |
| 42 | + {{- end -}} |
| 43 | + |
| 44 | + {{- $.Scratch.Set "content" ($.Scratch.Get "finalContent") -}} |
| 45 | + {{- end -}} |
| 46 | +{{- end -}} |
| 47 | + |
| 48 | + |
| 49 | +{{/* ========================================================= |
| 50 | + STAGE 2: FLATTEN TABS & CLEAN WRAPPER TAGS |
| 51 | + ========================================================= */}} |
| 52 | +{{- $processedContent := $.Scratch.Get "content" -}} |
| 53 | + |
| 54 | +{{- if in $processedContent "{{< tab header=\"" -}} |
| 55 | + {{- $tabChunks := split $processedContent "{{< tab header=\"" -}} |
| 56 | + {{- $.Scratch.Set "flattenedTabs" (index $tabChunks 0) -}} |
| 57 | + |
| 58 | + {{- range $idx, $chunk := $tabChunks -}} |
| 59 | + {{- if gt $idx 0 -}} |
| 60 | + {{- $parts := split $chunk "\" >}}" -}} |
| 61 | + {{- $headerName := index $parts 0 -}} |
| 62 | + {{- $tabBody := index $parts 1 -}} |
| 63 | + |
| 64 | + {{- $runningTabs := $.Scratch.Get "flattenedTabs" -}} |
| 65 | + {{- $.Scratch.Set "flattenedTabs" (printf "%s\n\n### Option: %s\n\n%s" $runningTabs $headerName $tabBody) -}} |
| 66 | + {{- end -}} |
| 67 | + {{- end -}} |
| 68 | + {{- $processedContent = $.Scratch.Get "flattenedTabs" -}} |
| 69 | +{{- end -}} |
| 70 | + |
| 71 | +{{- $processedContent = replace $processedContent "{{< tabpane >}}" "" -}} |
| 72 | +{{- $processedContent = replace $processedContent "{{< /tabpane >}}" "" -}} |
| 73 | +{{- $processedContent = replace $processedContent "{{<markdown>}}" "" -}} |
| 74 | +{{- $processedContent = replace $processedContent "{{</markdown>}}" "" -}} |
| 75 | +{{- $processedContent = replace $processedContent "{{< /tab >}}" "" -}} |
| 76 | + |
| 77 | + |
| 78 | +{{/* ========================================================= |
| 79 | + STAGE 3: CONVERT ALL HIGHLIGHT VARIANTS TO MARKDOWN CODEBLOCKS |
| 80 | + ========================================================= */}} |
| 81 | +{{- /* Step A: Normalize all opening tags (highlight & highlight-editable) to uniform markdown syntax */ -}} |
| 82 | +{{- $processedContent = replaceRE `\{\{\s*<\s*highlight\s+([a-zA-Z0-9_-]+)[^>]*>\s*\}\}` "\n```$1\n" $processedContent -}} |
| 83 | +{{- $processedContent = replaceRE `\{\{\s*<\s*highlight-editable\s+([a-zA-Z0-9_-]+)[^>]*>\s*\}\}` "\n```$1\n" $processedContent -}} |
| 84 | + |
| 85 | +{{- /* Step B: Normalize all closing tags to a temporary uniform string to guarantee we catch them all together */ -}} |
| 86 | +{{- $processedContent = replaceRE `\{\{\s*<\s*/highlight\s*>\s*\}\}` "{{</closeblock>}}" $processedContent -}} |
| 87 | +{{- $processedContent = replaceRE `\{\{\s*<\s*/highlight-editable\s*>\s*\}\}` "{{</closeblock>}}" $processedContent -}} |
| 88 | + |
| 89 | +{{- /* Step C: Safely replace all uniform closing tags with clean markdown backticks */ -}} |
| 90 | +{{- $processedContent = replace $processedContent "{{</closeblock>}}" "\n```\n" -}} |
| 91 | + |
| 92 | + |
| 93 | +{{/* ========================================================= |
| 94 | + STAGE 4: STRIP VARIABLES FROM EDITABLE CODE BLOCKS |
| 95 | + ========================================================= */}} |
| 96 | +{{- if in $processedContent "$$$" -}} |
| 97 | + {{- /* Strip out the $$$variable-name$$$ formatting, leaving only the value */ -}} |
| 98 | + {{- /* Matches: $$$id$$$value$$$ -> value */ -}} |
| 99 | + {{- $processedContent = replaceRE `\$\$\$[a-zA-Z0-9_-]+\$\$\$(.*?)\$\$\$` "$1" $processedContent -}} |
| 100 | +{{- end -}} |
| 101 | + |
| 102 | + |
| 103 | +{{/* ========================================================= |
| 104 | + STAGE 5: CONVERT NOTEBOXES TO MARKDOWN BLOCKQUOTES |
| 105 | + ========================================================= */}} |
| 106 | +{{- if in $processedContent "notebox" -}} |
| 107 | + {{- /* Standardize tags */ -}} |
| 108 | + {{- $processedContent = replaceRE `\{\{\s*<\s*notebox\s*>\s*\}\}` "{{<notebox>}}" $processedContent -}} |
| 109 | + {{- $processedContent = replaceRE `\{\{\s*<\s*/notebox\s*>\s*\}\}` "{{</notebox>}}" $processedContent -}} |
| 110 | + |
| 111 | + {{- /* Split by the opening notebox tag to cleanly prepend blockquote markers to every line inside */ -}} |
| 112 | + {{- $noteChunks := split $processedContent "{{<notebox>}}" -}} |
| 113 | + {{- $.Scratch.Set "cleanNotes" (index $noteChunks 0) -}} |
| 114 | + |
| 115 | + {{- range $idx, $chunk := $noteChunks -}} |
| 116 | + {{- if gt $idx 0 -}} |
| 117 | + {{- $parts := split $chunk "{{</notebox>}}" -}} |
| 118 | + {{- $noteBody := index $parts 0 -}} |
| 119 | + {{- $restOfText := index $parts 1 -}} |
| 120 | + |
| 121 | + {{- /* Prepend > to each line within the note block */ -}} |
| 122 | + {{- $blockquoteLines := slice -}} |
| 123 | + {{- range (split $noteBody "\n") -}} |
| 124 | + {{- $blockquoteLines = $blockquoteLines | append (printf "> %s" .) -}} |
| 125 | + {{- end -}} |
| 126 | + {{- $formattedNote := delimit $blockquoteLines "\n" -}} |
| 127 | + |
| 128 | + {{- $runningNotes := $.Scratch.Get "cleanNotes" -}} |
| 129 | + {{- $.Scratch.Set "cleanNotes" (printf "%s\n\n%s\n\n%s" $runningNotes $formattedNote $restOfText) -}} |
| 130 | + {{- end -}} |
| 131 | + {{- end -}} |
| 132 | + {{- $processedContent = $.Scratch.Get "cleanNotes" -}} |
| 133 | +{{- end -}} |
| 134 | + |
| 135 | +{{ $processedContent }} |
0 commit comments