Skip to content

Commit 37901c3

Browse files
committed
FIX: Render markdown code fences in suggested customer response as HTML <pre><code>
1 parent ead67aa commit 37901c3

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

.github/workflows/issue-notify.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,42 @@ jobs:
166166
ENGINEER_GUIDANCE=""
167167
fi
168168
169-
# Format suggested customer response
169+
# Format suggested customer response (Markdown -> HTML, preserving code blocks)
170170
SUGGESTED_RESPONSE_RAW="$INPUT_SUGGESTED_RESPONSE"
171171
if [ -n "$SUGGESTED_RESPONSE_RAW" ]; then
172-
SUGGESTED_RESPONSE=$(echo "$SUGGESTED_RESPONSE_RAW" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/$/\<br\>/g')
172+
SUGGESTED_RESPONSE=$(printf '%s' "$SUGGESTED_RESPONSE_RAW" | awk '
173+
function htmlesc(s) {
174+
gsub(/&/, "\\&amp;", s)
175+
gsub(/</, "\\&lt;", s)
176+
gsub(/>/, "\\&gt;", s)
177+
return s
178+
}
179+
BEGIN { in_code = 0 }
180+
{
181+
line = $0
182+
# Toggle on fenced code block markers (```), allow optional language
183+
if (line ~ /^[[:space:]]*```/) {
184+
if (in_code == 0) { printf "<pre><code>"; in_code = 1 }
185+
else { printf "</code></pre>"; in_code = 0 }
186+
next
187+
}
188+
if (in_code) {
189+
# Inside a code block: HTML-escape and preserve newlines literally
190+
printf "%s\n", htmlesc(line)
191+
} else {
192+
esc = htmlesc(line)
193+
# Convert inline `code` to <code>code</code>
194+
out = ""
195+
while (match(esc, /`[^`]+`/)) {
196+
out = out substr(esc, 1, RSTART-1) "<code>" substr(esc, RSTART+1, RLENGTH-2) "</code>"
197+
esc = substr(esc, RSTART+RLENGTH)
198+
}
199+
out = out esc
200+
printf "%s<br>", out
201+
}
202+
}
203+
END { if (in_code) printf "</code></pre>" }
204+
')
173205
else
174206
SUGGESTED_RESPONSE=""
175207
fi

0 commit comments

Comments
 (0)