mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-13 08:55:50 +01:00
(refs #409)Fix header anchor name in Markdown
This commit is contained in:
@@ -167,8 +167,8 @@ class GitBucketHtmlSerializer(
|
|||||||
val child = node.getChildren.asScala.headOption
|
val child = node.getChildren.asScala.headOption
|
||||||
val anchorName = child match {
|
val anchorName = child match {
|
||||||
case Some(x: AnchorLinkNode) => x.getName
|
case Some(x: AnchorLinkNode) => x.getName
|
||||||
case Some(x: TextNode) => x.getText // TODO
|
case Some(x: TextNode) => x.getText
|
||||||
case _ => GitBucketHtmlSerializer.generateAnchorName(printChildrenToString(node))
|
case _ => GitBucketHtmlSerializer.generateAnchorName(extractText(node)) // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
printer.print(s"""<$tag class="markdown-head">""")
|
printer.print(s"""<$tag class="markdown-head">""")
|
||||||
@@ -183,6 +183,15 @@ class GitBucketHtmlSerializer(
|
|||||||
printer.print(s"</$tag>")
|
printer.print(s"</$tag>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def extractText(node: Node): String = {
|
||||||
|
val sb = new StringBuilder()
|
||||||
|
node.getChildren.asScala.map {
|
||||||
|
case x: TextNode => sb.append(x.getText)
|
||||||
|
case x: Node => sb.append(extractText(x))
|
||||||
|
}
|
||||||
|
sb.toString()
|
||||||
|
}
|
||||||
|
|
||||||
override def visit(node: HeaderNode): Unit = {
|
override def visit(node: HeaderNode): Unit = {
|
||||||
printHeaderTag(node)
|
printHeaderTag(node)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user