html2text: Try and handle one more mention case
authorMikael Berthe <mikael@lilotux.net>
Sat, 13 May 2017 12:36:38 +0200
changeset 132 4bf4f6ce268e
parent 131 6461e0637767
child 133 bdbdafd5e665
html2text: Try and handle one more mention case + switch to devel version
cmd/version.go
printer/html2text/html2text.go
printer/html2text/html2text_test.go
--- a/cmd/version.go	Sat May 13 11:56:52 2017 +0200
+++ b/cmd/version.go	Sat May 13 12:36:38 2017 +0200
@@ -23,7 +23,7 @@
 }
 
 // VERSION of the madonctl application
-var VERSION = "1.1.0"
+var VERSION = "1.1.1-dev"
 
 var versionCmd = &cobra.Command{
 	Use:   "version",
--- a/printer/html2text/html2text.go	Sat May 13 11:56:52 2017 +0200
+++ b/printer/html2text/html2text.go	Sat May 13 12:36:38 2017 +0200
@@ -116,6 +116,11 @@
 		last = b.Bytes()[bl-1]
 	}
 
+	// Add heading space if needed
+	if last != ' ' && last != '\n' && last != '#' && last != '@' {
+		b.WriteString(" ")
+	}
+
 	var tmpbuf bytes.Buffer
 	for c := n.FirstChild; c != nil; c = c.NextSibling {
 		process(c, &tmpbuf, class)
@@ -126,11 +131,6 @@
 		return
 	}
 
-	// Add heading space if needed
-	if last != ' ' && last != '\n' {
-		b.WriteString(" ")
-	}
-
 	s := tmpbuf.String()
 	if strings.HasPrefix(s, "#") || strings.HasPrefix(s, "@") {
 		b.WriteString(s) // Tag or mention: display content
--- a/printer/html2text/html2text_test.go	Sat May 13 11:56:52 2017 +0200
+++ b/printer/html2text/html2text_test.go	Sat May 13 12:36:38 2017 +0200
@@ -146,6 +146,16 @@
 	assert.Equal(t, expected, r)
 }
 
+func TestTextifyMastodonMention(t *testing.T) {
+	expected := "La tête à @Toto \\o/"
+
+	body := `<p>La tête à <span class="h-card"><a href="https://example.com/@Toto">@<span>Toto</span></a></span> \o/</p>`
+
+	r, e := Textify(body)
+	assert.Nil(t, e)
+	assert.Equal(t, expected, r)
+}
+
 func TestTextifyMastodonMentionAndTag(t *testing.T) {
 	expected := "@ACh Mais heu ! Moi aussi je fais du #TootRadio de gens morts il y a 5 siècles. Gesulado, Charpentier, Mireille Mathieu..."