git » sdk » commit 1d0c890

Render inline code tag as backtick

author Stephen Paul Weber
2025-12-28 03:27:40 UTC
committer Stephen Paul Weber
2025-12-28 03:27:40 UTC
parent e5133d1d2a7a2ab54237c1bc488b30ef8f39a291

Render inline code tag as backtick

borogove/XEP0393.hx +6 -6

diff --git a/borogove/XEP0393.hx b/borogove/XEP0393.hx
index a391a96..9b543be 100644
--- a/borogove/XEP0393.hx
+++ b/borogove/XEP0393.hx
@@ -15,7 +15,7 @@ class XEP0393 {
 		return blocks;
 	}
 
-	public static function render(xhtml: Stanza) {
+	public static function render(xhtml: Stanza, inPre = false) {
 		if (xhtml.name == "br") {
 			return "\n";
 		}
@@ -42,12 +42,12 @@ class XEP0393 {
 			s.add("~");
 		}
 
-		if (xhtml.name == "tt") {
+		if (!inPre && (xhtml.name == "tt" || xhtml.name == "code")) {
 			s.add("`");
 		}
 
 		for (child in xhtml.children) {
-			s.add(renderNode(child));
+			s.add(renderNode(child, xhtml.name == "pre"));
 		}
 
 		if (xhtml.name == "b" || xhtml.name == "strong") {
@@ -62,7 +62,7 @@ class XEP0393 {
 			s.add("~");
 		}
 
-		if (xhtml.name == "tt") {
+		if (!inPre && (xhtml.name == "tt" || xhtml.name == "code")) {
 			s.add("`");
 		}
 
@@ -81,9 +81,9 @@ class XEP0393 {
 		return s.toString();
 	}
 
-	public static function renderNode(xhtml: Node) {
+	public static function renderNode(xhtml: Node, inPre = false) {
 		return switch (xhtml) {
-			case Element(c): render(c);
+			case Element(c): render(c, inPre);
 			case CData(c): c.content;
 		};
 	}