From 51c6263f13d481f82eab9e3e881f4a3d715135f1 Mon Sep 17 00:00:00 2001
From: Mr-Wiseguy <mrwiseguyromhacking@gmail.com>
Date: Wed, 12 Mar 2025 00:06:48 -0400
Subject: [PATCH] Fix errant RML tag in mod menu and insert breaks for newlines
 when setting element text

---
 src/ui/elements/ui_element.cpp  | 22 +++++++++++++++++++++-
 src/ui/elements/ui_element.h    |  2 +-
 src/ui/ui_mod_details_panel.cpp |  2 +-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/ui/elements/ui_element.cpp b/src/ui/elements/ui_element.cpp
index c60ee1c..6e67bfa 100644
--- a/src/ui/elements/ui_element.cpp
+++ b/src/ui/elements/ui_element.cpp
@@ -272,10 +272,30 @@ bool Element::is_enabled() const {
     return enabled && !disabled_from_parent;
 }
 
+// Adapted from RmlUi's `EncodeRml`.
+std::string escape_rml(std::string_view string)
+{
+	std::string result;
+	result.reserve(string.size());
+	for (char c : string)
+	{
+		switch (c)
+		{
+		case '<': result += "&lt;"; break;
+		case '>': result += "&gt;"; break;
+		case '&': result += "&amp;"; break;
+		case '"': result += "&quot;"; break;
+        case '\n': result += "<br/>"; break;
+		default: result += c; break;
+		}
+	}
+	return result;
+}
+
 void Element::set_text(std::string_view text) {
     if (can_set_text) {
         // Escape the string into Rml to prevent element injection.
-        base->SetInnerRML(Rml::StringUtilities::EncodeRml(std::string(text)));
+        base->SetInnerRML(escape_rml(text));
     }
     else {
         assert(false && "Attempted to set text of an element that cannot have its text set.");
diff --git a/src/ui/elements/ui_element.h b/src/ui/elements/ui_element.h
index 2dbd3bf..b4a8e97 100644
--- a/src/ui/elements/ui_element.h
+++ b/src/ui/elements/ui_element.h
@@ -61,7 +61,7 @@ public:
     virtual ~Element();
     void clear_children();
     bool remove_child(ResourceId child);
-    bool remove_child(Element *child) { remove_child(child->get_resource_id()); }
+    bool remove_child(Element *child) { return remove_child(child->get_resource_id()); }
     void add_style(Style *style, std::string_view style_name);
     void add_style(Style *style, const std::initializer_list<std::string_view> &style_names);
     void set_enabled(bool enabled);
diff --git a/src/ui/ui_mod_details_panel.cpp b/src/ui/ui_mod_details_panel.cpp
index 4903bf8..00fb557 100644
--- a/src/ui/ui_mod_details_panel.cpp
+++ b/src/ui/ui_mod_details_panel.cpp
@@ -83,7 +83,7 @@ void ModDetailsPanel::set_mod_details(const recomp::mods::ModDetails& details, c
     title_label->set_text(cur_details.display_name);
     version_label->set_text(cur_details.version.to_string());
 
-    std::string authors_str = "<i>Authors</i>:";
+    std::string authors_str = "Authors:";
     bool first = true;
     for (const std::string& author : details.authors) {
         authors_str += (first ? " " : ", ") + author;