Work towards a highlight.js unit test
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -91,6 +91,12 @@
|
||||
<version>1.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.mozilla/rhino -->
|
||||
<dependency>
|
||||
<groupId>org.mozilla</groupId>
|
||||
<artifactId>rhino</artifactId>
|
||||
<version>1.7.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -96,12 +96,11 @@ public class MarkdownMacro extends BaseMacro implements Macro
|
||||
" hljs.highlightBlock(block);\n" +
|
||||
" });\n" +
|
||||
"</script>";
|
||||
|
||||
Parser parser = Parser.builder(options).build();
|
||||
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
|
||||
|
||||
Node document = parser.parse(bodyContent);
|
||||
String html = renderer.render(document ) + highlightjs;
|
||||
String html = renderer.render(document) + highlightjs;
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,16 @@ public class MarkdownUnitTest {
|
||||
Mockito.when(requiredResources.requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs")).thenReturn(requiredResources);
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
String output = markdownMacro.execute(new HashMap(), "*Italic*", conversionContext);
|
||||
assertTrue(Pattern.matches("<p><em>Italic</em></p>[\\S\\s]*", output));
|
||||
assertTrue(Pattern.matches("[\\S\\s]*<em>Italic</em>[\\S\\s]*", output));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyntaxHighlighting() throws MacroExecutionException {
|
||||
Mockito.when(pageBuilderService.assembler()).thenReturn(webResourceAssembler);
|
||||
Mockito.when(webResourceAssembler.resources()).thenReturn(requiredResources);
|
||||
Mockito.when(requiredResources.requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs")).thenReturn(requiredResources);
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
String output = markdownMacro.execute(new HashMap(), "public class JavaClass {}", conversionContext);
|
||||
assertTrue(Pattern.matches("[\\S\\s]*<script>\\sAJS\\.\\$\\('\\[data\\-macro\\-name=\"markdown\"\\] code'\\)\\.each\\(function\\(i, block\\) \\{\\s hljs\\.highlightBlock\\(block\\);\\s \\}\\);\\s<\\/script>[\\S\\s]*", output));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user