p2: widen document fence for space and zero-width

Strip U+200B–U+200D, U+2060, U+FEFF before fencing. Match
(?i)<\s*/?\s*document so </ document> cannot sit outside the frame.
This commit is contained in:
2026-09-23 00:09:14 -07:00
parent ff87a04f94
commit a992216ec0
2 changed files with 17 additions and 2 deletions
+6 -2
View File
@@ -577,11 +577,15 @@ func min(a, b int) int {
return b
}
var documentTag = regexp.MustCompile(`(?i)</?document`)
var (
documentTag = regexp.MustCompile(`(?i)<\s*/?\s*document`)
zwChars = regexp.MustCompile("[\u200b\u200c\u200d\u2060\ufeff]")
)
func fenceDocument(s string) string {
s = zwChars.ReplaceAllString(s, "")
return documentTag.ReplaceAllStringFunc(s, func(m string) string {
if len(m) >= 2 && m[1] == '/' {
if strings.Contains(m, "/") {
return "&lt;/document"
}
return "&lt;document"