// 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
) ([]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)
}
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 {
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 {
"[[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>`)
}