Skip to content

Commit 7d64848

Browse files
committed
Do not add spurious spaces after citation reference
1 parent c875978 commit 7d64848

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

html2text.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func (ctx *textifyTraverseContext) normalizeHrefLink(link string) string {
517517
}
518518

519519
func formatCitation(idx int) string {
520-
return fmt.Sprintf("[%d] ", idx)
520+
return fmt.Sprintf("[%d]", idx)
521521
}
522522

523523
func (ctx *textifyTraverseContext) addCitation(url string) string {
@@ -545,6 +545,7 @@ func (ctx *textifyTraverseContext) emitCitations() {
545545

546546
for i, link := range links {
547547
ctx.buf.WriteString(formatCitation(i + 1))
548+
ctx.buf.WriteByte(' ')
548549
ctx.buf.WriteString(link)
549550
ctx.buf.WriteByte('\n')
550551
}

html2text_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,31 +536,31 @@ func TestCitationStyleLinks(t *testing.T) {
536536
},
537537
{
538538
`<a href="http://example.com/"></a>`,
539-
"[1] \n\n[1] http://example.com/",
539+
"[1]\n\n[1] http://example.com/",
540540
},
541541
{
542542
`<a href="">Link</a>`,
543543
"Link",
544544
},
545545
{
546-
`<a href="http://example1.com/">Link1</a><a href="http://example2.com/">Link2</a>`,
547-
"Link1 [1] Link2 [2] \n\n[1] http://example1.com/\n[2] http://example2.com/",
546+
`<a href="http://example1.com/">Link1</a>? <a href="http://example2.com/">Link2</a>!`,
547+
"Link1 [1]? Link2 [2]!\n\n[1] http://example1.com/\n[2] http://example2.com/",
548548
},
549549
{
550550
`<a href="http://example1.com/">Link1</a><a href="http://example1.com/">Link1 again</a>`,
551-
"Link1 [1] Link1 again [1] \n\n[1] http://example1.com/",
551+
"Link1 [1] Link1 again [1]\n\n[1] http://example1.com/",
552552
},
553553
{
554554
`<a href="http://example.com/"><span class="a">Link</span></a>`,
555-
"Link [1] \n\n[1] http://example.com/",
555+
"Link [1]\n\n[1] http://example.com/",
556556
},
557557
{
558558
"<a href='http://example.com/'>\n\t<span class='a'>Link</span>\n\t</a>",
559-
"Link [1] \n\n[1] http://example.com/",
559+
"Link [1]\n\n[1] http://example.com/",
560560
},
561561
{
562562
`<a href="http://example.com/"><img src="http://example.ru/hello.jpg" alt="Example"></a>`,
563-
"Example [1] \n\n[1] http://example.com/",
563+
"Example [1]\n\n[1] http://example.com/",
564564
},
565565
}
566566

0 commit comments

Comments
 (0)