diff --git a/modules/markup/html.go b/modules/markup/html.go
index 4687244668b..f64114226e1 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -349,8 +349,8 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) *html.Nod
// TextNode emoji will be converted to ``, then the next iteration will visit the "span"
// if we don't stop it, it will go into the TextNode again and create an infinite recursion
return node.NextSibling
- } else if node.Data == "code" || node.Data == "pre" {
- return node.NextSibling // ignore code and pre nodes
+ } else if node.Data == "code" || node.Data == "pre" || node.Data == "math" {
+ return node.NextSibling // ignore code, pre and math nodes
} else if node.Data == "img" {
return visitNodeImg(ctx, node)
} else if node.Data == "video" {
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 8881edb9486..f4b44a5cbe1 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -543,6 +543,9 @@ func TestPostProcess(t *testing.T) {
`Some text with 😄 in the middle`)
test("http://localhost:3000/person/repo/issues/4#issuecomment-1234",
`person/repo#4 (comment)`)
+ test(
+ "",
+ "")
// special tags, GitHub's behavior, and for unclosed tags, output as text content as much as possible
test("