Highlight.java
Highlight.java copied to clipboard
Issue with rendering empty <script> tags
When I am trying to render an empty script tag '' the result will contain an unexpected null tag:
<span class="null">null</span>
As far as I could see the reason is the highlighter tries to figure out the language within the script tag, but cannot figure it out, thus both the language name and the code will be null.
See: com.codewaves.codehighlight.core.HighlightParser.processSubLanguage()
A test case to reproduce the issue:
@Test
public void testScriptError() {
String sourceCode = "<script></script>";
Highlighter highlighter = new Highlighter(something -> new HtmlRenderer("hljs-"));
Highlighter.HighlightResult result = highlighter.highlight("html", sourceCode);
Truth.assertThat(result.getResult().toString()).doesNotContain("null");
}