Skip to content

Commit

Permalink
Do not add spurious spaces after citation reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Necoro committed May 10, 2020
1 parent c875978 commit 7d64848
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion html2text.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (ctx *textifyTraverseContext) normalizeHrefLink(link string) string {
}

func formatCitation(idx int) string {
return fmt.Sprintf("[%d] ", idx)
return fmt.Sprintf("[%d]", idx)
}

func (ctx *textifyTraverseContext) addCitation(url string) string {
Expand Down Expand Up @@ -545,6 +545,7 @@ func (ctx *textifyTraverseContext) emitCitations() {

for i, link := range links {
ctx.buf.WriteString(formatCitation(i + 1))
ctx.buf.WriteByte(' ')
ctx.buf.WriteString(link)
ctx.buf.WriteByte('\n')
}
Expand Down
14 changes: 7 additions & 7 deletions html2text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,31 +536,31 @@ func TestCitationStyleLinks(t *testing.T) {
},
{
`<a href="http://example.com/"></a>`,
"[1] \n\n[1] http://example.com/",
"[1]\n\n[1] http://example.com/",
},
{
`<a href="">Link</a>`,
"Link",
},
{
`<a href="http://example1.com/">Link1</a><a href="http://example2.com/">Link2</a>`,
"Link1 [1] Link2 [2] \n\n[1] http://example1.com/\n[2] http://example2.com/",
`<a href="http://example1.com/">Link1</a>? <a href="http://example2.com/">Link2</a>!`,
"Link1 [1]? Link2 [2]!\n\n[1] http://example1.com/\n[2] http://example2.com/",
},
{
`<a href="http://example1.com/">Link1</a><a href="http://example1.com/">Link1 again</a>`,
"Link1 [1] Link1 again [1] \n\n[1] http://example1.com/",
"Link1 [1] Link1 again [1]\n\n[1] http://example1.com/",
},
{
`<a href="http://example.com/"><span class="a">Link</span></a>`,
"Link [1] \n\n[1] http://example.com/",
"Link [1]\n\n[1] http://example.com/",
},
{
"<a href='http://example.com/'>\n\t<span class='a'>Link</span>\n\t</a>",
"Link [1] \n\n[1] http://example.com/",
"Link [1]\n\n[1] http://example.com/",
},
{
`<a href="http://example.com/"><img src="http://example.ru/hello.jpg" alt="Example"></a>`,
"Example [1] \n\n[1] http://example.com/",
"Example [1]\n\n[1] http://example.com/",
},
}

Expand Down

0 comments on commit 7d64848

Please sign in to comment.