Skip to content

Commit c9d1e31

Browse files
committed
Use flexmark-java instead of pegdown
1 parent 0d90edb commit c9d1e31

7 files changed

Lines changed: 36 additions & 28 deletions

File tree

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.junichi11</groupId>
55
<artifactId>netbeans-github-issues</artifactId>
6-
<version>0.3.0</version>
6+
<version>0.3.1-SNAPSHOT</version>
77
<packaging>nbm</packaging>
88
<build>
99
<plugins>
@@ -88,11 +88,6 @@
8888
<artifactId>org-openide-dialogs</artifactId>
8989
<version>${netbeans.api.version}</version>
9090
</dependency>
91-
<dependency>
92-
<groupId>org.pegdown</groupId>
93-
<artifactId>pegdown</artifactId>
94-
<version>1.6.0</version>
95-
</dependency>
9691
<dependency>
9792
<groupId>org.eclipse.mylyn.github</groupId>
9893
<artifactId>org.eclipse.egit.github.core</artifactId>
@@ -175,6 +170,11 @@
175170
<artifactId>org-openide-windows</artifactId>
176171
<version>${netbeans.api.version}</version>
177172
</dependency>
173+
<dependency>
174+
<groupId>com.vladsch.flexmark</groupId>
175+
<artifactId>flexmark-all</artifactId>
176+
<version>0.26.4</version>
177+
</dependency>
178178
</dependencies>
179179
<properties>
180180
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/com/junichi11/netbeans/modules/github/issues/GitHubIssues.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
import org.netbeans.modules.bugtracking.issuetable.IssueNode;
5656
import org.netbeans.modules.bugtracking.spi.BugtrackingSupport;
5757
import org.openide.util.RequestProcessor;
58-
import org.pegdown.Extensions;
59-
import org.pegdown.PegDownProcessor;
6058

6159
/**
6260
*
@@ -74,7 +72,6 @@ public final class GitHubIssues {
7472
private GitHubRepositoryProvider repositoryProvider;
7573
private IssueNode.ChangesProvider<GitHubIssue> changesProvider;
7674
private RequestProcessor rp;
77-
private PegDownProcessor pegDownProcessor;
7875
// colors
7976
public static final Color GREEN_COLOR = Color.decode("#6cc644"); // NOI18N
8077
public static final Color RED_COLOR = Color.decode("#bd2c00"); // NOI18N
@@ -171,11 +168,4 @@ public String getRecentChanges(GitHubIssue issue) {
171168
return changesProvider;
172169
}
173170

174-
public PegDownProcessor getPegDownProcessor() {
175-
if (pegDownProcessor == null) {
176-
pegDownProcessor = new PegDownProcessor(Extensions.ALL);
177-
}
178-
return pegDownProcessor;
179-
}
180-
181171
}

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/GitHubIssue.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
package com.junichi11.netbeans.modules.github.issues.issue;
4343

4444
import com.junichi11.netbeans.modules.github.issues.GitHubIssueState;
45-
import com.junichi11.netbeans.modules.github.issues.GitHubIssues;
4645
import com.junichi11.netbeans.modules.github.issues.GitHubIssuesConfig;
4746
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepository;
4847
import com.junichi11.netbeans.modules.github.issues.utils.DateUtils;
48+
import com.junichi11.netbeans.modules.github.issues.utils.StringUtils;
4949
import com.junichi11.netbeans.modules.github.issues.utils.UiUtils;
5050
import java.beans.PropertyChangeListener;
5151
import java.beans.PropertyChangeSupport;
@@ -75,7 +75,6 @@
7575
import org.netbeans.modules.bugtracking.spi.IssueStatusProvider;
7676
import org.netbeans.modules.bugtracking.spi.IssueStatusProvider.Status;
7777
import org.openide.util.NbBundle;
78-
import org.pegdown.PegDownProcessor;
7978

8079
/**
8180
*
@@ -338,9 +337,8 @@ public Comment editComment(Comment comment, String editedBody) {
338337
comment.setBody(editedBody);
339338
Comment editComment = GitHubIssueSupport.editComment(getRepository(), comment);
340339
if (editComment != null) {
341-
PegDownProcessor processor = GitHubIssues.getInstance().getPegDownProcessor();
342340
String body = editComment.getBody();
343-
String bodyHtml = processor.markdownToHtml(body);
341+
String bodyHtml = StringUtils.markdownToHtml(body);
344342
comment.setBodyHtml(String.format("<html>%s</html>", bodyHtml)); // NOI18N
345343
comment.setBody(body);
346344
comment.setUpdatedAt(editComment.getUpdatedAt());

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/CommentTabbedPanel.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141
*/
4242
package com.junichi11.netbeans.modules.github.issues.issue.ui;
4343

44-
import com.junichi11.netbeans.modules.github.issues.GitHubIssues;
44+
import com.junichi11.netbeans.modules.github.issues.utils.StringUtils;
4545
import java.awt.Component;
4646
import java.awt.Dialog;
4747
import java.awt.Font;
4848
import org.openide.DialogDescriptor;
4949
import org.openide.DialogDisplayer;
50-
import org.pegdown.PegDownProcessor;
5150

5251
/**
5352
*
@@ -184,8 +183,7 @@ public void stateChanged(javax.swing.event.ChangeEvent evt) {
184183
private void commentTabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_commentTabbedPaneStateChanged
185184
Component selectedComponent = commentTabbedPane.getSelectedComponent();
186185
if (selectedComponent == commentPreviewPanel) {
187-
PegDownProcessor processor = GitHubIssues.getInstance().getPegDownProcessor();
188-
String html = processor.markdownToHtml(commentWriteTextArea.getText());
186+
String html = StringUtils.markdownToHtml(commentWriteTextArea.getText());
189187
commentPreviewEditorPane.setText(html);
190188
}
191189
}//GEN-LAST:event_commentTabbedPaneStateChanged

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/CreatePullRequestPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
package com.junichi11.netbeans.modules.github.issues.issue.ui;
4343

4444
import com.junichi11.netbeans.modules.github.issues.GitHubIcons;
45+
import com.junichi11.netbeans.modules.github.issues.utils.StringUtils;
4546
import java.awt.Component;
4647
import java.awt.event.ItemEvent;
4748
import java.awt.event.ItemListener;
@@ -58,7 +59,6 @@
5859
import org.eclipse.egit.github.core.Repository;
5960
import org.eclipse.egit.github.core.RepositoryBranch;
6061
import org.openide.util.ChangeSupport;
61-
import org.parboiled.common.StringUtils;
6262

6363
/**
6464
*

src/main/java/com/junichi11/netbeans/modules/github/issues/issue/ui/GitHubIssuePanel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.junichi11.netbeans.modules.github.issues.repository.GitHubRepository;
6060
import com.junichi11.netbeans.modules.github.issues.ui.AttributesListCellRenderer;
6161
import com.junichi11.netbeans.modules.github.issues.utils.GitHubIssuesUtils;
62+
import com.junichi11.netbeans.modules.github.issues.utils.StringUtils;
6263
import com.junichi11.netbeans.modules.github.issues.utils.UiUtils;
6364
import java.awt.Color;
6465
import java.awt.Dimension;
@@ -107,7 +108,6 @@
107108
import org.openide.util.ChangeSupport;
108109
import org.openide.util.NbBundle;
109110
import org.openide.util.RequestProcessor;
110-
import org.pegdown.PegDownProcessor;
111111

112112
/**
113113
*
@@ -411,10 +411,9 @@ public void update() {
411411
List<Comment> comments = gitHubIssue.getComments();
412412
// set count
413413
commentsCollapsibleSectionPanel.setLabel(Bundle.GitHubIssuePanel_comment_count(comments.size()));
414-
PegDownProcessor processor = GitHubIssues.getInstance().getPegDownProcessor();
415414
for (Comment comment : comments) {
416415
String body = comment.getBody();
417-
String bodyHtml = processor.markdownToHtml(body);
416+
String bodyHtml = StringUtils.markdownToHtml(body);
418417
comment.setBodyHtml(String.format("<html>%s</html>", bodyHtml)); // NOI18N
419418
}
420419
commentsPanel.addComments(comments, repository);

src/main/java/com/junichi11/netbeans/modules/github/issues/utils/StringUtils.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
*/
4242
package com.junichi11.netbeans.modules.github.issues.utils;
4343

44+
import com.vladsch.flexmark.ast.Node;
45+
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
46+
import com.vladsch.flexmark.ext.tables.TablesExtension;
47+
import com.vladsch.flexmark.html.HtmlRenderer;
48+
import com.vladsch.flexmark.parser.Parser;
49+
import com.vladsch.flexmark.util.options.MutableDataSet;
50+
import java.util.Arrays;
4451
import java.util.List;
4552
import java.util.StringTokenizer;
4653

@@ -50,9 +57,25 @@
5057
*/
5158
public final class StringUtils {
5259

60+
private static final MutableDataSet OPTIONS = new MutableDataSet();
61+
private static final Parser PARSER = Parser.builder(OPTIONS).build();
62+
private static final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
63+
64+
static {
65+
OPTIONS.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()));
66+
}
67+
5368
private StringUtils() {
5469
}
5570

71+
public static String markdownToHtml(String text) {
72+
if (text == null) {
73+
return ""; // NOI18N
74+
}
75+
Node document = PARSER.parse(text);
76+
return RENDERER.render(document);
77+
}
78+
5679
/**
5780
* Check whether specified string is {@code null} or empty.
5881
*

0 commit comments

Comments
 (0)