From 899aefc771c9d1d44d7136f5a96af4808a6d6c0a Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Sat, 23 May 2020 19:15:15 +0200 Subject: [PATCH] fix(renderer): do not HTML escape content twice in source blocks remove call to `escape` on the content of the source block Fixes #570 Signed-off-by: Xavier Coulon --- pkg/renderer/html5/delimited_block.go | 3 +- pkg/renderer/html5/delimited_block_test.go | 57 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/pkg/renderer/html5/delimited_block.go b/pkg/renderer/html5/delimited_block.go index 6ba6e9f1..05acbdf3 100644 --- a/pkg/renderer/html5/delimited_block.go +++ b/pkg/renderer/html5/delimited_block.go @@ -62,10 +62,9 @@ func init() { }) sourceBlockContentTmpl = newTextTemplate("source block content", - `{{ $ctx := .Context }}{{ with .Data }}{{ render $ctx .Elements | printf "%s" | escape }}{{ end }}`, + `{{ $ctx := .Context }}{{ with .Data }}{{ render $ctx .Elements | printf "%s" }}{{ end }}`, texttemplate.FuncMap{ "render": renderElements, - "escape": EscapeString, }) exampleBlockTmpl = newTextTemplate("example block", `{{ $ctx := .Context }}{{ with .Data }}
{{ if .Title }} diff --git a/pkg/renderer/html5/delimited_block_test.go b/pkg/renderer/html5/delimited_block_test.go index 458791c7..819144f1 100644 --- a/pkg/renderer/html5/delimited_block_test.go +++ b/pkg/renderer/html5/delimited_block_test.go @@ -333,6 +333,63 @@ end
  a<<b
+
` + Expect(RenderHTML(source)).To(MatchHTML(expected)) + }) + It("with callouts and syntax highlighting", func() { + source := `[source,java] +---- +@QuarkusTest +public class GreetingResourceTest { + + @InjectMock + @RestClient // <1> + GreetingService greetingService; + + @Test + public void testHelloEndpoint() { + Mockito.when(greetingService.hello()).thenReturn("hello from mockito"); + + given() + .when().get("/hello") + .then() + .statusCode(200) + .body(is("hello from mockito")); + } + +} +---- +<1> We need to use the @RestClient CDI qualifier, since Quarkus creates the GreetingService bean with this qualifier. +` + expected := `
+
+
@QuarkusTest
+public class GreetingResourceTest {
+
+    @InjectMock
+    @RestClient // (1)
+    GreetingService greetingService;
+
+    @Test
+    public void testHelloEndpoint() {
+        Mockito.when(greetingService.hello()).thenReturn("hello from mockito");
+
+        given()
+          .when().get("/hello")
+          .then()
+             .statusCode(200)
+             .body(is("hello from mockito"));
+    }
+
+}
+
+
+
+
    +
  1. +

    We need to use the @RestClient CDI qualifier, since Quarkus creates the GreetingService bean with this qualifier.

    +
  2. +
` Expect(RenderHTML(source)).To(MatchHTML(expected)) })