Thu, 24 Oct 2019 19:30:01 +0200
PreviewerHTML, ExporterHTML:
- enhanced the Markdown previewer to support Mermaid via the md_mermaid extension, if it is available and has been enabled.
--- a/eric6/Preferences/ConfigurationPages/EditorFilePage.py Wed Oct 23 20:06:12 2019 +0200 +++ b/eric6/Preferences/ConfigurationPages/EditorFilePage.py Thu Oct 24 19:30:01 2019 +0200 @@ -100,6 +100,8 @@ Preferences.getEditor("PreviewMarkdownUsePyMdownExtensions")) self.previewMarkdownMathJaxCheckBox.setChecked( Preferences.getEditor("PreviewMarkdownMathJax")) + self.previewMarkdownMermaidCheckBox.setChecked( + Preferences.getEditor("PreviewMarkdownMermaid")) index = self.previewMarkdownHTMLFormatComboBox.findText( Preferences.getEditor("PreviewMarkdownHTMLFormat")) self.previewMarkdownHTMLFormatComboBox.setCurrentIndex(index) @@ -188,6 +190,9 @@ "PreviewMarkdownMathJax", self.previewMarkdownMathJaxCheckBox.isChecked()) Preferences.setEditor( + "PreviewMarkdownMermaid", + self.previewMarkdownMermaidCheckBox.isChecked()) + Preferences.setEditor( "PreviewMarkdownHTMLFormat", self.previewMarkdownHTMLFormatComboBox.currentText())
--- a/eric6/Preferences/ConfigurationPages/EditorFilePage.ui Wed Oct 23 20:06:12 2019 +0200 +++ b/eric6/Preferences/ConfigurationPages/EditorFilePage.ui Thu Oct 24 19:30:01 2019 +0200 @@ -554,7 +554,17 @@ <string>Select to enable Math support using MathJax</string> </property> <property name="text"> - <string>Enable MathJax support</string> + <string>Enable Math support</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QCheckBox" name="previewMarkdownMermaidCheckBox"> + <property name="toolTip"> + <string>Select to enable Graph support using Mermaid</string> + </property> + <property name="text"> + <string>Enable Graph support</string> </property> </widget> </item> @@ -694,6 +704,7 @@ <tabstop>previewMarkdownNLtoBreakCheckBox</tabstop> <tabstop>previewMarkdownPyMdownCheckBox</tabstop> <tabstop>previewMarkdownMathJaxCheckBox</tabstop> + <tabstop>previewMarkdownMermaidCheckBox</tabstop> <tabstop>previewRestExtensionsEdit</tabstop> <tabstop>previewRestSphinxCheckBox</tabstop> <tabstop>previewRestDocutilsHTMLFormatComboBox</tabstop>
--- a/eric6/Preferences/__init__.py Wed Oct 23 20:06:12 2019 +0200 +++ b/eric6/Preferences/__init__.py Thu Oct 24 19:30:01 2019 +0200 @@ -479,6 +479,7 @@ "PreviewMarkdownNLtoBR": True, "PreviewMarkdownUsePyMdownExtensions": True, "PreviewMarkdownMathJax": True, + "PreviewMarkdownMermaid": True, "PreviewMarkdownHTMLFormat": "HTML5", # XHTML1, HTML4, HTML5 "PreviewRestDocutilsHTMLFormat": "HTML5", # HTML4, HTML5
--- a/eric6/QScintilla/Exporters/ExporterHTML.py Wed Oct 23 20:06:12 2019 +0200 +++ b/eric6/QScintilla/Exporters/ExporterHTML.py Thu Oct 24 19:30:01 2019 +0200 @@ -526,25 +526,34 @@ return "" extensions = [] + + if Preferences.getEditor("PreviewMarkdownMermaid"): + try: + import md_mermaid # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ + extensions.append("md_mermaid") + except ImportError: + pass + + if Preferences.getEditor("PreviewMarkdownNLtoBR"): + extensions.append('nl2br') + + pyMdown = False if Preferences.getEditor("PreviewMarkdownUsePyMdownExtensions"): try: import pymdownx # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ # PyPI package is 'pymdown-extensions' - extensions = [ + extensions.extend([ 'pymdownx.extra', 'pymdownx.caret', 'pymdownx.emoji', 'pymdownx.mark', 'pymdownx.tilde', 'pymdownx.keys', 'pymdownx.tasklist', 'pymdownx.smartsymbols', - ] - if Preferences.getEditor("PreviewMarkdownNLtoBR"): - extensions.append('nl2br') + ]) + pyMdown = True except ImportError: pass - if not extensions: - if Preferences.getEditor("PreviewMarkdownNLtoBR"): - extensions = ['fenced_code', 'nl2br', 'extra'] - else: - extensions = ['fenced_code', 'extra'] + + if not pyMdown: + extensions.extend(['extra', 'toc']) # version 2.0 supports only extension names, not instances if ( @@ -621,6 +630,8 @@ _TildeExtension(), _CaretExtension(), _MarkExtension() ]) + text = self.editor.text() + if Preferences.getEditor("PreviewMarkdownMathJax"): mathjax = ( "<script type='text/javascript' id='MathJax-script' async" @@ -628,12 +639,28 @@ "tex-chtml.js'>\n" "</script>\n" ) + # prepare text for mathjax + text = ( + text + .replace(r"\(", r"\\(") + .replace(r"\)", r"\\)") + .replace(r"\[", r"\\[") + .replace(r"\]", r"\\]") + ) else: mathjax = "" + if Preferences.getEditor("PreviewMarkdownMermaid"): + mermaid = ( + "<script type='text/javascript' id='Mermaid-script'" + " src='https://unpkg.com/mermaid@8/dist/mermaid.min.js'>\n" + "</script>\n" + ) + else: + mermaid = "" + htmlFormat = Preferences.getEditor("PreviewMarkdownHTMLFormat").lower() - body = markdown.markdown(self.editor.text(), - extensions=extensions, + body = markdown.markdown(text, extensions=extensions, output_format=htmlFormat) if htmlFormat == "xhtml1": @@ -663,9 +690,10 @@ '''<meta http-equiv="Content-Type" ''' '''content="text/html; charset=utf-8" />\n''' '''{0}''' + '''{1}''' '''</head>\n''' '''<body>\n''' - ).format(mathjax) + ).format(mathjax, mermaid) foot = '''\n</body>\n</html>\n'''
--- a/eric6/UI/Previewers/PreviewerHTML.py Wed Oct 23 20:06:12 2019 +0200 +++ b/eric6/UI/Previewers/PreviewerHTML.py Thu Oct 24 19:30:01 2019 +0200 @@ -679,25 +679,34 @@ """installation instructions.</a></p>""") extensions = [] + + if Preferences.getEditor("PreviewMarkdownMermaid"): + try: + import md_mermaid # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ + extensions.append("md_mermaid") + except ImportError: + pass + + if convertNewLineToBreak: + extensions.append('nl2br') + + pyMdown = False if usePyMdownExtensions: try: import pymdownx # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ # PyPI package is 'pymdown-extensions' - extensions = [ + extensions.extend([ 'pymdownx.extra', 'pymdownx.caret', 'pymdownx.emoji', 'pymdownx.mark', 'pymdownx.tilde', 'pymdownx.keys', 'pymdownx.tasklist', 'pymdownx.smartsymbols', - ] - if convertNewLineToBreak: - extensions.append('nl2br') + ]) + pyMdown = True except ImportError: pass - if not extensions: - if convertNewLineToBreak: - extensions = ['extra', 'toc', 'nl2br'] - else: - extensions = ['extra', 'toc'] + + if not pyMdown: + extensions.extend(['extra', 'toc']) # version 2.0 supports only extension names, not instances if ( @@ -781,9 +790,26 @@ "tex-chtml.js'>\n" "</script>\n" ) + # prepare text for mathjax + text = ( + text + .replace(r"\(", r"\\(") + .replace(r"\)", r"\\)") + .replace(r"\[", r"\\[") + .replace(r"\]", r"\\]") + ) else: mathjax = "" + if Preferences.getEditor("PreviewMarkdownMermaid"): + mermaid = ( + "<script type='text/javascript' id='Mermaid-script'" + " src='https://unpkg.com/mermaid@8/dist/mermaid.min.js'>\n" + "</script>\n" + ) + else: + mermaid = "" + htmlFormat = Preferences.getEditor("PreviewMarkdownHTMLFormat").lower() body = markdown.markdown(text, extensions=extensions, output_format=htmlFormat.lower()) @@ -809,9 +835,10 @@ '''<meta http-equiv="Content-Type" ''' '''content="text/html; charset=utf-8" />\n''' '''{0}''' + '''{1}''' '''</head>\n''' '''<body>\n''' - ).format(mathjax) + ).format(mathjax, mermaid) foot = '''\n</body>\n</html>\n'''