Skip to content

Commit

Permalink
Add support for (TM) and (R) in markup. (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore authored Jun 6, 2020
1 parent 8810e1a commit f15b786
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
10 changes: 9 additions & 1 deletion pkg/renderer/html5/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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, copyright)
result := convert(buf.String(), ellipsis, copyright, trademark, registered)
return []byte(result), nil
}

Expand All @@ -33,6 +33,14 @@ func copyright(source string) string {
return strings.Replace(source, "(C)", "©", -1)
}

func trademark(source string) string {
return strings.Replace(source, "(TM)", "™", -1)
}

func registered(source string) string {
return strings.Replace(source, "(R)", "®", -1)
}

type converter func(string) string

func convert(source string, converters ...converter) string {
Expand Down
31 changes: 27 additions & 4 deletions pkg/renderer/html5/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ var _ = Describe("strings", 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">
<p>some text&#8230;&#8203;</p>
</div>`
Expand All @@ -21,10 +19,35 @@ var _ = Describe("strings", func() {

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(MatchHTML(expected))
})

It("text with trademark", func() {
source := `TheRightThing(TM)`
expected := `<div class="paragraph">
<p>TheRightThing&#153;</p>
</div>`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("text with registered", func() {
source := `TheRightThing(R)`
expected := `<div class="paragraph">
<p>TheRightThing&#174;</p>
</div>`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("title with registered", func() {
// We will often want to use these symbols in headers.
source := `== Registered(R)`
expected := `<div class="sect1">
<h2 id="_registered_r">Registered&#174;</h2>
<div class="sectionbody">
</div>
</div>`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})
Expand Down

0 comments on commit f15b786

Please sign in to comment.