Book Marx: Properly format bookmarks.

Change-Id: Idd6f2c4622d4b1a16c74b2d3af02e637625732fc
diff --git a/build.gradle b/build.gradle
index d7c4fea..5643d46 100644
--- a/build.gradle
+++ b/build.gradle
@@ -75,6 +75,8 @@
 
     implementation 'org.jsoup:jsoup:1.12.1'
 
+    implementation "com.vladsch.flexmark:flexmark-all"
+
     constraints {
         implementation "com.vladmihalcea:hibernate-types-52:${hibernateTypesVersion}"
         implementation "org.mapstruct:mapstruct:${mapstructVersion}"
@@ -83,6 +85,7 @@
         implementation "jakarta.security.jacc:jakarta.security.jacc-api:${jakartaJaccVersion}"
         implementation "net.java.dev.jna:jna:${jnaVersion}"
         implementation "org.bitbucket.b_c:jose4j:${jose4jVersion}"
+        implementation "com.vladsch.flexmark:flexmark-all:${flexmarkVersion}"
     }
 }
 
diff --git a/gradle.properties b/gradle.properties
index 04a46b5..5759eca 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -24,5 +24,6 @@
 jnaVersion = 5.5.0
 jose4jVersion = 0.7.0
 testcontainersVersion = 1.12.4
+flexmarkVersion = 0.60.2
 
 org.gradle.parallel = true
diff --git a/pom.xml b/pom.xml
index 1701c09..5377fe1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,7 @@
     <jakarta-jacc-api.version>1.6.1</jakarta-jacc-api.version>
     <jna.version>5.5.0</jna.version>
     <jsoup.version>1.12.1</jsoup.version>
+    <flexmark.version>0.60.2</flexmark.version>
   </properties>
 
   <dependencyManagement>
@@ -61,6 +62,13 @@
         <version>${jsoup.version}</version>
       </dependency>
 
+      <!-- FlexMark -->
+      <dependency>
+        <groupId>com.vladsch.flexmark</groupId>
+        <artifactId>flexmark-all</artifactId>
+        <version>${flexmark.version}</version>
+      </dependency>
+
       <!-- JNA -->
       <dependency>
         <groupId>net.java.dev.jna</groupId>
@@ -203,6 +211,12 @@
       <artifactId>jsoup</artifactId>
     </dependency>
 
+    <!-- FlexMark -->
+    <dependency>
+      <groupId>com.vladsch.flexmark</groupId>
+      <artifactId>flexmark-all</artifactId>
+    </dependency>
+
     <!-- JOSE for Java -->
     <dependency>
       <groupId>org.bitbucket.b_c</groupId>
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
index 8985948..6bbd3a6 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
@@ -9,6 +9,7 @@
 import javax.persistence.FetchType;
 import javax.persistence.JoinColumn;
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
 @Entity
 @Table(name = "bookmarks", schema = "benki")
@@ -30,4 +31,9 @@
       joinColumns = @JoinColumn(name = "bookmark"))
   @Column(name = "tag")
   public Set<String> tags;
+
+  @Transient
+  public String getDescriptionHtml() {
+    return new MarkdownConverter().htmlify(description);
+  }
 }
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/MarkdownConverter.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/MarkdownConverter.java
index 0a09b40..1fae62c 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/MarkdownConverter.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/MarkdownConverter.java
@@ -1,5 +1,46 @@
 package eu.mulk.mulkcms2.benki.bookmarks;
 
+import com.vladsch.flexmark.ext.abbreviation.AbbreviationExtension;
+import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
+import com.vladsch.flexmark.ext.definition.DefinitionExtension;
+import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
+import com.vladsch.flexmark.ext.tables.TablesExtension;
+import com.vladsch.flexmark.ext.typographic.TypographicExtension;
+import com.vladsch.flexmark.html.HtmlRenderer;
+import com.vladsch.flexmark.parser.Parser;
+import com.vladsch.flexmark.util.data.MutableDataSet;
+import java.util.Arrays;
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
 public class MarkdownConverter {
 
+  private final Parser parser;
+  private final HtmlRenderer renderer;
+
+  MarkdownConverter() {
+    var options = new MutableDataSet();
+    options.set(
+        Parser.EXTENSIONS,
+        Arrays.asList(
+            TablesExtension.create(),
+            StrikethroughExtension.create(),
+            AbbreviationExtension.create(),
+            AutolinkExtension.create(),
+            DefinitionExtension.create(),
+            TypographicExtension.create()));
+    options.set(Parser.FENCED_CODE_BLOCK_PARSER, true);
+    options.set(HtmlRenderer.SOFT_BREAK, "\n");
+    options.set(HtmlRenderer.HARD_BREAK, "<br />\n");
+    options.set(TypographicExtension.ENABLE_SMARTS, true);
+    options.set(TypographicExtension.ENABLE_QUOTES, true);
+
+    this.parser = Parser.builder(options).build();
+    this.renderer = HtmlRenderer.builder(options).build();
+  }
+
+  public String htmlify(String markdown) {
+    var parsedDocument = parser.parse(markdown);
+    return renderer.render(parsedDocument);
+  }
 }
diff --git a/src/main/resources/META-INF/resources/cms2/base.css b/src/main/resources/META-INF/resources/cms2/base.css
index fd224de..bb5d200 100644
--- a/src/main/resources/META-INF/resources/cms2/base.css
+++ b/src/main/resources/META-INF/resources/cms2/base.css
@@ -112,6 +112,7 @@
   background-color: var(--main-bg-color);
   padding: 10px;
   border-left: 1px solid lightgray;
+  overflow: scroll;
 }
 
 body > footer {
@@ -127,4 +128,20 @@
 
 h1.bookmark-title {
   font-size: 1em;
-}
\ No newline at end of file
+  margin: 0;
+  padding: 0;
+}
+
+.bookmark-info {
+  font-style: italic;
+  font-size: smaller;
+  margin: 0;
+  padding: 0;
+}
+
+article.bookmark {
+  margin: 0.5em 0;
+  border: 1px solid lightcoral;
+  padding: 0.3em;
+  background: #fee;
+}
diff --git a/src/main/resources/templates/benki/bookmarks/bookmarkList.html b/src/main/resources/templates/benki/bookmarks/bookmarkList.html
index 4ad97fd..0d392c8 100644
--- a/src/main/resources/templates/benki/bookmarks/bookmarkList.html
+++ b/src/main/resources/templates/benki/bookmarks/bookmarkList.html
@@ -15,14 +15,14 @@
     <article class="bookmark">
       <header>
         <a href="{uri}"><h1 class="bookmark-title">{title}</h1></a>
-        <div>
+        <div class="bookmark-info">
           <time datetime="{date.htmlDateTime}">{date.humanDateTime}</time>
           <span class="bookmark-owner">{owner.firstName} {owner.lastName}</span>
         </div>
       </header>
 
       <section class="bookmark-description">
-        {description}
+        {descriptionHtml.raw}
       </section>
     </article>
   {/with}