From 89030e95b824dd25ef3015a592882092fe8490b3 Mon Sep 17 00:00:00 2001 From: crystal <71373843+CrystalCommunication@users.noreply.github.com> Date: Mon, 23 Jan 2023 02:32:57 -0700 Subject: [PATCH 1/5] headline link fix --- modules/markup/html.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/markup/html.go b/modules/markup/html.go index 6b5a8e32d4ef4..de6abe3940d26 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -359,6 +359,10 @@ func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node if attr.Key == "id" && !(strings.HasPrefix(attr.Val, "user-content-") || blackfridayExtRegex.MatchString(attr.Val)) { node.Attr[idx].Val = "user-content-" + attr.Val } + // Add user-content- to # links too + if attr.Key == "href" && (strings.HasPrefix(attr.Val, "#")) && !(strings.HasPrefix(attr.Val, "#user-content-") || blackfridayExtRegex.MatchString(attr.Val)) { + node.Attr[idx].Val = "#user-content-" + strings.TrimPrefix(attr.Val, "#") + } if attr.Key == "class" && attr.Val == "emoji" { textProcs = nil From ef71b25746e898068286ac4bde0287fda4e0091a Mon Sep 17 00:00:00 2001 From: crystal <71373843+CrystalCommunication@users.noreply.github.com> Date: Mon, 23 Jan 2023 03:06:31 -0700 Subject: [PATCH 2/5] cleanup --- modules/markup/html.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index de6abe3940d26..ba5c60283d7c7 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -360,7 +360,7 @@ func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node node.Attr[idx].Val = "user-content-" + attr.Val } // Add user-content- to # links too - if attr.Key == "href" && (strings.HasPrefix(attr.Val, "#")) && !(strings.HasPrefix(attr.Val, "#user-content-") || blackfridayExtRegex.MatchString(attr.Val)) { + if attr.Key == "href" && strings.HasPrefix(attr.Val, "#") && !(strings.HasPrefix(attr.Val, "#user-content-") || blackfridayExtRegex.MatchString(strings.TrimPrefix(attr.Val, "#"))) { node.Attr[idx].Val = "#user-content-" + strings.TrimPrefix(attr.Val, "#") } From d267f0944039cbd3236b0a692a51d74f6903340e Mon Sep 17 00:00:00 2001 From: crystal <71373843+CrystalCommunication@users.noreply.github.com> Date: Sun, 29 Jan 2023 00:35:53 -0700 Subject: [PATCH 3/5] refactor this section --- modules/markup/html.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index ba5c60283d7c7..acbbf40baaa22 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -356,12 +356,15 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node) { // Add user-content- to IDs if they don't already have them for idx, attr := range node.Attr { - if attr.Key == "id" && !(strings.HasPrefix(attr.Val, "user-content-") || blackfridayExtRegex.MatchString(attr.Val)) { + var val = strings.TrimPrefix(attr.Val, "#"); + var notHasPrefix = !(strings.HasPrefix(val, "user-content-") || blackfridayExtRegex.MatchString(val)); + + if attr.Key == "id" && notHasPrefix { node.Attr[idx].Val = "user-content-" + attr.Val } // Add user-content- to # links too - if attr.Key == "href" && strings.HasPrefix(attr.Val, "#") && !(strings.HasPrefix(attr.Val, "#user-content-") || blackfridayExtRegex.MatchString(strings.TrimPrefix(attr.Val, "#"))) { - node.Attr[idx].Val = "#user-content-" + strings.TrimPrefix(attr.Val, "#") + if attr.Key == "href" && strings.HasPrefix(attr.Val, "#") && notHasPrefix { + node.Attr[idx].Val = "#user-content-" + val } if attr.Key == "class" && attr.Val == "emoji" { From 400e5db03d9933f13df3c5efd8e40259ceaf605d Mon Sep 17 00:00:00 2001 From: crystal <71373843+CrystalCommunication@users.noreply.github.com> Date: Sun, 29 Jan 2023 08:29:57 -0700 Subject: [PATCH 4/5] make fmt --- modules/markup/html.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index acbbf40baaa22..52c818b06ba8f 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -356,8 +356,8 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node) { // Add user-content- to IDs if they don't already have them for idx, attr := range node.Attr { - var val = strings.TrimPrefix(attr.Val, "#"); - var notHasPrefix = !(strings.HasPrefix(val, "user-content-") || blackfridayExtRegex.MatchString(val)); + val := strings.TrimPrefix(attr.Val, "#") + notHasPrefix := !(strings.HasPrefix(val, "user-content-") || blackfridayExtRegex.MatchString(val)) if attr.Key == "id" && notHasPrefix { node.Attr[idx].Val = "user-content-" + attr.Val From e7da7bf052b35a75028fd7f44152c6de42e33921 Mon Sep 17 00:00:00 2001 From: crystal <71373843+CrystalCommunication@users.noreply.github.com> Date: Mon, 30 Jan 2023 20:44:07 -0700 Subject: [PATCH 5/5] merge comments --- modules/markup/html.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index e26d07f5376ca..bcb38f99eb4a8 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -358,7 +358,7 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output } func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node) { - // Add user-content- to IDs if they don't already have them + // Add user-content- to IDs and "#" links if they don't already have them for idx, attr := range node.Attr { val := strings.TrimPrefix(attr.Val, "#") notHasPrefix := !(strings.HasPrefix(val, "user-content-") || blackfridayExtRegex.MatchString(val)) @@ -366,7 +366,7 @@ func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node if attr.Key == "id" && notHasPrefix { node.Attr[idx].Val = "user-content-" + attr.Val } - // Add user-content- to # links too + if attr.Key == "href" && strings.HasPrefix(attr.Val, "#") && notHasPrefix { node.Attr[idx].Val = "#user-content-" + val }