Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(renderer): do not HTML escape content twice in source blocks #571

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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