aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/terminaldweller/doc/Md.java
blob: be0c447c859210b74a1e4b743bbbe4914acb2af3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.terminaldweller.doc;

import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;

/** The markdown class which provides the markdown parser. */
public class Md {
  /**
   * Parses a markdown string and returns the result in html.
   *
   * @param markdown the string containing the markdown string.
   * @return the rendered markdown document in html.
   */
  public String mdparseService(String markdown) {
    Parser parser = parser.builder().build();
    Node document = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    return renderer.render(document);
  }
}