eric6/QScintilla/Exporters/ExporterHTML.py

changeset 7524
282680dae446
parent 7360
9190402e4505
child 7771
787a6b3f8c9f
--- a/eric6/QScintilla/Exporters/ExporterHTML.py	Sat Apr 11 14:50:48 2020 +0200
+++ b/eric6/QScintilla/Exporters/ExporterHTML.py	Sat Apr 11 19:08:37 2020 +0200
@@ -17,7 +17,7 @@
 
 from PyQt5.QtCore import Qt
 from PyQt5.QtGui import QCursor, QFontInfo
-from PyQt5.QtWidgets import QApplication
+from PyQt5.QtWidgets import QApplication, QInputDialog
 from PyQt5.Qsci import QsciScintilla
 
 from E5Gui import E5MessageBox
@@ -408,7 +408,25 @@
                 self.editor.getLanguage().lower() == "markdown"
             ):
                 # export markdown to HTML
-                html = self.__generateFromMarkdown()
+                colorSchemes = [
+                    self.tr("Light Background Color"),
+                    self.tr("Dark Background Color"),
+                ]
+                QApplication.restoreOverrideCursor()
+                colorScheme, ok = QInputDialog.getItem(
+                    None,
+                    self.tr("Markdown Export"),
+                    self.tr("Select color scheme:"),
+                    colorSchemes,
+                    0, False)
+                if ok:
+                    colorSchemeIndex = colorSchemes.index(colorScheme)
+                else:
+                    # light background as default
+                    colorSchemeIndex = 0
+                QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
+                QApplication.processEvents()
+                html = self.__generateFromMarkdown(colorSchemeIndex == 1)
             elif (
                 extension in Preferences.getEditor(
                     "PreviewRestFileNameExtensions") or
@@ -503,10 +521,13 @@
         sys.stderr = origStderr
         return html
     
-    def __generateFromMarkdown(self):
+    def __generateFromMarkdown(self, useDarkScheme):
         """
         Private method to convert Markdown text into HTML.
         
+        @param useDarkScheme flag indicating to export using a dark color
+            scheme
+        @type bool
         @return processed HTML
         @rtype str
         """
@@ -534,7 +555,7 @@
         
         mermaidNeeded = False
         if Preferences.getEditor("PreviewMarkdownMermaid"):
-            if MarkdownExtensions.MermaidRegex.search(text):
+            if MarkdownExtensions.MermaidRegexFullText.search(text):
                 extensions.append(MarkdownExtensions.MermaidExtension())
                 mermaidNeeded = True
         
@@ -592,12 +613,37 @@
                 " src='https://unpkg.com/mermaid@8/dist/mermaid.min.js'>\n"
                 "</script>\n"
             )
+            if useDarkScheme:
+                mermaid_initialize = (
+                    "<script>mermaid.initialize({"
+                    "theme: 'dark', "
+                    "startOnLoad:true"
+                    "});</script>"
+                )
+            else:
+                mermaid_initialize = (
+                    "<script>mermaid.initialize({"
+                    "theme: 'default', "
+                    "startOnLoad:true"
+                    "});</script>"
+                )
         else:
             mermaid = ""
+            mermaid_initialize = ""
         
         htmlFormat = Preferences.getEditor("PreviewMarkdownHTMLFormat").lower()
         body = markdown.markdown(text, extensions=extensions,
                                  output_format=htmlFormat)
+        if useDarkScheme:
+            style = (
+                PreviewerHTMLStyles.css_markdown_dark +
+                PreviewerHTMLStyles.css_pygments_dark
+            )
+        else:
+            style = (
+                PreviewerHTMLStyles.css_markdown_light +
+                PreviewerHTMLStyles.css_pygments_light
+            )
         
         if htmlFormat == "xhtml1":
             head = (
@@ -632,12 +678,8 @@
             '''</style>\n'''
             '''</head>\n'''
             '''<body>\n'''
-        ).format(
-            mathjax, mermaid,
-            PreviewerHTMLStyles.css_markdown +
-            PreviewerHTMLStyles.css_pygments
-        )
+        ).format(mathjax, mermaid, style)
         
         foot = '''\n</body>\n</html>\n'''
         
-        return head + body + foot
+        return head + body + mermaid_initialize + foot

eric ide

mercurial