Home
Analytics
Parsing markdown with birt designer
Gertenbol
<p>Hi there,</p>
<p> </p>
<p>I'm using Birt designer in Eclipse. The application I'm fetching data from is using markdown. I have been looking for ways to create bullet lists based on the markdown *. Any ideas on how to do this?</p>
<p> </p>
<p>Thanks,</p>
<p>Geert</p>
Find more posts tagged with
Comments
jfranken
<p>Hi Geert,</p>
<p> </p>
<p>I haven't used markdown, but the attached example shows how to turn "*" bullets into an html list. There is probably a more efficient way to write the code, but hopefully this example will get you started.</p>
<p> </p>
<p>Regards,</p>
<p>Jeff</p>
Clement Wong
<p>Also, you can convert the incoming markdown text to HTML using a Java package such flexmark-java (<a data-ipb='nomediaparse' href='
https://github.com/vsch/flexmark-java'>https://github.com/vsch/flexmark-java</a>)
, commonmark-java, or pegdown ( <a data-ipb='nomediaparse' href='
https://github.com/sirthias/pegdown'>https://github.com/sirthias/pegdown</a>).</p>
;
<p> </p>
<p>You can perform this conversion, for example as a Computed Column, or in a text report item.</p>
<p> </p>
<p>Then, with the converted HTML, you can output as is, or parse further as needed.</p>
<p> </p>
<p>I've used the pegdown package in a BIRT report. You'll need to include its dependencies (asm-all-5.0.3.jar, parboiled-core-1.1.7.jar, parboiled-java-1.1.7.jar) and the main package, pegdown-1.6.0.jar as part of the report's resources.</p>
<p> </p>
<p>For example, pegdown would convert the following markdown "This is *Sparta*" to "<p>This is <em>Sparta</em></p>".</p>
<p> </p>
<p>I also have tried flexmark-java (latest version 0.15.0) and it works too. The JARs included needed were: flexmark-0.15.0.jar, flexmark-util-0.15.0.jar and flexmark-html-parser-0.15.0.jar (downloaded @ <a data-ipb='nomediaparse' href='
https://search.maven.org/#search|ga|1|g:"com.vladsch.flexmark" ).'>https://search.maven.org/#search|ga|1|g:"com.vladsch.flexmark" ).</a></p>
;
<p> </p>
<p>Example code snippet:</p>
<pre class="_prettyXprint _lang-">
importPackage( Packages.com.vladsch.flexmark.parser );
importPackage( Packages.com.vladsch.flexmark.html );
var parser = Parser.builder().build();
var document = parser.parse("This is *Sparta*");
var renderer = HtmlRenderer.builder().build();
var convertedText = renderer.render(document); // "<p>This is <em>Sparta</em></p>"
//I am using commercial BIRT to write out to the log file to see the output.
//
//var logger = java.util.logging.Logger.getLogger("birt.report.logger");
//logger.warning (convertedText);
</pre>