diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/UI/Previewers/MarkdownExtensions.py --- a/src/eric7/UI/Previewers/MarkdownExtensions.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/UI/Previewers/MarkdownExtensions.py Wed Jul 13 14:55:47 2022 +0200 @@ -21,22 +21,19 @@ ## License: GNU GPLv3 ###################################################################### -MermaidRegex = re.compile( - r"^(?P<mermaid_sign>[\~\`]){3}[ \t]*[Mm]ermaid[ \t]*$" -) -MermaidRegexFullText = re.compile( - r"([\~\`]){3}[ \t]*[Mm]ermaid" -) +MermaidRegex = re.compile(r"^(?P<mermaid_sign>[\~\`]){3}[ \t]*[Mm]ermaid[ \t]*$") +MermaidRegexFullText = re.compile(r"([\~\`]){3}[ \t]*[Mm]ermaid") class MermaidPreprocessor(Preprocessor): """ Class implementing a markdown pre-processor for Mermaid. """ + def run(self, lines): """ Public method to do the pre-processing. - + @param lines text lines to be processed @type list of str @return processed lines @@ -69,15 +66,11 @@ new_lines.append('<div class="mermaid">') m_start = None elif m_end: - new_lines.append('</div>') + new_lines.append("</div>") new_lines.append("") m_end = None elif in_mermaid_code: - new_lines.append( - line.strip() - .replace("<", "<") - .replace(">", ">") - ) + new_lines.append(line.strip().replace("<", "<").replace(">", ">")) else: new_lines.append(line) @@ -85,7 +78,7 @@ old_line = line if is_mermaid: - new_lines.append('') + new_lines.append("") return new_lines @@ -94,16 +87,18 @@ """ Class implementing a Markdown Extension for Mermaid. """ + def extendMarkdown(self, md, md_globals): """ Public method to register the extension. - + @param md reference to markdown @param md_globals global config parameters """ - md.preprocessors.register(MermaidPreprocessor(md), 'mermaid', 35) + md.preprocessors.register(MermaidPreprocessor(md), "mermaid", 35) md.registerExtension(self) + ###################################################################### ## Some extension to some basic additions ###################################################################### @@ -112,30 +107,36 @@ class SimplePatternExtension(Extension): """ Class implementing a Markdown extension for ~, ~~, ^, ^^ and ==. - + Note: This is a very simple pattern extension that might conflict with formulas set for MathJax. Use the 'pymdown-extensions' package in this case. """ - DEL_RE = r'(~~)(.+?)~~' - SUB_RE = r'(~)(.+?)~' - INS_RE = r'(\^\^)(.*?)\^\^' - SUP_RE = r'(\^)(.*?)\^' - MARK_RE = r'(==)(.*?)==' - + + DEL_RE = r"(~~)(.+?)~~" + SUB_RE = r"(~)(.+?)~" + INS_RE = r"(\^\^)(.*?)\^\^" + SUP_RE = r"(\^)(.*?)\^" + MARK_RE = r"(==)(.*?)==" + def extendMarkdown(self, md): """ Public method to register the extension. - + @param md reference to markdown """ md.inlinePatterns.register( - SimpleTagInlineProcessor(self.SUB_RE, 'sub'), 'subscript', 30) + SimpleTagInlineProcessor(self.SUB_RE, "sub"), "subscript", 30 + ) md.inlinePatterns.register( - SimpleTagInlineProcessor(self.DEL_RE, 'del'), 'deleted', 40) + SimpleTagInlineProcessor(self.DEL_RE, "del"), "deleted", 40 + ) md.inlinePatterns.register( - SimpleTagInlineProcessor(self.SUP_RE, 'sup'), 'superscript', 30) + SimpleTagInlineProcessor(self.SUP_RE, "sup"), "superscript", 30 + ) md.inlinePatterns.register( - SimpleTagInlineProcessor(self.INS_RE, 'ins'), 'inserted', 40) + SimpleTagInlineProcessor(self.INS_RE, "ins"), "inserted", 40 + ) md.inlinePatterns.register( - SimpleTagInlineProcessor(self.MARK_RE, 'mark'), 'mark', 40) + SimpleTagInlineProcessor(self.MARK_RE, "mark"), "mark", 40 + )