From daf03123a61597c10a23c17ec9f98ed894c28c79 Mon Sep 17 00:00:00 2001 From: Pavel Baksy Date: Tue, 10 Feb 2026 23:47:30 +0100 Subject: [PATCH] Support syntax highlighting for all XML/JSON-based content types via +xml/+json suffix --- src/request_tab_widget.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/request_tab_widget.py b/src/request_tab_widget.py index bf8e6c3..c986c64 100644 --- a/src/request_tab_widget.py +++ b/src/request_tab_widget.py @@ -1150,6 +1150,18 @@ class RequestTabWidget(Gtk.Box): return "" + def _is_json_content_type(self, content_type): + """Check if the content type is JSON or a JSON-based format.""" + return ('application/json' in content_type + or 'text/json' in content_type + or '+json' in content_type) + + def _is_xml_content_type(self, content_type): + """Check if the content type is XML or an XML-based format.""" + return ('application/xml' in content_type + or 'text/xml' in content_type + or '+xml' in content_type) + def _get_language_from_content_type(self, content_type): """Get GtkSourceView language ID from content type.""" if not content_type: @@ -1157,9 +1169,9 @@ class RequestTabWidget(Gtk.Box): language_manager = GtkSource.LanguageManager.get_default() - if 'application/json' in content_type or 'text/json' in content_type: + if self._is_json_content_type(content_type): return language_manager.get_language('json') - elif 'application/xml' in content_type or 'text/xml' in content_type: + elif self._is_xml_content_type(content_type): return language_manager.get_language('xml') elif 'text/html' in content_type: return language_manager.get_language('html') @@ -1176,10 +1188,10 @@ class RequestTabWidget(Gtk.Box): return body try: - if 'application/json' in content_type or 'text/json' in content_type: + if self._is_json_content_type(content_type): parsed = json.loads(body) return json.dumps(parsed, indent=2, ensure_ascii=False) - elif 'application/xml' in content_type or 'text/xml' in content_type: + elif self._is_xml_content_type(content_type): dom = xml.dom.minidom.parseString(body) return dom.toprettyxml(indent=" ") except Exception as e: