markdown: Organize preprocessor priorities in one place.

All of our custom Markdown extensions have priorities that govern
the order in which the preprocessors will be run. It is more
convenient to have these all in one file so that you can easily
discern the order at first glance.

Thanks to Alya Abbott for reporting the bug that led to this
refactoring!
This commit is contained in:
Eeshan Garg
2021-09-17 13:01:36 -04:00
committed by Tim Abbott
parent 6367384510
commit bfbd77ca5c
11 changed files with 66 additions and 14 deletions

View File

@@ -5,6 +5,8 @@ import markdown
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor
from zerver.lib.markdown.preprocessor_priorities import PREPROCESSOR_PRIORITES
START_TABBED_SECTION_REGEX = re.compile(r"^\{start_tabs\}$")
END_TABBED_SECTION_REGEX = re.compile(r"^\{end_tabs\}$")
TAB_CONTENT_REGEX = re.compile(r"^\{tab\|\s*(.+?)\s*\}$")
@@ -76,7 +78,9 @@ TAB_DISPLAY_NAMES = {
class TabbedSectionsGenerator(Extension):
def extendMarkdown(self, md: markdown.Markdown) -> None:
md.preprocessors.register(
TabbedSectionsPreprocessor(md, self.getConfigs()), "tabbed_sections", -500
TabbedSectionsPreprocessor(md, self.getConfigs()),
"tabbed_sections",
PREPROCESSOR_PRIORITES["tabbed_sections"],
)