Browse Source

Escape text before putting it in a pango span

tags/0.8.2^0
Julien Blanchard 1 year ago
parent
commit
d401d48174
3 changed files with 19 additions and 9 deletions
  1. 1
    1
      Cargo.lock
  2. 1
    1
      Cargo.toml
  3. 17
    7
      src/draw.rs

+ 1
- 1
Cargo.lock View File

@@ -136,7 +136,7 @@ dependencies = [
136 136
 
137 137
 [[package]]
138 138
 name = "castor"
139
-version = "0.8.1"
139
+version = "0.8.2"
140 140
 dependencies = [
141 141
  "ansi-parser 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
142 142
  "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",

+ 1
- 1
Cargo.toml View File

@@ -1,6 +1,6 @@
1 1
 [package]
2 2
 name = "castor"
3
-version = "0.8.1"
3
+version = "0.8.2"
4 4
 authors = ["Julien Blanchard <julien@typed-hole.org>"]
5 5
 edition = "2018"
6 6
 

+ 17
- 7
src/draw.rs View File

@@ -36,7 +36,7 @@ pub fn gemini_content(
36 36
                         crate::settings::h1_color(),
37 37
                         font_family,
38 38
                         crate::settings::h1_character(),
39
-                        header
39
+                        escape_text(&header)
40 40
                     ),
41 41
                 );
42 42
             }
@@ -49,7 +49,7 @@ pub fn gemini_content(
49 49
                         crate::settings::h2_color(),
50 50
                         font_family,
51 51
                         crate::settings::h2_character(),
52
-                        header
52
+                        escape_text(&header)
53 53
                     ),
54 54
                 );
55 55
             }
@@ -62,7 +62,7 @@ pub fn gemini_content(
62 62
                         crate::settings::h3_color(),
63 63
                         font_family,
64 64
                         crate::settings::h3_character(),
65
-                        header
65
+                        escape_text(&header)
66 66
                     ),
67 67
                 );
68 68
             }
@@ -75,7 +75,7 @@ pub fn gemini_content(
75 75
                         crate::settings::list_color(),
76 76
                         font_family,
77 77
                         crate::settings::list_character(),
78
-                        item
78
+                        escape_text(&item)
79 79
                     ),
80 80
                 );
81 81
             }
@@ -84,6 +84,12 @@ pub fn gemini_content(
84 84
             }
85 85
             Ok(crate::gemini::parser::TextElement::Text(text)) => {
86 86
                 let mut end_iter = buffer.get_end_iter();
87
+                let text = if text.contains("<span") {
88
+                    text
89
+                } else {
90
+                    escape_text(&text)
91
+                };
92
+
87 93
                 if mono_toggle {
88 94
                     buffer.insert_markup(
89 95
                         &mut end_iter,
@@ -130,7 +136,7 @@ pub fn gemini_text_content(
130 136
                     &format!(
131 137
                         "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
132 138
                         crate::settings::text_color(),
133
-                        text
139
+                        escape_text(&text)
134 140
                     ),
135 141
                 );
136 142
             }
@@ -164,7 +170,7 @@ pub fn gopher_content(
164 170
                         "<span foreground=\"{}\" {}>{}</span>\n",
165 171
                         crate::settings::text_color(),
166 172
                         font_family,
167
-                        text
173
+                        escape_text(&text)
168 174
                     ),
169 175
                 );
170 176
             }
@@ -206,7 +212,7 @@ pub fn finger_content(
206 212
                         "<span foreground=\"{}\" {}>{}</span>\n",
207 213
                         crate::settings::text_color(),
208 214
                         font_family,
209
-                        text
215
+                        escape_text(&text)
210 216
                     ),
211 217
                 );
212 218
             }
@@ -374,3 +380,7 @@ pub fn insert_external_button(gui: &Arc<Gui>, url: Url, label: &str) {
374 380
     let mut end_iter = buffer.get_end_iter();
375 381
     buffer.insert(&mut end_iter, "\n");
376 382
 }
383
+
384
+fn escape_text(str: &str) -> String {
385
+    String::from(glib::markup_escape_text(&str).as_str())
386
+}

Loading…
Cancel
Save