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
5 changes: 4 additions & 1 deletion modules/common/src/main/MarkdownRender.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lila.common

import chess.format.pgn.PgnStr
import com.vladsch.flexmark.ast.{ AutoLink, Image, Link, LinkNode }
import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension
import com.vladsch.flexmark.ext.autolink.AutolinkExtension
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension
import com.vladsch.flexmark.ext.tables.{ TableBlock, TablesExtension }
Expand Down Expand Up @@ -51,6 +52,7 @@ final class MarkdownRender(
):

private val extensions = java.util.ArrayList[Extension]()
if header then extensions.add(AnchorLinkExtension.create())
if table then
extensions.add(TablesExtension.create())
extensions.add(MarkdownRender.tableWrapperExtension)
Expand All @@ -73,7 +75,8 @@ final class MarkdownRender(

// configurable
if table then options.set(TablesExtension.CLASS_NAME, "slist")
if !header then options.set(Parser.HEADING_PARSER, Boolean.box(false))
if header then options.set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, Boolean.box(false))
else options.set(Parser.HEADING_PARSER, Boolean.box(false))
if !blockQuote then options.set(Parser.BLOCK_QUOTE_PARSER, Boolean.box(false))
if !list then options.set(Parser.LIST_BLOCK_PARSER, Boolean.box(false))

Expand Down
10 changes: 9 additions & 1 deletion modules/common/src/test/MarkdownTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import lila.core.misc.lpv.LpvEmbed

class MarkdownTest extends munit.FunSuite:

val render: Markdown => Html = new MarkdownRender(assetDomain = AssetDomain("lichess1.org").some)("test")
val render: Markdown => Html =
new MarkdownRender(assetDomain = AssetDomain("lichess1.org").some, header = true)("test")

test("autolinks add rel") {
val md = Markdown("https://example.com")
Expand Down Expand Up @@ -88,3 +89,10 @@ class MarkdownTest extends munit.FunSuite:
"""
)
}
test("anchorlink added for headings") {
assertEquals(
render(Markdown("# heading")),
Html("""<h1><a href="#heading" id="heading"></a>heading</h1>
""")
)
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object Dependencies {
val version = "0.64.8"
val bundle =
("com.vladsch.flexmark" % "flexmark" % version) ::
List("ext-tables", "ext-autolink", "ext-gfm-strikethrough", "html2md-converter").map { ext =>
List("ext-tables", "ext-anchorlink", "ext-autolink", "ext-gfm-strikethrough", "html2md-converter").map { ext =>
"com.vladsch.flexmark" % s"flexmark-$ext" % version
}
}
Expand Down