Skip to content

Commit 348d18b

Browse files
committed
Remove HTML Comment Handling
1 parent def81c3 commit 348d18b

2 files changed

Lines changed: 0 additions & 67 deletions

File tree

commonmark-ext-gfm-alerts/src/main/java/org/commonmark/ext/gfm/alerts/internal/AlertHtmlNodeRenderer.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import org.commonmark.ext.gfm.alerts.Alert;
44
import org.commonmark.ext.gfm.alerts.AlertTitle;
5-
import org.commonmark.node.HtmlInline;
65
import org.commonmark.node.Node;
7-
import org.commonmark.node.Text;
86
import org.commonmark.renderer.html.HtmlNodeRendererContext;
97
import org.commonmark.renderer.html.HtmlWriter;
108

@@ -40,21 +38,6 @@ protected void renderAlert(Alert alert) {
4038
htmlWriter.tag("p", context.extendAttributes(alert, "p", Map.of("class", "markdown-alert-title")));
4139
var first = alert.getFirstChild();
4240
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-
}
5841
renderChildren(first);
5942
} else {
6043
htmlWriter.text(getAlertTitle(type));
@@ -90,38 +73,6 @@ private String getAlertTitle(String type) {
9073
}
9174
}
9275

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-
12576
private void renderChildren(Node parent) {
12677
var node = parent.getFirstChild();
12778
while (node != null) {

commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsTest.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,6 @@ public void customTitleWithComment() {
184184
"</div>\n");
185185
}
186186

187-
@Test
188-
public void customTitleWithOnlyCommentFallsBackToDefaultTitle() {
189-
assertRenderingCustomTitles("> [!TIP] <!-- This won't appear --> <!-- This won't either -->\n> Body text",
190-
"<div class=\"markdown-alert markdown-alert-tip\" data-alert-type=\"tip\">\n" +
191-
"<p class=\"markdown-alert-title\">Tip<!-- This won't appear --> <!-- This won't either --></p>\n" +
192-
"<p>Body text</p>\n" +
193-
"</div>\n");
194-
}
195-
196187
@Test
197188
public void customTitleWithInlineFormatting() {
198189
assertRenderingCustomTitles("> [!NOTE] Custom _title <ins>with **formatting**</ins>_\n> Note with a custom title",
@@ -264,15 +255,6 @@ public void onlyTrailingWhitespaceIsNotCustomTitle() {
264255
"</div>\n");
265256
}
266257

267-
@Test
268-
public void onlyHtmlCommentsInTitleUseDefaultTitle() {
269-
assertRenderingCustomTitles("> [!NOTE] <!-- This won't appear --> <!---> <!-- Neither will this -->\n> Body text",
270-
"<div class=\"markdown-alert markdown-alert-note\" data-alert-type=\"note\">\n" +
271-
"<p class=\"markdown-alert-title\">Note<!-- This won't appear --> <!---> <!-- Neither will this --></p>\n" +
272-
"<p>Body text</p>\n" +
273-
"</div>\n");
274-
}
275-
276258
// Lazy continuation
277259

278260
@Test

0 commit comments

Comments
 (0)