Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ type postProcessCtx struct {

// processors used by this context.
procs []processor

// if set to true, when an <a> is found, instead of just returning during
// visitNode, it will recursively visit the node exclusively running
// shortLinkProcessorFull with true.
visitLinksForShortLinks bool
}

// PostProcess does the final required transformations to the passed raw HTML
Expand All @@ -191,11 +186,10 @@ func PostProcess(
) ([]byte, error) {
// create the context from the parameters
ctx := &postProcessCtx{
metas: metas,
urlPrefix: urlPrefix,
isWikiMarkdown: isWikiMarkdown,
procs: defaultProcessors,
visitLinksForShortLinks: true,
metas: metas,
urlPrefix: urlPrefix,
isWikiMarkdown: isWikiMarkdown,
procs: defaultProcessors,
}
return ctx.postProcess(rawHTML)
}
Expand Down Expand Up @@ -285,9 +279,6 @@ func (ctx *postProcessCtx) visitNode(node *html.Node) {
ctx.textNode(node)
case html.ElementNode:
if node.Data == "a" || node.Data == "code" || node.Data == "pre" {
if node.Data == "a" && ctx.visitLinksForShortLinks {
ctx.visitNodeForShortLinks(node)
}
return
}
for n := node.FirstChild; n != nil; n = n.NextSibling {
Expand All @@ -302,7 +293,7 @@ func (ctx *postProcessCtx) visitNodeForShortLinks(node *html.Node) {
case html.TextNode:
shortLinkProcessorFull(ctx, node, true)
case html.ElementNode:
if node.Data == "code" || node.Data == "pre" {
if node.Data == "code" || node.Data == "pre" || node.Data == "a" {
return
}
for n := node.FirstChild; n != nil; n = n.NextSibling {
Expand Down
4 changes: 4 additions & 0 deletions modules/markup/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,8 @@ func TestRender_ShortLinks(t *testing.T) {
"[[some/path/Link #.jpg]]",
`<p><a href="`+notencodedImgurl+`" rel="nofollow"><img src="`+notencodedImgurl+`"/></a></p>`,
`<p><a href="`+notencodedImgurlWiki+`" rel="nofollow"><img src="`+notencodedImgurlWiki+`"/></a></p>`)
test(
"<p><a href=\"https://example.org\">[[foobar]]</a></p>",
`<p><a href="https://example.org" rel="nofollow">[[foobar]]</a></p>`,
`<p><a href="https://example.org" rel="nofollow">[[foobar]]</a></p>`)
}