Skip to content

Commit e6dcbd2

Browse files
committed
fix html in markdown
1 parent 01f2996 commit e6dcbd2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

modules/markup/html.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ var globalVars = sync.OnceValue(func() *globalVarsType {
8686
// codePreviewPattern matches "http://domain/.../{owner}/{repo}/src/commit/{commit}/{filepath}#L10-L20"
8787
v.codePreviewPattern = regexp.MustCompile(`https?://\S+/([^\s/]+)/([^\s/]+)/src/commit/([0-9a-f]{7,64})(/\S+)#(L\d+(-L\d+)?)`)
8888

89-
// cleans: "<foo/bar", "<any words/", ("<html", "<head", "<script", "<style")
90-
v.tagCleaner = regexp.MustCompile(`(?i)<(/?\w+/\w+|/[\w ]+/|/?(html|head|script|style\b))`)
89+
// cleans: "<foo/bar", "<any words/", ("<html", "<head", "<script", "<style", "<?", "<%")
90+
v.tagCleaner = regexp.MustCompile(`(?i)<(/?\w+/\w+|/[\w ]+/|/?(html|head|script|style|%|\?)\b)`)
9191
v.nulCleaner = strings.NewReplacer("\000", "")
9292
return v
9393
})
@@ -253,7 +253,7 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
253253
node, err := html.Parse(io.MultiReader(
254254
// prepend "<html><body>"
255255
strings.NewReader("<html><body>"),
256-
// Strip out nuls - they're always invalid
256+
// strip out NULLs (they're always invalid), and escape known tags
257257
bytes.NewReader(globalVars().tagCleaner.ReplaceAll([]byte(globalVars().nulCleaner.Replace(string(rawHTML))), []byte("&lt;$1"))),
258258
// close the tags
259259
strings.NewReader("</body></html>"),

modules/markup/html_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ func TestPostProcess(t *testing.T) {
525525
test("<script>a</script>", `&lt;script&gt;a&lt;/script&gt;`)
526526
test("<STYLE>a", `&lt;STYLE&gt;a`)
527527
test("<style>a</STYLE>", `&lt;style&gt;a&lt;/STYLE&gt;`)
528+
529+
// other special tags, our special behavior
530+
test("<?php\nfoo", "&lt;?php\nfoo")
531+
test("<%asp\nfoo", "&lt;%asp\nfoo")
528532
}
529533

530534
func TestIssue16020(t *testing.T) {

0 commit comments

Comments
 (0)