eric6/QScintilla/MarkupProviders/__init__.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric6/QScintilla/MarkupProviders/__init__.py	Sun Apr 14 15:09:21 2019 +0200
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2017 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Package providing various markup providers.
+"""
+
+from __future__ import unicode_literals
+
+import os
+
+import Preferences
+
+
+def getMarkupProvider(editor):
+    """
+    Public method to get a markup provider for the given editor.
+    
+    @param editor reference to the editor to get the markup provider for
+    @type Editor
+    @return markup provider
+    @rtype MarkupBase
+    """
+    if editor is not None:
+        fn = editor.getFileName()
+        
+        if fn:
+            extension = os.path.normcase(os.path.splitext(fn)[1][1:])
+        else:
+            extension = ""
+        if extension in \
+            Preferences.getEditor("PreviewHtmlFileNameExtensions") or \
+                editor.getLanguage() == "HTML":
+            from .HtmlProvider import HtmlProvider
+            return HtmlProvider()
+        elif extension in \
+            Preferences.getEditor("PreviewMarkdownFileNameExtensions") or \
+                editor.getLanguage().lower() == "markdown":
+            from .MarkdownProvider import MarkdownProvider
+            return MarkdownProvider()
+        elif extension in \
+            Preferences.getEditor("PreviewRestFileNameExtensions") or \
+                editor.getLanguage().lower() == "restructuredtext":
+            from .RestructuredTextProvider import RestructuredTextProvider
+            return RestructuredTextProvider()
+    
+    # no supported markup provider identified
+    from .MarkupBase import MarkupBase
+    return MarkupBase()

eric ide

mercurial