markdown: Fix imports for compatibility with typeshed stubs.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-10-18 21:37:43 -07:00
parent f294688157
commit 08c64f5cfa
5 changed files with 25 additions and 15 deletions

View File

@ -33,6 +33,11 @@ import ahocorasick
import dateutil.parser
import dateutil.tz
import markdown
import markdown.blockprocessors
import markdown.inlinepatterns
import markdown.postprocessors
import markdown.treeprocessors
import markdown.util
import requests
from django.conf import settings
from django.db.models import Q

View File

@ -79,9 +79,11 @@ import re
from typing import Any, Dict, Iterable, List, Mapping, MutableSequence, Optional
import lxml.html
import markdown
from django.utils.html import escape
from markdown import Markdown
from markdown.extensions import Extension
from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension
from markdown.preprocessors import Preprocessor
from pygments.lexers import get_lexer_by_name
from pygments.util import ClassNotFound
@ -137,7 +139,7 @@ CODE_VALIDATORS = {
'curl': validate_curl_content,
}
class FencedCodeExtension(markdown.Extension):
class FencedCodeExtension(Extension):
def __init__(self, config: Mapping[str, Any] = {}) -> None:
self.config = {
'run_content_validators': [
@ -149,7 +151,7 @@ class FencedCodeExtension(markdown.Extension):
for key, value in config.items():
self.setConfig(key, value)
def extendMarkdown(self, md: markdown.Markdown) -> None:
def extendMarkdown(self, md: Markdown) -> None:
""" Add FencedBlockPreprocessor to the Markdown instance. """
md.registerExtension(self)
processor = FencedBlockPreprocessor(
@ -321,9 +323,9 @@ class TexHandler(BaseHandler):
self.processor.pop()
class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
def __init__(self, md: markdown.Markdown, run_content_validators: bool=False) -> None:
markdown.preprocessors.Preprocessor.__init__(self, md)
class FencedBlockPreprocessor(Preprocessor):
def __init__(self, md: Markdown, run_content_validators: bool=False) -> None:
super().__init__(md)
self.checked_for_codehilite = False
self.run_content_validators = run_content_validators

View File

@ -2,7 +2,8 @@ import re
from typing import Any, List
from typing.re import Match
import markdown
from markdown import Markdown
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor
from zerver.lib.emoji import EMOTICON_CONVERSIONS, name_to_codepoint
@ -35,8 +36,8 @@ ROW_HTML = """\
</tr>
"""
class EmoticonTranslationsHelpExtension(markdown.Extension):
def extendMarkdown(self, md: markdown.Markdown) -> None:
class EmoticonTranslationsHelpExtension(Extension):
def extendMarkdown(self, md: Markdown) -> None:
""" Add SettingHelpExtension to the Markdown instance. """
md.registerExtension(self)
md.preprocessors.register(EmoticonTranslation(), 'emoticon_translations', -505)

View File

@ -2,7 +2,8 @@ import re
from typing import Any, List, Optional
from typing.re import Match
import markdown
from markdown import Markdown
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor
# There is a lot of duplicated code between this file and
@ -66,8 +67,8 @@ LINK_TYPE_HANDLERS = {
'stream': stream_handle_match,
}
class RelativeLinksHelpExtension(markdown.Extension):
def extendMarkdown(self, md: markdown.Markdown) -> None:
class RelativeLinksHelpExtension(Extension):
def extendMarkdown(self, md: Markdown) -> None:
""" Add RelativeLinksHelpExtension to the Markdown instance. """
md.registerExtension(self)
md.preprocessors.register(RelativeLinks(), 'help_relative_links', 520)

View File

@ -2,7 +2,8 @@ import re
from typing import Any, List, Optional
from typing.re import Match
import markdown
from markdown import Markdown
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor
# There is a lot of duplicated code between this file and
@ -62,8 +63,8 @@ settings_markdown = """
"""
class SettingHelpExtension(markdown.Extension):
def extendMarkdown(self, md: markdown.Markdown) -> None:
class SettingHelpExtension(Extension):
def extendMarkdown(self, md: Markdown) -> None:
""" Add SettingHelpExtension to the Markdown instance. """
md.registerExtension(self)
md.preprocessors.register(Setting(), 'setting', 515)