vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.21k stars 260 forks source link

Question: Using flexmark to render markdown in a javafx application #591

Open kinglighthill opened 9 months ago

kinglighthill commented 9 months ago

I'm currently working on an e-learning application developed with JavaFX for Windows and macOS. I have been trying to use Flexmark to render some markdown text but I don't understand how to use it. Can it be you in Javafx or is it meant only for Java Swing? Again I have some latex I would also want to render, Is there an existing extension for it? Sorry if this question is redundant, I have gone through most of the issues and the repo and still have not found any helpful solution but I have a strong feeling that this library can help me. Thanks.

thmarx commented 8 months ago

Since JavaFx only uses Java, this shouldn't be a problem. Just render markdown into a string (see code below) and use a WebView to display the html.

Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();

// You can re-use parser and renderer instances
Node document = parser.parse("This is *Sparta*");
String html = renderer.render(document);