Parsing markdown with birt designer

Hi there,


 


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?


 


Thanks,


Geert


Comments

  • Hi Geert,


     


    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.


     


    Regards,


    Jeff


    Jeff F.

     

    Customer Support Engineer I

    Website: www.opentext.com

     

    emailsupport-logo-opentext.gif

     

     

     

  • edited February 17

    Also, you can convert the incoming markdown text to HTML using a Java package such flexmark-java (https://github.com/vsch/flexmark-java), commonmark-java, or pegdown ( https://github.com/sirthias/pegdown).


     


    You can perform this conversion, for example as a Computed Column, or in a text report item.


     


    Then, with the converted HTML, you can output as is, or parse further as needed.


     


    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.


     


    For example, pegdown would convert the following markdown "This is *Sparta*" to "<p>This is <em>Sparta</em></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 @ https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.vladsch.flexmark%22%20).


     


    Example code snippet:



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

    Clement Wong
    Principal Analytics Architect

    OpenText Corporation
    http://www.actuate.com | http://www.opentext.com

Sign In or Register to comment.