Support syntax highlighting for all XML/JSON-based content types via +xml/+json suffix
This commit is contained in:
parent
4a8776a42d
commit
034f1a7443
@ -1150,6 +1150,18 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
|
|
||||||
return ""
|
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):
|
def _get_language_from_content_type(self, content_type):
|
||||||
"""Get GtkSourceView language ID from content type."""
|
"""Get GtkSourceView language ID from content type."""
|
||||||
if not content_type:
|
if not content_type:
|
||||||
@ -1157,9 +1169,9 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
|
|
||||||
language_manager = GtkSource.LanguageManager.get_default()
|
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')
|
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')
|
return language_manager.get_language('xml')
|
||||||
elif 'text/html' in content_type:
|
elif 'text/html' in content_type:
|
||||||
return language_manager.get_language('html')
|
return language_manager.get_language('html')
|
||||||
@ -1176,10 +1188,10 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
return body
|
return body
|
||||||
|
|
||||||
try:
|
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)
|
parsed = json.loads(body)
|
||||||
return json.dumps(parsed, indent=2, ensure_ascii=False)
|
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)
|
dom = xml.dom.minidom.parseString(body)
|
||||||
return dom.toprettyxml(indent=" ")
|
return dom.toprettyxml(indent=" ")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user