Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Last active March 1, 2017 11:33
Show Gist options
  • Save dmikurube/ca2b3e53bc9f6acf1baa474401cb6dae to your computer and use it in GitHub Desktop.
Save dmikurube/ca2b3e53bc9f6acf1baa474401cb6dae to your computer and use it in GitHub Desktop.
Trying Markdown libraries in Java
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
// https://github.com/vsch/flexmark-java
compile group: 'com.vladsch.flexmark', name: 'flexmark', version: '0.15.4'
compile group: 'com.vladsch.flexmark', name: 'flexmark-util', version: '0.15.4'
// https://github.com/atlassian/commonmark-java
compile group: 'com.atlassian.commonmark', name: 'commonmark', version: '0.8.0'
// Pegdown has reached its end of life.
// https://github.com/sirthias/pegdown
compile group: 'org.pegdown', name: 'pegdown', version: '1.6.0'
// https://code.google.com/archive/p/markdown4j/
compile group: 'org.commonjava.googlecode.markdown4j', name: 'markdown4j', version: '2.2-cj-1.1'
// https://github.com/myabc/markdownj
compile group: 'org.markdownj', name: 'markdownj', version: '0.4'
// https://github.com/lruiz/MarkdownPapers
compile group: 'org.tautua.markdownpapers', name: 'markdownpapers-core', version: '1.4.4'
// https://github.com/rjeschke/txtmark
compile group: 'com.github.rjeschke', name: 'txtmark', version: '0.13'
// https://github.com/gitbucket/markedj
compile group: 'io.github.gitbucket', name: 'markedj', version: '1.0.9'
testCompile 'junit:junit:4.+'
}
sourceSets {
main {
java {
srcDir '.'
exclude 'Test*.java'
}
}
test {
java {
srcDir '.'
include 'Test*.java'
}
}
}
test {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
task run(type:JavaExec) {
main = project.hasProperty('main') ? project.getProperty('main') : 'MarkdownExamples'
classpath = sourceSets.main.runtimeClasspath
}
import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.parser.ParserEmulationProfile;
import com.vladsch.flexmark.util.options.MutableDataHolder;
import com.vladsch.flexmark.util.options.MutableDataSet;
public class MarkdownExamples {
public static void main(String[] args) {
System.out.println(flexmark("This is *Sparta*"));
}
public static String flexmarkToHtml(String markdown) {
MutableDataHolder options = new MutableDataSet();
options.setFrom(ParserEmulationProfile.MARKDOWN);
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(markdown);
return renderer.render(document);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment