676 """package.<br/>Install it with your package manager,""" |
676 """package.<br/>Install it with your package manager,""" |
677 """ 'pip install Markdown' or see """ |
677 """ 'pip install Markdown' or see """ |
678 """<a href="http://pythonhosted.org/Markdown/install.html">""" |
678 """<a href="http://pythonhosted.org/Markdown/install.html">""" |
679 """installation instructions.</a></p>""") |
679 """installation instructions.</a></p>""") |
680 |
680 |
|
681 from . import PreviewerHTMLStyles |
|
682 from . import MarkdownExtensions |
|
683 |
681 extensions = [] |
684 extensions = [] |
682 |
685 |
|
686 mermaidNeeded = False |
683 if Preferences.getEditor("PreviewMarkdownMermaid"): |
687 if Preferences.getEditor("PreviewMarkdownMermaid"): |
684 try: |
688 if MarkdownExtensions.MermaidRegexFullText.search(text): |
685 import md_mermaid # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ |
689 extensions.append(MarkdownExtensions.MermaidExtension()) |
686 extensions.append("md_mermaid") |
690 mermaidNeeded = True |
687 except ImportError: |
|
688 pass |
|
689 |
691 |
690 if convertNewLineToBreak: |
692 if convertNewLineToBreak: |
691 extensions.append('nl2br') |
693 extensions.append('nl2br') |
692 |
694 |
693 pyMdown = False |
695 pyMdown = False |
695 try: |
697 try: |
696 import pymdownx # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ |
698 import pymdownx # __IGNORE_EXCEPTION__ __IGNORE_WARNING__ |
697 # PyPI package is 'pymdown-extensions' |
699 # PyPI package is 'pymdown-extensions' |
698 |
700 |
699 extensions.extend([ |
701 extensions.extend([ |
|
702 'toc', |
700 'pymdownx.extra', 'pymdownx.caret', 'pymdownx.emoji', |
703 'pymdownx.extra', 'pymdownx.caret', 'pymdownx.emoji', |
701 'pymdownx.mark', 'pymdownx.tilde', 'pymdownx.keys', |
704 'pymdownx.mark', 'pymdownx.tilde', 'pymdownx.keys', |
702 'pymdownx.tasklist', 'pymdownx.smartsymbols', |
705 'pymdownx.tasklist', 'pymdownx.smartsymbols', |
703 ]) |
706 ]) |
704 pyMdown = True |
707 pyMdown = True |
712 if ( |
715 if ( |
713 markdown.version_info[0] > 2 or |
716 markdown.version_info[0] > 2 or |
714 (markdown.version_info[0] == 2 and |
717 (markdown.version_info[0] == 2 and |
715 markdown.version_info[1] > 0) |
718 markdown.version_info[1] > 0) |
716 ): |
719 ): |
717 class _TildeExtension(markdown.Extension): |
720 extensions.append(MarkdownExtensions.SimplePatternExtension()) |
718 """ |
|
719 Class is placed here, because it depends on imported |
|
720 markdown, and markdown import is lazy. |
|
721 |
|
722 (see https://pythonhosted.org/Markdown/extensions/api.html |
|
723 this page for details) |
|
724 """ |
|
725 DEL_RE = r'(~~)(.+?)~~' |
|
726 SUB_RE = r'(~)(.+?)~' |
|
727 |
|
728 def extendMarkdown(self, md, md_globals): |
|
729 # Create the sub pattern and insert it into markdown |
|
730 # parser |
|
731 sub_tag = markdown.inlinepatterns.SimpleTagPattern( |
|
732 self.SUB_RE, 'sub') |
|
733 md.inlinePatterns.add('sub', sub_tag, '>not_strong') |
|
734 |
|
735 # Create the del pattern and insert it into markdown |
|
736 # parser |
|
737 del_tag = markdown.inlinepatterns.SimpleTagPattern( |
|
738 self.DEL_RE, 'del') |
|
739 md.inlinePatterns.add('del', del_tag, '>not_strong') |
|
740 |
|
741 class _CaretExtension(markdown.Extension): |
|
742 """ |
|
743 Class is placed here, because it depends on imported |
|
744 markdown, and markdown import is lazy. |
|
745 |
|
746 (see https://pythonhosted.org/Markdown/extensions/api.html |
|
747 this page for details) |
|
748 """ |
|
749 INS_RE = r'(\^\^)(.*?)\^\^' |
|
750 SUP_RE = r'(\^)(.*?)\^' |
|
751 |
|
752 def extendMarkdown(self, md, md_globals): |
|
753 # Create the sup pattern and insert it into markdown |
|
754 # parser |
|
755 sup_tag = markdown.inlinepatterns.SimpleTagPattern( |
|
756 self.SUP_RE, 'sup') |
|
757 md.inlinePatterns.add('sup', sup_tag, '>not_strong') |
|
758 |
|
759 # Create the ins pattern and insert it into markdown |
|
760 # parser |
|
761 ins_tag = markdown.inlinepatterns.SimpleTagPattern( |
|
762 self.INS_RE, 'ins') |
|
763 md.inlinePatterns.add('ins', ins_tag, '>not_strong') |
|
764 |
|
765 class _MarkExtension(markdown.Extension): |
|
766 """ |
|
767 Class is placed here, because it depends on imported |
|
768 markdown, and markdown import is lazy. |
|
769 |
|
770 (see https://pythonhosted.org/Markdown/extensions/api.html |
|
771 this page for details) |
|
772 """ |
|
773 MARK_RE = r'(==)(.*?)==' |
|
774 |
|
775 def extendMarkdown(self, md, md_globals): |
|
776 # Create the mark pattern and insert it into markdown |
|
777 # parser |
|
778 mark_tag = markdown.inlinepatterns.SimpleTagPattern( |
|
779 self.MARK_RE, 'mark') |
|
780 md.inlinePatterns.add('mark', mark_tag, '>not_strong') |
|
781 |
|
782 extensions.extend([ |
|
783 _TildeExtension(), _CaretExtension(), _MarkExtension() |
|
784 ]) |
|
785 |
721 |
786 if Preferences.getEditor("PreviewMarkdownMathJax"): |
722 if Preferences.getEditor("PreviewMarkdownMathJax"): |
787 mathjax = ( |
723 mathjax = ( |
788 "<script type='text/javascript' id='MathJax-script' async" |
724 "<script type='text/javascript' id='MathJax-script' async" |
789 " src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/" |
725 " src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/" |
834 '''<meta name="Generator" content="eric6" />\n''' |
770 '''<meta name="Generator" content="eric6" />\n''' |
835 '''<meta http-equiv="Content-Type" ''' |
771 '''<meta http-equiv="Content-Type" ''' |
836 '''content="text/html; charset=utf-8" />\n''' |
772 '''content="text/html; charset=utf-8" />\n''' |
837 '''{0}''' |
773 '''{0}''' |
838 '''{1}''' |
774 '''{1}''' |
|
775 '''<style type="text/css">''' |
|
776 '''{2}''' |
|
777 '''</style>\n''' |
839 '''</head>\n''' |
778 '''</head>\n''' |
840 '''<body>\n''' |
779 '''<body>\n''' |
841 ).format(mathjax, mermaid) |
780 ).format( |
|
781 mathjax, mermaid, |
|
782 PreviewerHTMLStyles.css_markdown + |
|
783 PreviewerHTMLStyles.css_pygments |
|
784 ) |
842 |
785 |
843 foot = '''\n</body>\n</html>\n''' |
786 foot = '''\n</body>\n</html>\n''' |
844 |
787 |
845 return head + body + foot |
788 return head + body + foot |