Skip to content

Use flexmark instead of markdownj #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
17 changes: 13 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>26.0.0</version>
<version>29.2.1</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -84,6 +84,8 @@ Wisconsin-Madison.</license.copyrightOwners>

<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>deploy-to-scijava</releaseProfiles>

<flexmark.version>0.62.2</flexmark.version>
</properties>

<dependencies>
Expand All @@ -95,9 +97,16 @@ Wisconsin-Madison.</license.copyrightOwners>

<!-- Third-party dependencies -->
<dependency>
<groupId>org.markdownj</groupId>
<artifactId>markdownj</artifactId>
<version>0.3.0-1.0.2b4</version>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>${flexmark.version}</version>
</dependency>

<!-- Test scope dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@

package org.scijava.plugins.text.markdown;

import com.petebevin.markdown.MarkdownProcessor;

import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import java.util.Arrays;
import java.util.List;

import org.scijava.plugin.Plugin;
import org.scijava.text.AbstractTextFormat;
import org.scijava.text.TextFormat;

/**
* Text format for <a
* href="http://daringfireball.net/projects/markdown/">Markdown</a>.
* Text format for
* <a href="http://daringfireball.net/projects/markdown/">Markdown</a>.
*
* @author Curtis Rueden
*/
Expand All @@ -55,8 +55,11 @@ public List<String> getExtensions() {

@Override
public String asHTML(final String text) {
final MarkdownProcessor markdown = new MarkdownProcessor();
return markdown.markdown(text);
Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();

Node node = parser.parse(text);
return renderer.render(node);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

package org.scijava.plugins.text.markdown;

import static org.junit.Assert.assertEquals;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.scijava.Context;
import org.scijava.io.handle.DataHandleService;
import org.scijava.text.TextService;

public class MarkdownTextFormatTest {

private static Context context;

private final String markdown = "ImageJ*2* uses **SciJava**\n";
private final String expected =
"<p>ImageJ<em>2</em> uses <strong>SciJava</strong></p>\n";

@BeforeClass
public static void setUp() {
context = new Context(TextService.class, DataHandleService.class);
}

@AfterClass
public static void tearDown() {
context.dispose();
}

@Test
public void testMarkdownToHTML() {
MarkdownTextFormat format = new MarkdownTextFormat();
String html = format.asHTML(markdown);
assertEquals("Format markdown as HTML", expected, html);
}

@Test
public void testTextServiceMarkdown() throws IOException {
File tmpFile = File.createTempFile("MarkdownTextFormatTest", ".md");
tmpFile.deleteOnExit();

try (BufferedWriter writer = new BufferedWriter(new FileWriter(tmpFile))) {
writer.write(markdown);
}
TextService textService = context.getService(TextService.class);
String html = textService.asHTML(tmpFile);
assertEquals("Handler for Markdown format", MarkdownTextFormat.class,
textService.getHandler(tmpFile).getClass());
assertEquals("Markdown converted from file", "<html><body>" + expected +
"</body></html>", html);
}
}