Skip to content

Commit

Permalink
feat(renderer): support Copyright character replacement
Browse files Browse the repository at this point in the history
replace `(C)` with `&bytesparadise#169;`

Fixes bytesparadise#524

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Mar 29, 2020
1 parent 163c64f commit 6bb6ccd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
6 changes: 5 additions & 1 deletion pkg/renderer/html5/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ func renderStringElement(ctx renderer.Context, str types.StringElement) ([]byte,
if err != nil {
return []byte{}, errors.Wrapf(err, "unable to render string")
}
result := convert(buf.String(), ellipsis)
result := convert(buf.String(), ellipsis, copyright)
return []byte(result), nil
}

func ellipsis(source string) string {
return strings.Replace(source, "...", "&#8230;&#8203;", -1)
}

func copyright(source string) string {
return strings.Replace(source, "(C)", "&#169;", -1)
}

type converter func(string) string

func convert(source string, converters ...converter) string {
Expand Down
25 changes: 16 additions & 9 deletions pkg/renderer/html5/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ import (

var _ = Describe("strings", func() {

Context("ellipsis conversion", func() {

It("text with ellipsis", func() {
source := `some text...`
// top-level section is not rendered per-say,
// but the section will be used to set the HTML page's <title> element
expected := `<div class="paragraph">
It("text with ellipsis", func() {
source := `some text...`
// top-level section is not rendered per-say,
// but the section will be used to set the HTML page's <title> element
expected := `<div class="paragraph">
<p>some text&#8230;&#8203;</p>
</div>`
Expect(RenderHTML(source)).To(Equal(expected))
})
Expect(RenderHTML(source)).To(Equal(expected))
})

It("text with copyright", func() {
source := `Copyright (C)`
// top-level section is not rendered per-say,
// but the section will be used to set the HTML page's <title> element
expected := `<div class="paragraph">
<p>Copyright &#169;</p>
</div>`
Expect(RenderHTML(source)).To(Equal(expected))
})
})

0 comments on commit 6bb6ccd

Please sign in to comment.