diff --git a/i3pystatus/core/modules.py b/i3pystatus/core/modules.py index 4c8fa54..d26c266 100644 --- a/i3pystatus/core/modules.py +++ b/i3pystatus/core/modules.py @@ -38,7 +38,7 @@ class Module(SettingsBase): if key not in self.output: self.output.update({key: val}) if self.output.get("markup") == "pango": - self.__text_to_pango() + self.text_to_pango() json.insert(convert_position(self.position, json), self.output) @@ -111,17 +111,29 @@ class Module(SettingsBase): self.position = position return self - def __text_to_pango(self): + def text_to_pango(self): """ - Replaces all ampersands in `"full_text"` and `"short_text"` blocks` in + Replaces all ampersands in `full_text` and `short_text` attributes of `self.output` with `&`. + + It is called internally when pango markup is used. + + Can be called multiple times (`&` won't change to `&`). """ + def replace(s): + s = s.split("&") + out = s[0] + for i in range(len(s) - 1): + if s[i + 1].startswith("amp;"): + out += "&" + s[i + 1] + else: + out += "&" + s[i + 1] + return out + if "full_text" in self.output.keys(): - out = self.output["full_text"].replace("&", "&") - self.output.update({"full_text": out}) + self.output["full_text"] = replace(self.output["full_text"]) if "short_text" in self.output.keys(): - out = self.output["short_text"].replace("&", "&") - self.output.update({"short_text": out}) + self.output["short_text"] = replace(self.output["short_text"]) class IntervalModule(Module):