mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 23:15:49 +01:00
Fix page-relative links, e.g. in TOC.
This commit is contained in:
@@ -35,6 +35,8 @@ object Asciidoc {
|
|||||||
prefixRelativeUrls(rendered, relativeUrlPrefix)
|
prefixRelativeUrls(rendered, relativeUrlPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private[this] val exceptionPrefixes = Seq("#", "/", "http://", "https://")
|
||||||
|
|
||||||
def prefixRelativeUrls(html: String, urlPrefix: String): String = {
|
def prefixRelativeUrls(html: String, urlPrefix: String): String = {
|
||||||
val cleaner = new HtmlCleaner()
|
val cleaner = new HtmlCleaner()
|
||||||
val node = cleaner.clean(html)
|
val node = cleaner.clean(html)
|
||||||
@@ -43,7 +45,8 @@ object Asciidoc {
|
|||||||
htmlNode match {
|
htmlNode match {
|
||||||
case tag: TagNode if tag.getName == "a" =>
|
case tag: TagNode if tag.getName == "a" =>
|
||||||
Option(tag.getAttributeByName("href")) foreach { href =>
|
Option(tag.getAttributeByName("href")) foreach { href =>
|
||||||
if (!href.startsWith("/") && !href.startsWith("http://") && !href.startsWith("https://")) {
|
if (exceptionPrefixes.forall(p => !href.startsWith(p))) {
|
||||||
|
// if (!href.startsWith("/") && !href.startsWith("http://") && !href.startsWith("https://")) {
|
||||||
tag.addAttribute("href", s"${urlPrefix}${href}")
|
tag.addAttribute("href", s"${urlPrefix}${href}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user