enables markdown support in issue descriptions and comments - fixes #10

Sat, 05 Dec 2020 13:05:00 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 05 Dec 2020 13:05:00 +0100
changeset 162
2adc8623dd89
parent 161
3d9218457b62
child 163
a5b9632729b6

enables markdown support in issue descriptions and comments - fixes #10

build.gradle.kts file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/viewmodel/IssueDetailView.java file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/issue-view.jsp file | annotate | diff | comparison | revisions
src/main/webapp/lightpit.css file | annotate | diff | comparison | revisions
--- a/build.gradle.kts	Wed Nov 25 11:17:39 2020 +0100
+++ b/build.gradle.kts	Sat Dec 05 13:05:00 2020 +0100
@@ -32,6 +32,7 @@
                 implementation("org.slf4j:slf4j-api:${slf4jVersion}")
                 implementation("org.apache.logging.log4j:log4j-core:${log4jVersion}")
                 implementation("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}")
+                implementation("com.vladsch.flexmark:flexmark-all:0.62.2")
             }
         }
     }
--- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Wed Nov 25 11:17:39 2020 +0100
+++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java	Sat Dec 05 13:05:00 2020 +0100
@@ -72,7 +72,7 @@
         }
     }
 
-    private void populate(ProjectView viewModel, PathParameters pathParameters, DaoProvider dao) throws SQLException {
+    private void populate(ProjectView viewModel, PathParameters pathParameters, DaoProvider dao) {
         final var projectDao = dao.getProjectDao();
         final var versionDao = dao.getVersionDao();
         final var componentDao = dao.getComponentDao();
@@ -480,6 +480,8 @@
         viewModel.setIssue(issue);
         viewModel.setComments(issueDao.listComments(issue));
 
+        viewModel.processMarkdown();
+
         forwardView(req, resp, viewModel, "issue-view");
     }
 
--- a/src/main/java/de/uapcore/lightpit/viewmodel/IssueDetailView.java	Wed Nov 25 11:17:39 2020 +0100
+++ b/src/main/java/de/uapcore/lightpit/viewmodel/IssueDetailView.java	Sat Dec 05 13:05:00 2020 +0100
@@ -1,8 +1,14 @@
 package de.uapcore.lightpit.viewmodel;
 
+import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
+import com.vladsch.flexmark.ext.tables.TablesExtension;
+import com.vladsch.flexmark.html.HtmlRenderer;
+import com.vladsch.flexmark.parser.Parser;
+import com.vladsch.flexmark.util.data.MutableDataSet;
 import de.uapcore.lightpit.entities.Issue;
 import de.uapcore.lightpit.entities.IssueComment;
 
+import java.util.Arrays;
 import java.util.List;
 
 public class IssueDetailView extends ProjectView {
@@ -25,4 +31,17 @@
     public void setComments(List<IssueComment> comments) {
         this.comments = comments;
     }
+
+    public void processMarkdown() {
+        final var options = new MutableDataSet()
+                .set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()))
+                .toImmutable();
+        final var parser = Parser.builder(options).build();
+        final var renderer = HtmlRenderer.builder(options).build();
+
+        issue.setDescription(renderer.render(parser.parse(issue.getDescription())));
+        for (var comment : comments) {
+            comment.setComment(renderer.render(parser.parse(comment.getComment())));
+        }
+    }
 }
--- a/src/main/webapp/WEB-INF/jsp/issue-view.jsp	Wed Nov 25 11:17:39 2020 +0100
+++ b/src/main/webapp/WEB-INF/jsp/issue-view.jsp	Sat Dec 05 13:05:00 2020 +0100
@@ -97,7 +97,9 @@
     <tr>
         <th class="vtop"><fmt:message key="issue.description"/></th>
         <td>
-            <textarea readonly rows="10"><c:out value="${issue.description}"/></textarea>
+            <div class="markdown-styled">
+            ${issue.description}
+            </div>
         </td>
     </tr>
     <tr>
@@ -183,8 +185,8 @@
                     <!-- TODO: update count -->
                 </c:if>
             </div>
-            <div class="medskip">
-                <c:out value="${comment.comment}"/>
+            <div class="medskip markdown-styled">
+                ${comment.comment}
             </div>
         </div>
     </c:forEach>
--- a/src/main/webapp/lightpit.css	Wed Nov 25 11:17:39 2020 +0100
+++ b/src/main/webapp/lightpit.css	Sat Dec 05 13:05:00 2020 +0100
@@ -269,3 +269,21 @@
 .row > div {
     display: table-cell;
 }
+
+/* MARKDOWN STYLES */
+
+div.markdown-styled p:first-child {
+    margin-top: 0;
+}
+
+div.markdown-styled table {
+    border-collapse: collapse;
+}
+
+div.markdown-styled td,
+div.markdown-styled th {
+    padding: 0.25em;
+    border-style: solid;
+    border-color: darkgray;
+    border-width: 1pt;
+}

mercurial