~jan0sch/smederee

Showing details for patch 6a1ca2b7b4edbd69ee6ed8f6041016a41b678336.
2023-02-17 (Fri), 3:09 PM - Jens Grassel - 6a1ca2b7b4edbd69ee6ed8f6041016a41b678336

Markdown: Add some extensions for markdown rendering.

- anchors for headings
- tables
- task list items
Summary of changes
3 files modified with 55 lines added and 38 lines removed
  • CHANGELOG.md with 4 added and 0 removed lines
  • build.sbt with 43 added and 37 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala with 8 added and 1 removed lines
diff -rN -u old-smederee/build.sbt new-smederee/build.sbt
--- old-smederee/build.sbt	2025-03-01 08:33:19.975338449 +0000
+++ new-smederee/build.sbt	2025-03-01 08:33:19.975338449 +0000
@@ -151,6 +151,9 @@
         library.circeGeneric,
         library.circeParser,
         library.commonMark,
+        library.commonMarkExtHeadingAnchor,
+        library.commonMarkExtTables,
+        library.commonMarkExtTaskListItems,
         library.doobieCore,
         library.doobieHikari,
         library.doobiePostgres,
@@ -340,43 +343,46 @@
       val simpleJavaMail  = "7.8.2"
       val springSecurity  = "6.0.1"
     }
-    val apacheSshdCore       = "org.apache.sshd"              %  "sshd-core"              % Version.apacheSshd
-    val apacheSshdSftp       = "org.apache.sshd"              %  "sshd-sftp"              % Version.apacheSshd
-    val apacheSshdScp        = "org.apache.sshd"              %  "sshd-scp"               % Version.apacheSshd
-    val bouncyCastleProvider = "org.bouncycastle"             %  "bcprov-jdk15to18"       % Version.bouncyCastle
-    val catsCore             = "org.typelevel"                %% "cats-core"              % Version.cats
-    val catsEffect           = "org.typelevel"                %% "cats-effect"            % Version.catsEffect
-    val circeCore            = "io.circe"                     %% "circe-core"             % Version.circe
-    val circeGeneric         = "io.circe"                     %% "circe-generic"          % Version.circe
-    val circeParser          = "io.circe"                     %% "circe-parser"           % Version.circe
-    val commonMark           = "org.commonmark"               %  "commonmark"             % Version.commonMark
-    val doobieCore           = "org.tpolecat"                 %% "doobie-core"            % Version.doobie
-    val doobieHikari         = "org.tpolecat"                 %% "doobie-hikari"          % Version.doobie
-    val doobiePostgres       = "org.tpolecat"                 %% "doobie-postgres"        % Version.doobie
-    val doobieScalaTest      = "org.tpolecat"                 %% "doobie-scalatest"       % Version.doobie
-    val flywayCore           = "org.flywaydb"                 %  "flyway-core"            % Version.flyway
-    val fs2Core              = "co.fs2"                       %% "fs2-core"               % Version.fs2
-    val fs2IO                = "co.fs2"                       %% "fs2-io"                 % Version.fs2
-    val http4sCirce          = "org.http4s"                   %% "http4s-circe"           % Version.http4s
-    val http4sCore           = "org.http4s"                   %% "http4s-core"            % Version.http4s
-    val http4sDsl            = "org.http4s"                   %% "http4s-dsl"             % Version.http4s
-    val http4sEmberServer    = "org.http4s"                   %% "http4s-ember-server"    % Version.http4s
-    val http4sEmberClient    = "org.http4s"                   %% "http4s-ember-client"    % Version.http4s
-    //val http4sTwirl          = "org.http4s"                   %% "http4s-twirl"           % Version.http4s
-    val ip4sCore             = "com.comcast"                  %% "ip4s-core"              % Version.ip4s
-    val jansi                = "com.github.Osiris-Team"       %  "jansi"                  % Version.jansi
-    val jclOverSlf4j         = "org.slf4j"                    %  "jcl-over-slf4j"         % Version.jclOverSlf4j
-    val logback              = "ch.qos.logback"               %  "logback-classic"        % Version.logback
-    val munit                = "org.scalameta"                %% "munit"                  % Version.munit
-    val munitCatsEffect      = "org.typelevel"                %% "munit-cats-effect-3"    % Version.munitCatsEffect
-    val munitDiscipline      = "org.typelevel"                %% "discipline-munit"       % Version.munitDiscipline
-    val munitScalaCheck      = "org.scalameta"                %% "munit-scalacheck"       % Version.munit
-    val osLib                = "com.lihaoyi"                  %% "os-lib"                 % Version.osLib
-    val postgresql           = "org.postgresql"               %  "postgresql"             % Version.postgresql
-    val pureConfig           = "com.github.pureconfig"        %% "pureconfig-core"        % Version.pureConfig
-    val scalaCheck           = "org.scalacheck"               %% "scalacheck"             % Version.scalaCheck
-    val simpleJavaMail       = "org.simplejavamail"           %  "simple-java-mail"       % Version.simpleJavaMail
-    val springSecurityCrypto = "org.springframework.security" %  "spring-security-crypto" % Version.springSecurity
+    val apacheSshdCore             = "org.apache.sshd"              %  "sshd-core"                      % Version.apacheSshd
+    val apacheSshdSftp             = "org.apache.sshd"              %  "sshd-sftp"                      % Version.apacheSshd
+    val apacheSshdScp              = "org.apache.sshd"              %  "sshd-scp"                       % Version.apacheSshd
+    val bouncyCastleProvider       = "org.bouncycastle"             %  "bcprov-jdk15to18"               % Version.bouncyCastle
+    val catsCore                   = "org.typelevel"                %% "cats-core"                      % Version.cats
+    val catsEffect                 = "org.typelevel"                %% "cats-effect"                    % Version.catsEffect
+    val circeCore                  = "io.circe"                     %% "circe-core"                     % Version.circe
+    val circeGeneric               = "io.circe"                     %% "circe-generic"                  % Version.circe
+    val circeParser                = "io.circe"                     %% "circe-parser"                   % Version.circe
+    val commonMark                 = "org.commonmark"               %  "commonmark"                     % Version.commonMark
+    val commonMarkExtHeadingAnchor = "org.commonmark"               %  "commonmark-ext-heading-anchor"  % Version.commonMark
+    val commonMarkExtTables        = "org.commonmark"               %  "commonmark-ext-gfm-tables"      % Version.commonMark
+    val commonMarkExtTaskListItems = "org.commonmark"               %  "commonmark-ext-task-list-items" % Version.commonMark
+    val doobieCore                 = "org.tpolecat"                 %% "doobie-core"                    % Version.doobie
+    val doobieHikari               = "org.tpolecat"                 %% "doobie-hikari"                  % Version.doobie
+    val doobiePostgres             = "org.tpolecat"                 %% "doobie-postgres"                % Version.doobie
+    val doobieScalaTest            = "org.tpolecat"                 %% "doobie-scalatest"               % Version.doobie
+    val flywayCore                 = "org.flywaydb"                 %  "flyway-core"                    % Version.flyway
+    val fs2Core                    = "co.fs2"                       %% "fs2-core"                       % Version.fs2
+    val fs2IO                      = "co.fs2"                       %% "fs2-io"                         % Version.fs2
+    val http4sCirce                = "org.http4s"                   %% "http4s-circe"                   % Version.http4s
+    val http4sCore                 = "org.http4s"                   %% "http4s-core"                    % Version.http4s
+    val http4sDsl                  = "org.http4s"                   %% "http4s-dsl"                     % Version.http4s
+    val http4sEmberServer          = "org.http4s"                   %% "http4s-ember-server"            % Version.http4s
+    val http4sEmberClient          = "org.http4s"                   %% "http4s-ember-client"            % Version.http4s
+    //val http4sTwirl                = "org.http4s"                   %% "http4s-twirl"                   % Version.http4s
+    val ip4sCore                   = "com.comcast"                  %% "ip4s-core"                      % Version.ip4s
+    val jansi                      = "com.github.Osiris-Team"       %  "jansi"                          % Version.jansi
+    val jclOverSlf4j               = "org.slf4j"                    %  "jcl-over-slf4j"                 % Version.jclOverSlf4j
+    val logback                    = "ch.qos.logback"               %  "logback-classic"                % Version.logback
+    val munit                      = "org.scalameta"                %% "munit"                          % Version.munit
+    val munitCatsEffect            = "org.typelevel"                %% "munit-cats-effect-3"            % Version.munitCatsEffect
+    val munitDiscipline            = "org.typelevel"                %% "discipline-munit"               % Version.munitDiscipline
+    val munitScalaCheck            = "org.scalameta"                %% "munit-scalacheck"               % Version.munit
+    val osLib                      = "com.lihaoyi"                  %% "os-lib"                         % Version.osLib
+    val postgresql                 = "org.postgresql"               %  "postgresql"                     % Version.postgresql
+    val pureConfig                 = "com.github.pureconfig"        %% "pureconfig-core"                % Version.pureConfig
+    val scalaCheck                 = "org.scalacheck"               %% "scalacheck"                     % Version.scalaCheck
+    val simpleJavaMail             = "org.simplejavamail"           %  "simple-java-mail"               % Version.simpleJavaMail
+    val springSecurityCrypto       = "org.springframework.security" %  "spring-security-crypto"         % Version.springSecurity
   }
 
 // *****************************************************************************
diff -rN -u old-smederee/CHANGELOG.md new-smederee/CHANGELOG.md
--- old-smederee/CHANGELOG.md	2025-03-01 08:33:19.975338449 +0000
+++ new-smederee/CHANGELOG.md	2025-03-01 08:33:19.975338449 +0000
@@ -22,6 +22,10 @@
 
 ### Added
 
+- extensions to the markdown renderer for:
+   - anchors for headings
+   - table rendering
+   - task list items
 - linkable line number for file viewer
 - support for labels per repository
 - support for milestones per repository
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala	2025-03-01 08:33:19.975338449 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/MarkdownRenderer.scala	2025-03-01 08:33:19.979338445 +0000
@@ -18,6 +18,9 @@
 package de.smederee.hub
 
 import cats.syntax.all._
+import org.commonmark.ext.gfm.tables.TablesExtension
+import org.commonmark.ext.heading.anchor.HeadingAnchorExtension
+import org.commonmark.ext.task.list.items.TaskListItemsExtension
 import org.commonmark.node._
 import org.commonmark.parser.Parser
 import org.commonmark.renderer.html._
@@ -29,6 +32,9 @@
 object MarkdownRenderer {
   private val log = LoggerFactory.getLogger(getClass())
 
+  private val MarkdownExtensions =
+    List(TablesExtension.create(), HeadingAnchorExtension.create(), TaskListItemsExtension.create())
+
   /** Render the given markdown sources and adjust all relative links by prefixing them with the path for the repostiory
     * file browsing (`repo-name/files`).
     *
@@ -41,7 +47,7 @@
     *   A string containing the rendered markdown (HTML).
     */
   def renderRepositoryMarkdownFile(repo: Option[VcsRepository])(markdownSource: String): String = {
-    val parser   = Parser.builder().build()
+    val parser   = Parser.builder().extensions(MarkdownExtensions.asJava).build()
     val markdown = parser.parse(markdownSource)
     val renderer = HtmlRenderer
       .builder()
@@ -49,6 +55,7 @@
         override def create(context: AttributeProviderContext): AttributeProvider = new LinkHrefCorrector(repo)
       })
       .escapeHtml(true)
+      .extensions(MarkdownExtensions.asJava)
       .sanitizeUrls(true)
       .build()
     renderer.render(markdown)