6
6
7
7
import static org .jsoup .nodes .Document .OutputSettings .Syntax .html ;
8
8
9
+ import java .util .regex .Matcher ;
10
+ import java .util .regex .Pattern ;
9
11
import org .commonmark .node .BlockQuote ;
10
12
import org .commonmark .node .FencedCodeBlock ;
11
13
import org .commonmark .node .Heading ;
@@ -52,8 +54,11 @@ public static MarkdownToRstDocConverter getInstance() {
52
54
}
53
55
54
56
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>" );
57
62
Document document = Jsoup .parse (html );
58
63
RstNodeVisitor visitor = new RstNodeVisitor ();
59
64
document .body ().traverse (visitor );
@@ -75,7 +80,7 @@ public void head(Node node, int depth) {
75
80
int secondColonIndex = text .indexOf (':' , 1 );
76
81
writer .write (text .substring (0 , secondColonIndex + 1 ));
77
82
//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
79
84
// </p>). Since we standardize to html above, that <p> tag
80
85
// starts a newline. We account for that with this if/else
81
86
// statement, but we should refactor this in the future to
0 commit comments