flexmark-java icon indicating copy to clipboard operation
flexmark-java copied to clipboard

Question: Using flexmark to render markdown in a javafx application

Open kinglighthill opened this issue 1 year ago • 1 comments

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.

kinglighthill avatar Sep 12 '23 03:09 kinglighthill

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);

thmarx avatar Oct 25 '23 11:10 thmarx