Skip to content

Commit

Permalink
fix(renderer): do not HTML escape content twice in source blocks (#571)
Browse files Browse the repository at this point in the history
remove call to `escape` on the content of the source block

Fixes #570

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored May 23, 2020
1 parent d759c0b commit 08b705d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/renderer/html5/delimited_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}<div {{ if .ID }}id="{{ .ID }}" {{ end }}class="exampleblock">{{ if .Title }}
Expand Down
57 changes: 57 additions & 0 deletions pkg/renderer/html5/delimited_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,63 @@ end</code></pre>
<div class="content">
<pre> a&lt;&lt;b</pre>
</div>
</div>`
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 := `<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">@QuarkusTest
public class GreetingResourceTest {
@InjectMock
@RestClient // <b class="conum">(1)</b>
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"));
}
}</code></pre>
</div>
</div>
<div class="colist arabic">
<ol>
<li>
<p>We need to use the @RestClient CDI qualifier, since Quarkus creates the GreetingService bean with this qualifier.</p>
</li>
</ol>
</div>`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})
Expand Down

0 comments on commit 08b705d

Please sign in to comment.