[gobject-introspection: 23/30] docwriter: Handle unknown language MIME types



commit 13635f61c8c22d33832f3e88a0d1d728a7c748b3
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun May 7 20:26:36 2017 -0700

    docwriter: Handle unknown language MIME types
    
    Add "plain" -> "text/plain" to the mapping since "plain" is used several
    times in the GTK documentation. But also, fix the code that falls back to
    no syntax highlighting for an unknown language - it did not check for
    KeyError.

 giscanner/docwriter.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index 754787e3..6b14f72b 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -57,6 +57,7 @@ language_mimes = {
     "pascal": "text/x-pascal",
     "perl": "application/x-perl",
     "php": "application/x-php",
+    "plain": "text/plain",
     "python": "text/x-python",
     "ruby": "application/x-ruby",
     "sql": "text/x-sql",
@@ -359,11 +360,12 @@ class DocFormatter(object):
         return '</p><pre>\n    '
 
     def _process_code_start_with_language(self, node, match, props):
-        mime = language_mimes[props["language_name"].lower()]
         self._processing_code = True
-        if not mime:
+        try:
+            mime = language_mimes[props["language_name"].lower()]
+            return '</p><pre data-mime="' + mime + '">\n    '
+        except KeyError:
             return '</p><pre>\n    '
-        return '</p><pre data-mime="' + mime + '">\n    '
 
     def _process_code_end(self, node, match, props):
         self._processing_code = False


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]