66
77import static org .jsoup .nodes .Document .OutputSettings .Syntax .html ;
88
9+ import java .util .regex .Matcher ;
10+ import java .util .regex .Pattern ;
911import org .commonmark .node .BlockQuote ;
1012import org .commonmark .node .FencedCodeBlock ;
1113import org .commonmark .node .Heading ;
@@ -52,8 +54,11 @@ public static MarkdownToRstDocConverter getInstance() {
5254 }
5355
5456 public String convertCommonmarkToRst (String commonmark ) {
55- String html =
56- HtmlRenderer .builder ().escapeHtml (false ).build ().render (MARKDOWN_PARSER .parse (commonmark ));
57+ String html = HtmlRenderer .builder ().escapeHtml (false ).build ().render (MARKDOWN_PARSER .parse (commonmark ));
58+ //Replace the outer HTML paragraph tag with a div tag
59+ Pattern pattern = Pattern .compile ("^<p>(.*)</p>$" , Pattern .DOTALL );
60+ Matcher matcher = pattern .matcher (html );
61+ html = matcher .replaceAll ("<div>$1</div>" );
5762 Document document = Jsoup .parse (html );
5863 RstNodeVisitor visitor = new RstNodeVisitor ();
5964 document .body ().traverse (visitor );
@@ -75,7 +80,7 @@ public void head(Node node, int depth) {
7580 int secondColonIndex = text .indexOf (':' , 1 );
7681 writer .write (text .substring (0 , secondColonIndex + 1 ));
7782 //TODO right now the code generator gives us a mixture of
78- // commonmark and HTML (for instance :param xyz: <p> docs
83+ // RST and HTML (for instance :param xyz: <p> docs
7984 // </p>). Since we standardize to html above, that <p> tag
8085 // starts a newline. We account for that with this if/else
8186 // statement, but we should refactor this in the future to
0 commit comments