shithub: hell

Download patch

ref: 58a0909ef0e68e01874fad0e4fb01fbe6c47a2d6
parent: b711e39e9ed316a2d67b029b4d8e748589d9dfd2
author: penny <penny@limitedideas.org>
date: Sat Sep 6 20:26:50 EDT 2025

Add support for plaintext in statuses

--- a/mastodon.go
+++ b/mastodon.go
@@ -73,7 +73,7 @@
 	return c
 }
 
-func (hc *Hellclient) renderStatus(content string, index string) string {
+func (hc *Hellclient) renderStatus(content string, index string) (string, map[string]string) {
 	doc, err := html.Parse(strings.NewReader(content))
 	if err != nil {
 		log.Fatal(err)
@@ -81,11 +81,17 @@
 
 	//clear out the url map
 	hc.urlMap[index] = []string{}
+	preformats := make(map[string]string)
 
 	for node := range doc.Descendants() {
+		if node.Data == "pre" && node.FirstChild != nil {
+			preformats[fmt.Sprintf("%p%p", hc, node.FirstChild)] = node.FirstChild.Data
+			node.FirstChild.Data = fmt.Sprintf("%p%p", hc, node.FirstChild)
+		}
 		if node.Data == "a" && node.Type == html.ElementNode {
 			ismention := false
 			href := ""
+
 			for attr := range node.Attr {
 				if node.Attr[attr].Key == "class" && strings.Contains(node.Attr[attr].Val, "mention") {
 					node.Data = "div"
@@ -120,9 +126,12 @@
 	err = html.Render(&rendered, doc)
 
 	if err != nil {
-		log.Fatal(err)
+		return "", nil
 	}
-	return rendered.String()
+	
+	renderedPlainText := rendered.String()
+	
+	return renderedPlainText, preformats
 }
 
 func processStatusHints(toot *mastodon.Toot, postpointer *string) {
@@ -240,8 +249,13 @@
 }
 
 func (hc *Hellclient) formatStatusDetailed(post *mastodon.Status, index string, prefix string) string {
-	renderedPost := hc.renderStatus(post.Content, index)
-	return fmt.Sprintf("%v>%v <%v> %v", index, prefix, post.Account.Username, html2text.HTML2Text(renderedPost))
+	renderedPost, plaintexts := hc.renderStatus(post.Content, index)
+
+	rendered := fmt.Sprintf("%v>%v <%v> %v", index, prefix, post.Account.Username, html2text.HTML2Text(renderedPost))
+	for key, plaintext := range plaintexts {
+		rendered = strings.Replace(rendered, key, plaintext, 1)
+	}
+	return rendered
 }
 
 func (hc *Hellclient) formatEdit(post *mastodon.Status, index string) string {
--