Little enhancement to the previewers.

Mon, 02 Jan 2017 12:49:04 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 02 Jan 2017 12:49:04 +0100
changeset 5396
8d8940307e44
parent 5395
56efc13e456e
child 5397
fee5485e67f4

Little enhancement to the previewers.

UI/Previewer.py file | annotate | diff | comparison | revisions
UI/Previewers/PreviewerHTML.py file | annotate | diff | comparison | revisions
--- a/UI/Previewer.py	Sun Jan 01 18:13:13 2017 +0100
+++ b/UI/Previewer.py	Mon Jan 02 12:49:04 2017 +0100
@@ -143,7 +143,7 @@
         @return flag indicating if a preview can be shown (boolean)
         """
         if editor:
-            if editor.getFileName() is not None:
+            if bool(editor.getFileName()):
                 extension = os.path.normcase(
                     os.path.splitext(editor.getFileName())[1][1:])
                 return extension in \
@@ -152,7 +152,8 @@
                         "PreviewMarkdownFileNameExtensions") + \
                     Preferences.getEditor("PreviewRestFileNameExtensions") + \
                     Preferences.getEditor("PreviewQssFileNameExtensions")
-            elif editor.getLanguage() in ["HTML", "QSS"]:
+            elif editor.getLanguage().lower() in [
+                    "html", "markdown", "restructuredtext", "qss"]:
                 return True
         
         return False
@@ -173,16 +174,19 @@
                 extension = ""
             if extension in \
                 Preferences.getEditor("PreviewHtmlFileNameExtensions") or \
-               editor.getLanguage() == "HTML":
+                    editor.getLanguage().lower() == "html":
                 language = "HTML"
             elif extension in \
-                    Preferences.getEditor("PreviewMarkdownFileNameExtensions"):
+                Preferences.getEditor("PreviewMarkdownFileNameExtensions") or \
+                    editor.getLanguage().lower() == "markdown":
                 language = "Markdown"
             elif extension in \
-                    Preferences.getEditor("PreviewRestFileNameExtensions"):
+                Preferences.getEditor("PreviewRestFileNameExtensions") or \
+                    editor.getLanguage().lower() == "restructuredtext":
                 language = "ReST"
             elif extension in \
-                    Preferences.getEditor("PreviewQssFileNameExtensions"):
+                Preferences.getEditor("PreviewQssFileNameExtensions") or \
+                    editor.getLanguage().lower() == "qss":
                 language = "QSS"
             else:
                 language = ""
--- a/UI/Previewers/PreviewerHTML.py	Sun Jan 01 18:13:13 2017 +0100
+++ b/UI/Previewers/PreviewerHTML.py	Mon Jan 02 12:49:04 2017 +0100
@@ -164,13 +164,15 @@
                 extension = ""
             if extension in \
                 Preferences.getEditor("PreviewHtmlFileNameExtensions") or \
-               editor.getLanguage() == "HTML":
+                    editor.getLanguage() == "HTML":
                 language = "HTML"
             elif extension in \
-                    Preferences.getEditor("PreviewMarkdownFileNameExtensions"):
+                Preferences.getEditor("PreviewMarkdownFileNameExtensions") or \
+                    editor.getLanguage().lower() == "markdown":
                 language = "Markdown"
             elif extension in \
-                    Preferences.getEditor("PreviewRestFileNameExtensions"):
+                Preferences.getEditor("PreviewRestFileNameExtensions") or \
+                    editor.getLanguage().lower() == "restructuredtext":
                 language = "ReST"
             else:
                 self.__setHtml(fn, self.tr(
@@ -186,10 +188,11 @@
             else:
                 rootPath = ""
             
-            self.__processingThread.process(
-                fn, language, editor.text(),
-                self.ssiCheckBox.isChecked(), rootPath,
-                Preferences.getEditor("PreviewRestUseSphinx"))
+            if bool(editor.text()):
+                self.__processingThread.process(
+                    fn, language, editor.text(),
+                    self.ssiCheckBox.isChecked(), rootPath,
+                    Preferences.getEditor("PreviewRestUseSphinx"))
 
     def __setHtml(self, filePath, html):
         """
@@ -338,11 +341,6 @@
     """
     htmlReady = pyqtSignal(str, str)
     
-    DefaultStaticPath = os.path.join(
-        os.path.abspath(os.path.dirname(__file__)), 'sphinx_default')
-    StaticRegexp = re.compile(r'(src|href)=["\']_static([\s\w/\.]+?)["\']',
-                              re.IGNORECASE)
-    
     def __init__(self, parent=None):
         """
         Constructor
@@ -537,13 +535,6 @@
             fh.close()
         finally:
             shutil.rmtree(tempDir)
-
-        # Replace the "_static/..." references inserted by Sphinx with absolute
-        # links to the specified DefaultStaticPath replacement.
-        def replace(m):
-            return '{0}="file://{1}{2}"'.format(
-                m.group(1), self.DefaultStaticPath, m.group(2))
-        html = re.sub(self.StaticRegexp, replace, html)
         
         return html
     

eric ide

mercurial