Skip to content

Commit

Permalink
Various improvements to Markdown stubs (python#10963)
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin authored Nov 2, 2023
1 parent 5122e84 commit 1965076
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 165 deletions.
5 changes: 0 additions & 5 deletions stubs/Markdown/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
markdown.extensions.abbr.ABBR_REF_RE
markdown.extensions.attr_list.AttrListTreeprocessor.run
markdown.extensions.codehilite.CodeHilite.__init__
markdown.extensions.fenced_code.FencedBlockPreprocessor.__init__
markdown.extensions.footnotes.DEF_RE
markdown.extensions.footnotes.FootnotePreprocessor
markdown.extensions.footnotes.TABBED_RE
markdown.extensions.legacy_attrs.LegacyAttrs.run
markdown.extensions.toc.TocTreeprocessor.run
markdown.extensions.toc.slugify
markdown.postprocessors.UnescapePostprocessor # deprecated
6 changes: 3 additions & 3 deletions stubs/Markdown/markdown/blockparser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ from collections.abc import Iterable
from typing import Any, TypeVar
from xml.etree.ElementTree import Element, ElementTree

from . import Markdown
from .util import Registry
from markdown import blockprocessors, util
from markdown.core import Markdown

_T = TypeVar("_T")

Expand All @@ -13,7 +13,7 @@ class State(list[_T]):
def isstate(self, state: _T) -> bool: ...

class BlockParser:
blockprocessors: Registry
blockprocessors: util.Registry[blockprocessors.BlockProcessor]
state: State[Any] # TODO: possible to get rid of Any?
md: Markdown
def __init__(self, md: Markdown) -> None: ...
Expand Down
7 changes: 3 additions & 4 deletions stubs/Markdown/markdown/blockprocessors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ from re import Match, Pattern
from typing import Any, ClassVar
from xml.etree.ElementTree import Element

from markdown import Markdown

from .blockparser import BlockParser
from markdown.blockparser import BlockParser
from markdown.core import Markdown

logger: Logger

def build_block_parser(md: Markdown, **kwargs: Any): ...
def build_block_parser(md: Markdown, **kwargs: Any) -> BlockParser: ...

class BlockProcessor:
parser: BlockParser
Expand Down
26 changes: 13 additions & 13 deletions stubs/Markdown/markdown/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import Any, ClassVar, Protocol
from typing_extensions import Literal, Self
from xml.etree.ElementTree import Element

from .blockparser import BlockParser
from . import blockparser, inlinepatterns, postprocessors, preprocessors, treeprocessors
from .extensions import Extension
from .util import HtmlStash, Registry

Expand All @@ -20,11 +20,11 @@ class _ReadableStream(Protocol):
def close(self) -> object: ...

class Markdown:
preprocessors: Registry
inlinePatterns: Registry
treeprocessors: Registry
postprocessors: Registry
parser: BlockParser
preprocessors: Registry[preprocessors.Preprocessor]
inlinePatterns: Registry[inlinepatterns.InlineProcessor]
treeprocessors: Registry[treeprocessors.Treeprocessor]
postprocessors: Registry[postprocessors.Postprocessor]
parser: blockparser.BlockParser
htmlStash: HtmlStash
output_formats: ClassVar[dict[Literal["xhtml", "html"], Callable[[Element], str]]]
output_format: Literal["xhtml", "html"]
Expand All @@ -41,17 +41,17 @@ class Markdown:
output_format: Literal["xhtml", "html"] | None = ...,
tab_length: int | None = ...,
) -> None: ...
def build_parser(self) -> Markdown: ...
def registerExtensions(self, extensions: Sequence[Extension | str], configs: Mapping[str, Mapping[str, Any]]) -> Markdown: ...
def build_extension(self, ext_name: str, configs: Mapping[str, str]) -> Extension: ...
def registerExtension(self, extension: Extension) -> Markdown: ...
def build_parser(self) -> Self: ...
def registerExtensions(self, extensions: Sequence[Extension | str], configs: Mapping[str, dict[str, Any]]) -> Self: ...
def build_extension(self, ext_name: str, configs: Mapping[str, Any]) -> Extension: ...
def registerExtension(self, extension: Extension) -> Self: ...
def reset(self) -> Self: ...
def set_output_format(self, format: Literal["xhtml", "html"]) -> Markdown: ...
def is_block_level(self, tag: str) -> bool: ...
def set_output_format(self, format: Literal["xhtml", "html"]) -> Self: ...
def is_block_level(self, tag: object) -> bool: ...
def convert(self, source: str) -> str: ...
def convertFile(
self, input: str | _ReadableStream | None = None, output: str | _WritableStream | None = None, encoding: str | None = None
) -> Markdown: ...
) -> Self: ...

def markdown(
text: str,
Expand Down
4 changes: 2 additions & 2 deletions stubs/Markdown/markdown/extensions/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Mapping
from collections.abc import Iterable, Mapping
from typing import Any

from markdown.core import Markdown
Expand All @@ -10,5 +10,5 @@ class Extension:
def getConfigs(self) -> dict[str, Any]: ...
def getConfigInfo(self) -> list[tuple[str, str]]: ...
def setConfig(self, key: str, value: Any) -> None: ...
def setConfigs(self, items: Mapping[str, Any]) -> None: ...
def setConfigs(self, items: Mapping[str, Any] | Iterable[tuple[str, Any]]) -> None: ...
def extendMarkdown(self, md: Markdown) -> None: ...
4 changes: 2 additions & 2 deletions stubs/Markdown/markdown/extensions/abbr.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class AbbrPreprocessor(BlockProcessor): ...

class AbbrInlineProcessor(InlineProcessor):
title: Any
def __init__(self, pattern, title) -> None: ...
def __init__(self, pattern: str, title: str) -> None: ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> AbbrExtension: ...
10 changes: 7 additions & 3 deletions stubs/Markdown/markdown/extensions/admonition.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from re import Pattern
from re import Match, Pattern
from typing import Any
from xml.etree.ElementTree import Element

from markdown import blockparser
from markdown.blockprocessors import BlockProcessor
from markdown.extensions import Extension

Expand All @@ -11,6 +13,8 @@ class AdmonitionProcessor(BlockProcessor):
CLASSNAME_TITLE: str
RE: Pattern[str]
RE_SPACES: Any
def get_class_and_title(self, match): ...
def __init__(self, parser: blockparser.BlockParser): ...
def parse_content(self, parent: Element, block: str) -> tuple[Element | None, str, str]: ...
def get_class_and_title(self, match: Match[str]) -> tuple[str, str | None]: ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> AdmonitionExtension: ...
11 changes: 6 additions & 5 deletions stubs/Markdown/markdown/extensions/attr_list.pyi
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from re import Pattern
from xml.etree.ElementTree import Element

from markdown.extensions import Extension
from markdown.treeprocessors import Treeprocessor

def get_attrs(str): ...
def isheader(elem): ...
def get_attrs(str: str) -> list[tuple[str, str]]: ...
def isheader(elem: Element) -> bool: ...

class AttrListTreeprocessor(Treeprocessor):
BASE_RE: str
HEADER_RE: Pattern[str]
BLOCK_RE: Pattern[str]
INLINE_RE: Pattern[str]
NAME_RE: Pattern[str]
def assign_attrs(self, elem, attrs) -> None: ...
def sanitize_name(self, name): ...
def assign_attrs(self, elem: Element, attrs: str) -> None: ...
def sanitize_name(self, name: str) -> str: ...

class AttrListExtension(Extension): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> AttrListExtension: ...
13 changes: 6 additions & 7 deletions stubs/Markdown/markdown/extensions/codehilite.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from _typeshed import Incomplete
from typing import Any

from markdown.extensions import Extension
Expand All @@ -22,25 +21,25 @@ class CodeHilite:
options: dict[str, Any]
def __init__(
self,
src: Incomplete | None = ...,
src: str,
*,
linenums: Incomplete | None = ...,
linenums: bool | None = None,
guess_lang: bool = ...,
css_class: str = ...,
lang: Incomplete | None = ...,
lang: str | None = ...,
style: str = ...,
noclasses: bool = ...,
tab_length: int = ...,
hl_lines: Incomplete | None = ...,
hl_lines: list[int] = ...,
use_pygments: bool = ...,
**options: Any,
) -> None: ...
def hilite(self, shebang: bool = True) -> str: ...

class HiliteTreeprocessor(Treeprocessor):
def code_unescape(self, text): ...
def code_unescape(self, text: str) -> str: ...

class CodeHiliteExtension(Extension):
def __init__(self, **kwargs) -> None: ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> CodeHiliteExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/def_list.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class DefListProcessor(BlockProcessor):
class DefListIndentProcessor(ListIndentProcessor): ...
class DefListExtension(Extension): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> DefListExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/extra.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ extensions: Any
class ExtraExtension(Extension):
def __init__(self, **kwargs) -> None: ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> ExtraExtension: ...
10 changes: 5 additions & 5 deletions stubs/Markdown/markdown/extensions/fenced_code.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from _typeshed import Incomplete
from re import Pattern
from typing import ClassVar
from typing import Any, ClassVar

from markdown.core import Markdown
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor

class FencedCodeExtension(Extension): ...

class FencedBlockPreprocessor(Preprocessor):
FENCED_BLOCK_RE: ClassVar[Pattern[str]]
codehilite_conf: dict[Incomplete, Incomplete]
def __init__(self, md) -> None: ...
codehilite_conf: dict[str, Any]
def __init__(self, md: Markdown, config: dict[str, Any]) -> None: ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> FencedCodeExtension: ...
42 changes: 19 additions & 23 deletions stubs/Markdown/markdown/extensions/footnotes.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from collections import OrderedDict
from re import Pattern
from typing import Any
from xml.etree.ElementTree import Element

from markdown.core import Markdown
from markdown.extensions import Extension
from markdown.inlinepatterns import InlineProcessor
from markdown.postprocessors import Postprocessor
from markdown.preprocessors import Preprocessor
from markdown.treeprocessors import Treeprocessor

FN_BACKLINK_TEXT: Any
Expand All @@ -21,39 +22,34 @@ class FootnoteExtension(Extension):
def __init__(self, **kwargs) -> None: ...
parser: Any
md: Markdown
footnotes: Any
footnotes: OrderedDict[str, str]
def reset(self) -> None: ...
def unique_ref(self, reference, found: bool = False): ...
def findFootnotesPlaceholder(self, root): ...
def setFootnote(self, id, text) -> None: ...
def get_separator(self): ...
def makeFootnoteId(self, id): ...
def makeFootnoteRefId(self, id, found: bool = False): ...
def makeFootnotesDiv(self, root): ...

class FootnotePreprocessor(Preprocessor):
footnotes: Any
def __init__(self, footnotes) -> None: ...
def detectTabbed(self, lines): ...
def unique_ref(self, reference: str, found: bool = False) -> str: ...
def findFootnotesPlaceholder(self, root: Element): ...
def setFootnote(self, id: str, text: str) -> None: ...
def get_separator(self) -> str: ...
def makeFootnoteId(self, id: str) -> str: ...
def makeFootnoteRefId(self, id: str, found: bool = False) -> str: ...
def makeFootnotesDiv(self, root: Element) -> Element | None: ...

class FootnoteInlineProcessor(InlineProcessor):
footnotes: Any
def __init__(self, pattern, footnotes) -> None: ...
footnotes: FootnoteExtension
def __init__(self, pattern: str, footnotes: FootnoteExtension) -> None: ...

class FootnotePostTreeprocessor(Treeprocessor):
footnotes: Any
def __init__(self, footnotes) -> None: ...
footnotes: FootnoteExtension
def __init__(self, footnotes: FootnoteExtension) -> None: ...
def add_duplicates(self, li, duplicates) -> None: ...
def get_num_duplicates(self, li): ...
def handle_duplicates(self, parent) -> None: ...
offset: int

class FootnoteTreeprocessor(Treeprocessor):
footnotes: Any
def __init__(self, footnotes) -> None: ...
footnotes: FootnoteExtension
def __init__(self, footnotes: FootnoteExtension) -> None: ...

class FootnotePostprocessor(Postprocessor):
footnotes: Any
def __init__(self, footnotes) -> None: ...
footnotes: FootnoteExtension
def __init__(self, footnotes: FootnoteExtension) -> None: ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> FootnoteExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/legacy_attrs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class LegacyAttrs(Treeprocessor):

class LegacyAttrExtension(Extension): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> LegacyAttrExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/legacy_em.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ STRONG_EM_RE: str
class LegacyUnderscoreProcessor(UnderscoreProcessor): ...
class LegacyEmExtension(Extension): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> LegacyEmExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/md_in_html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ from markdown.extensions import Extension
class MarkdownInHtmlProcessor(BlockProcessor): ...
class MarkdownInHtmlExtension(Extension): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> MarkdownInHtmlExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/meta.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class MetaExtension(Extension):

class MetaPreprocessor(Preprocessor): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> MetaExtension: ...
2 changes: 1 addition & 1 deletion stubs/Markdown/markdown/extensions/nl2br.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ BR_RE: str

class Nl2BrExtension(Extension): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> Nl2BrExtension: ...
7 changes: 4 additions & 3 deletions stubs/Markdown/markdown/extensions/sane_lists.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from markdown import blockparser
from markdown.blockprocessors import OListProcessor, UListProcessor
from markdown.extensions import Extension

class SaneOListProcessor(OListProcessor):
def __init__(self, parser) -> None: ...
def __init__(self, parser: blockparser.BlockParser) -> None: ...

class SaneUListProcessor(UListProcessor):
def __init__(self, parser) -> None: ...
def __init__(self, parser: blockparser.BlockParser) -> None: ...

class SaneListExtension(Extension): ...

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> SaneListExtension: ...
20 changes: 12 additions & 8 deletions stubs/Markdown/markdown/extensions/smarty.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from collections.abc import Sequence
from typing import Any
from xml.etree.ElementTree import Element

from markdown import inlinepatterns, util
from markdown.core import Markdown
from markdown.extensions import Extension
from markdown.inlinepatterns import HtmlInlineProcessor

Expand All @@ -24,16 +28,16 @@ remainingDoubleQuotesRegex: str
HTML_STRICT_RE: str

class SubstituteTextPattern(HtmlInlineProcessor):
replace: Any
def __init__(self, pattern, replace, md) -> None: ...
replace: Sequence[int | str | Element]
def __init__(self, pattern: str, replace: Sequence[int | str | Element], md: Markdown) -> None: ...

class SmartyExtension(Extension):
substitutions: Any
def __init__(self, **kwargs) -> None: ...
def educateDashes(self, md) -> None: ...
def educateEllipses(self, md) -> None: ...
def educateAngledQuotes(self, md) -> None: ...
def educateQuotes(self, md) -> None: ...
inlinePatterns: Any
def educateDashes(self, md: Markdown) -> None: ...
def educateEllipses(self, md: Markdown) -> None: ...
def educateAngledQuotes(self, md: Markdown) -> None: ...
def educateQuotes(self, md: Markdown) -> None: ...
inlinePatterns: util.Registry[inlinepatterns.InlineProcessor]

def makeExtension(**kwargs): ...
def makeExtension(**kwargs) -> SmartyExtension: ...
Loading

0 comments on commit 1965076

Please sign in to comment.