|
2 | 2 |
|
3 | 3 | import org.commonmark.ext.gfm.alerts.Alert; |
4 | 4 | import org.commonmark.ext.gfm.alerts.AlertTitle; |
5 | | -import org.commonmark.node.HtmlInline; |
6 | 5 | import org.commonmark.node.Node; |
7 | | -import org.commonmark.node.Text; |
8 | 6 | import org.commonmark.renderer.html.HtmlNodeRendererContext; |
9 | 7 | import org.commonmark.renderer.html.HtmlWriter; |
10 | 8 |
|
@@ -40,21 +38,6 @@ protected void renderAlert(Alert alert) { |
40 | 38 | htmlWriter.tag("p", context.extendAttributes(alert, "p", Map.of("class", "markdown-alert-title"))); |
41 | 39 | var first = alert.getFirstChild(); |
42 | 40 | if (first instanceof AlertTitle) { |
43 | | - /* |
44 | | - * If the alert title only contains HTML comments like this: |
45 | | - * |
46 | | - * > [!TIP] <!-- This won't appear --> <!---> <!-- Neither will this --> |
47 | | - * > Body text |
48 | | - * |
49 | | - * Then the reader will see a blank title. In this case, it's better |
50 | | - * to render the default title (but keep the comments for accuracy). |
51 | | - * |
52 | | - * These comments will be visible when rendered to other formats like |
53 | | - * Markdown, so this is only relevant for the HTML renderer. |
54 | | - */ |
55 | | - if (isCommentOnlyTitle(first)) { |
56 | | - htmlWriter.text(getAlertTitle(type)); |
57 | | - } |
58 | 41 | renderChildren(first); |
59 | 42 | } else { |
60 | 43 | htmlWriter.text(getAlertTitle(type)); |
@@ -90,38 +73,6 @@ private String getAlertTitle(String type) { |
90 | 73 | } |
91 | 74 | } |
92 | 75 |
|
93 | | - private boolean isCommentOnlyTitle(Node title) { |
94 | | - var node = title.getFirstChild(); |
95 | | - if (node == null) { |
96 | | - return false; |
97 | | - } |
98 | | - while (node != null) { |
99 | | - if (node instanceof HtmlInline) { |
100 | | - if (!isHtmlComment((HtmlInline) node)) { |
101 | | - return false; |
102 | | - } |
103 | | - } else if (node instanceof Text) { |
104 | | - if (!((Text) node).getLiteral().trim().isEmpty()) { |
105 | | - return false; |
106 | | - } |
107 | | - } else { |
108 | | - return false; |
109 | | - } |
110 | | - node = node.getNext(); |
111 | | - } |
112 | | - return true; |
113 | | - } |
114 | | - |
115 | | - private boolean isHtmlComment(HtmlInline htmlInline) { |
116 | | - var literal = htmlInline.getLiteral(); |
117 | | - if (literal == null || !literal.startsWith("<!--")) { |
118 | | - return false; |
119 | | - } |
120 | | - return literal.equals("<!-->") |
121 | | - || literal.equals("<!--->") |
122 | | - || literal.endsWith("-->"); |
123 | | - } |
124 | | - |
125 | 76 | private void renderChildren(Node parent) { |
126 | 77 | var node = parent.getFirstChild(); |
127 | 78 | while (node != null) { |
|
0 commit comments