Skip to content

Commit

Permalink
fix(renderer): do not highlight syntax when language is not set (#515)
Browse files Browse the repository at this point in the history
fixes #514

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Mar 21, 2020
1 parent 1b574d6 commit c3439bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/renderer/html5/delimited_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func renderSourceBlock(ctx renderer.Context, b types.DelimitedBlock) ([]byte, er
language := b.Attributes.GetAsString(types.AttrLanguage)

hightligher, _ := ctx.Document.Attributes.GetAsString("source-highlighter")
if hightligher == "pygments" {
if language != "" && hightligher == "pygments" {
// using github.com/alecthomas/chroma to highlight the content
contentBuf = bytes.NewBuffer(nil)
lexer := lexers.Get(language)
Expand Down
19 changes: 19 additions & 0 deletions pkg/renderer/html5/delimited_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,25 @@ type Foo struct{
Expect(RenderHTML5Body(source)).To(Equal(expected))
})

It("should render source block without highlighter when language is not set", func() {
source := `:source-highlighter: pygments
[source]
----
type Foo struct{
Field string
}
----`
expected := `<div class="listingblock">
<div class="content">
<pre class="pygments highlight"><code>type Foo struct{
Field string
}</code></pre>
</div>
</div>`
Expect(RenderHTML5Body(source)).To(Equal(expected))
})

It("should render source block with go syntax and custom style", func() {
source := `:source-highlighter: pygments
:pygments-style: manni
Expand Down

0 comments on commit c3439bd

Please sign in to comment.