Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/__init__.py +6 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/_compat.py +1 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/_punycode.py +67 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/cli/__init__.py +0 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/cli/parse.py +110 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/__init__.py +0 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/entities.py +5 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/html_blocks.py +69 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/html_re.py +39 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/normalize_url.py +81 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/utils.py +313 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/__init__.py +6 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/parse_link_destination.py +83 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/parse_link_label.py +44 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/parse_link_title.py +75 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/main.py +350 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/parser_block.py +113 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/parser_core.py +46 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/parser_inline.py +148 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/port.yaml +48 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/__init__.py +28 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/commonmark.py +75 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/default.py +36 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/zero.py +44 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/py.typed +1 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/renderer.py +336 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/ruler.py +275 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/__init__.py +27 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/blockquote.py +299 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/code.py +36 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/fence.py +101 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/heading.py +69 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/hr.py +56 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/html_block.py +90 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/lheading.py +86 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/list.py +345 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/paragraph.py +66 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/reference.py +235 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/state_block.py +261 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/table.py +250 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/__init__.py +19 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/block.py +13 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/inline.py +10 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/linkify.py +149 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/normalize.py +19 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/replacements.py +127 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/smartquotes.py +202 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/state_core.py +25 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/text_join.py +35 -0
- .cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_inline/__init__.py +31 -0
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A Python port of Markdown-It"""
|
| 2 |
+
|
| 3 |
+
__all__ = ("MarkdownIt",)
|
| 4 |
+
__version__ = "4.0.0"
|
| 5 |
+
|
| 6 |
+
from .main import MarkdownIt
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/_compat.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/_punycode.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2014 Mathias Bynens <https://mathiasbynens.be/>
|
| 2 |
+
# Copyright 2021 Taneli Hukkinen
|
| 3 |
+
#
|
| 4 |
+
# Permission is hereby granted, free of charge, to any person obtaining
|
| 5 |
+
# a copy of this software and associated documentation files (the
|
| 6 |
+
# "Software"), to deal in the Software without restriction, including
|
| 7 |
+
# without limitation the rights to use, copy, modify, merge, publish,
|
| 8 |
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
| 9 |
+
# permit persons to whom the Software is furnished to do so, subject to
|
| 10 |
+
# the following conditions:
|
| 11 |
+
#
|
| 12 |
+
# The above copyright notice and this permission notice shall be
|
| 13 |
+
# included in all copies or substantial portions of the Software.
|
| 14 |
+
#
|
| 15 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 16 |
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 17 |
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 18 |
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
| 19 |
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
| 20 |
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
| 21 |
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 22 |
+
|
| 23 |
+
import codecs
|
| 24 |
+
from collections.abc import Callable
|
| 25 |
+
import re
|
| 26 |
+
|
| 27 |
+
REGEX_SEPARATORS = re.compile(r"[\x2E\u3002\uFF0E\uFF61]")
|
| 28 |
+
REGEX_NON_ASCII = re.compile(r"[^\0-\x7E]")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def encode(uni: str) -> str:
|
| 32 |
+
return codecs.encode(uni, encoding="punycode").decode()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def decode(ascii: str) -> str:
|
| 36 |
+
return codecs.decode(ascii, encoding="punycode") # type: ignore
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def map_domain(string: str, fn: Callable[[str], str]) -> str:
|
| 40 |
+
parts = string.split("@")
|
| 41 |
+
result = ""
|
| 42 |
+
if len(parts) > 1:
|
| 43 |
+
# In email addresses, only the domain name should be punycoded. Leave
|
| 44 |
+
# the local part (i.e. everything up to `@`) intact.
|
| 45 |
+
result = parts[0] + "@"
|
| 46 |
+
string = parts[1]
|
| 47 |
+
labels = REGEX_SEPARATORS.split(string)
|
| 48 |
+
encoded = ".".join(fn(label) for label in labels)
|
| 49 |
+
return result + encoded
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def to_unicode(obj: str) -> str:
|
| 53 |
+
def mapping(obj: str) -> str:
|
| 54 |
+
if obj.startswith("xn--"):
|
| 55 |
+
return decode(obj[4:].lower())
|
| 56 |
+
return obj
|
| 57 |
+
|
| 58 |
+
return map_domain(obj, mapping)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def to_ascii(obj: str) -> str:
|
| 62 |
+
def mapping(obj: str) -> str:
|
| 63 |
+
if REGEX_NON_ASCII.search(obj):
|
| 64 |
+
return "xn--" + encode(obj)
|
| 65 |
+
return obj
|
| 66 |
+
|
| 67 |
+
return map_domain(obj, mapping)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/cli/__init__.py
ADDED
|
File without changes
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/cli/parse.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""
|
| 3 |
+
CLI interface to markdown-it-py
|
| 4 |
+
|
| 5 |
+
Parse one or more markdown files, convert each to HTML, and print to stdout.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import argparse
|
| 11 |
+
from collections.abc import Iterable, Sequence
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
from markdown_it import __version__
|
| 15 |
+
from markdown_it.main import MarkdownIt
|
| 16 |
+
|
| 17 |
+
version_str = f"markdown-it-py [version {__version__}]"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main(args: Sequence[str] | None = None) -> int:
|
| 21 |
+
namespace = parse_args(args)
|
| 22 |
+
if namespace.filenames:
|
| 23 |
+
convert(namespace.filenames)
|
| 24 |
+
else:
|
| 25 |
+
interactive()
|
| 26 |
+
return 0
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def convert(filenames: Iterable[str]) -> None:
|
| 30 |
+
for filename in filenames:
|
| 31 |
+
convert_file(filename)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def convert_file(filename: str) -> None:
|
| 35 |
+
"""
|
| 36 |
+
Parse a Markdown file and dump the output to stdout.
|
| 37 |
+
"""
|
| 38 |
+
try:
|
| 39 |
+
with open(filename, encoding="utf8", errors="ignore") as fin:
|
| 40 |
+
rendered = MarkdownIt().render(fin.read())
|
| 41 |
+
print(rendered, end="")
|
| 42 |
+
except OSError:
|
| 43 |
+
sys.stderr.write(f'Cannot open file "{filename}".\n')
|
| 44 |
+
sys.exit(1)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def interactive() -> None:
|
| 48 |
+
"""
|
| 49 |
+
Parse user input, dump to stdout, rinse and repeat.
|
| 50 |
+
Python REPL style.
|
| 51 |
+
"""
|
| 52 |
+
print_heading()
|
| 53 |
+
contents = []
|
| 54 |
+
more = False
|
| 55 |
+
while True:
|
| 56 |
+
try:
|
| 57 |
+
prompt, more = ("... ", True) if more else (">>> ", True)
|
| 58 |
+
contents.append(input(prompt) + "\n")
|
| 59 |
+
except EOFError:
|
| 60 |
+
print("\n" + MarkdownIt().render("\n".join(contents)), end="")
|
| 61 |
+
more = False
|
| 62 |
+
contents = []
|
| 63 |
+
except KeyboardInterrupt:
|
| 64 |
+
print("\nExiting.")
|
| 65 |
+
break
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def parse_args(args: Sequence[str] | None) -> argparse.Namespace:
|
| 69 |
+
"""Parse input CLI arguments."""
|
| 70 |
+
parser = argparse.ArgumentParser(
|
| 71 |
+
description="Parse one or more markdown files, "
|
| 72 |
+
"convert each to HTML, and print to stdout",
|
| 73 |
+
# NOTE: Remember to update README.md w/ the output of `markdown-it -h`
|
| 74 |
+
epilog=(
|
| 75 |
+
f"""
|
| 76 |
+
Interactive:
|
| 77 |
+
|
| 78 |
+
$ markdown-it
|
| 79 |
+
markdown-it-py [version {__version__}] (interactive)
|
| 80 |
+
Type Ctrl-D to complete input, or Ctrl-C to exit.
|
| 81 |
+
>>> # Example
|
| 82 |
+
... > markdown *input*
|
| 83 |
+
...
|
| 84 |
+
<h1>Example</h1>
|
| 85 |
+
<blockquote>
|
| 86 |
+
<p>markdown <em>input</em></p>
|
| 87 |
+
</blockquote>
|
| 88 |
+
|
| 89 |
+
Batch:
|
| 90 |
+
|
| 91 |
+
$ markdown-it README.md README.footer.md > index.html
|
| 92 |
+
"""
|
| 93 |
+
),
|
| 94 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 95 |
+
)
|
| 96 |
+
parser.add_argument("-v", "--version", action="version", version=version_str)
|
| 97 |
+
parser.add_argument(
|
| 98 |
+
"filenames", nargs="*", help="specify an optional list of files to convert"
|
| 99 |
+
)
|
| 100 |
+
return parser.parse_args(args)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def print_heading() -> None:
|
| 104 |
+
print(f"{version_str} (interactive)")
|
| 105 |
+
print("Type Ctrl-D to complete input, or Ctrl-C to exit.")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
exit_code = main(sys.argv[1:])
|
| 110 |
+
sys.exit(exit_code)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/__init__.py
ADDED
|
File without changes
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/entities.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""HTML5 entities map: { name -> characters }."""
|
| 2 |
+
|
| 3 |
+
import html.entities
|
| 4 |
+
|
| 5 |
+
entities = {name.rstrip(";"): chars for name, chars in html.entities.html5.items()}
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/html_blocks.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""List of valid html blocks names, according to commonmark spec
|
| 2 |
+
http://jgm.github.io/CommonMark/spec.html#html-blocks
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
# see https://spec.commonmark.org/0.31.2/#html-blocks
|
| 6 |
+
block_names = [
|
| 7 |
+
"address",
|
| 8 |
+
"article",
|
| 9 |
+
"aside",
|
| 10 |
+
"base",
|
| 11 |
+
"basefont",
|
| 12 |
+
"blockquote",
|
| 13 |
+
"body",
|
| 14 |
+
"caption",
|
| 15 |
+
"center",
|
| 16 |
+
"col",
|
| 17 |
+
"colgroup",
|
| 18 |
+
"dd",
|
| 19 |
+
"details",
|
| 20 |
+
"dialog",
|
| 21 |
+
"dir",
|
| 22 |
+
"div",
|
| 23 |
+
"dl",
|
| 24 |
+
"dt",
|
| 25 |
+
"fieldset",
|
| 26 |
+
"figcaption",
|
| 27 |
+
"figure",
|
| 28 |
+
"footer",
|
| 29 |
+
"form",
|
| 30 |
+
"frame",
|
| 31 |
+
"frameset",
|
| 32 |
+
"h1",
|
| 33 |
+
"h2",
|
| 34 |
+
"h3",
|
| 35 |
+
"h4",
|
| 36 |
+
"h5",
|
| 37 |
+
"h6",
|
| 38 |
+
"head",
|
| 39 |
+
"header",
|
| 40 |
+
"hr",
|
| 41 |
+
"html",
|
| 42 |
+
"iframe",
|
| 43 |
+
"legend",
|
| 44 |
+
"li",
|
| 45 |
+
"link",
|
| 46 |
+
"main",
|
| 47 |
+
"menu",
|
| 48 |
+
"menuitem",
|
| 49 |
+
"nav",
|
| 50 |
+
"noframes",
|
| 51 |
+
"ol",
|
| 52 |
+
"optgroup",
|
| 53 |
+
"option",
|
| 54 |
+
"p",
|
| 55 |
+
"param",
|
| 56 |
+
"search",
|
| 57 |
+
"section",
|
| 58 |
+
"summary",
|
| 59 |
+
"table",
|
| 60 |
+
"tbody",
|
| 61 |
+
"td",
|
| 62 |
+
"tfoot",
|
| 63 |
+
"th",
|
| 64 |
+
"thead",
|
| 65 |
+
"title",
|
| 66 |
+
"tr",
|
| 67 |
+
"track",
|
| 68 |
+
"ul",
|
| 69 |
+
]
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/html_re.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Regexps to match html elements"""
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
attr_name = "[a-zA-Z_:][a-zA-Z0-9:._-]*"
|
| 6 |
+
|
| 7 |
+
unquoted = "[^\"'=<>`\\x00-\\x20]+"
|
| 8 |
+
single_quoted = "'[^']*'"
|
| 9 |
+
double_quoted = '"[^"]*"'
|
| 10 |
+
|
| 11 |
+
attr_value = "(?:" + unquoted + "|" + single_quoted + "|" + double_quoted + ")"
|
| 12 |
+
|
| 13 |
+
attribute = "(?:\\s+" + attr_name + "(?:\\s*=\\s*" + attr_value + ")?)"
|
| 14 |
+
|
| 15 |
+
open_tag = "<[A-Za-z][A-Za-z0-9\\-]*" + attribute + "*\\s*\\/?>"
|
| 16 |
+
|
| 17 |
+
close_tag = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>"
|
| 18 |
+
comment = "<!---?>|<!--(?:[^-]|-[^-]|--[^>])*-->"
|
| 19 |
+
processing = "<[?][\\s\\S]*?[?]>"
|
| 20 |
+
declaration = "<![A-Za-z][^>]*>"
|
| 21 |
+
cdata = "<!\\[CDATA\\[[\\s\\S]*?\\]\\]>"
|
| 22 |
+
|
| 23 |
+
HTML_TAG_RE = re.compile(
|
| 24 |
+
"^(?:"
|
| 25 |
+
+ open_tag
|
| 26 |
+
+ "|"
|
| 27 |
+
+ close_tag
|
| 28 |
+
+ "|"
|
| 29 |
+
+ comment
|
| 30 |
+
+ "|"
|
| 31 |
+
+ processing
|
| 32 |
+
+ "|"
|
| 33 |
+
+ declaration
|
| 34 |
+
+ "|"
|
| 35 |
+
+ cdata
|
| 36 |
+
+ ")"
|
| 37 |
+
)
|
| 38 |
+
HTML_OPEN_CLOSE_TAG_STR = "^(?:" + open_tag + "|" + close_tag + ")"
|
| 39 |
+
HTML_OPEN_CLOSE_TAG_RE = re.compile(HTML_OPEN_CLOSE_TAG_STR)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/normalize_url.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from collections.abc import Callable
|
| 4 |
+
from contextlib import suppress
|
| 5 |
+
import re
|
| 6 |
+
from urllib.parse import quote, unquote, urlparse, urlunparse # noqa: F401
|
| 7 |
+
|
| 8 |
+
import mdurl
|
| 9 |
+
|
| 10 |
+
from .. import _punycode
|
| 11 |
+
|
| 12 |
+
RECODE_HOSTNAME_FOR = ("http:", "https:", "mailto:")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def normalizeLink(url: str) -> str:
|
| 16 |
+
"""Normalize destination URLs in links
|
| 17 |
+
|
| 18 |
+
::
|
| 19 |
+
|
| 20 |
+
[label]: destination 'title'
|
| 21 |
+
^^^^^^^^^^^
|
| 22 |
+
"""
|
| 23 |
+
parsed = mdurl.parse(url, slashes_denote_host=True)
|
| 24 |
+
|
| 25 |
+
# Encode hostnames in urls like:
|
| 26 |
+
# `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
|
| 27 |
+
#
|
| 28 |
+
# We don't encode unknown schemas, because it's likely that we encode
|
| 29 |
+
# something we shouldn't (e.g. `skype:name` treated as `skype:host`)
|
| 30 |
+
#
|
| 31 |
+
if parsed.hostname and (
|
| 32 |
+
not parsed.protocol or parsed.protocol in RECODE_HOSTNAME_FOR
|
| 33 |
+
):
|
| 34 |
+
with suppress(Exception):
|
| 35 |
+
parsed = parsed._replace(hostname=_punycode.to_ascii(parsed.hostname))
|
| 36 |
+
|
| 37 |
+
return mdurl.encode(mdurl.format(parsed))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def normalizeLinkText(url: str) -> str:
|
| 41 |
+
"""Normalize autolink content
|
| 42 |
+
|
| 43 |
+
::
|
| 44 |
+
|
| 45 |
+
<destination>
|
| 46 |
+
~~~~~~~~~~~
|
| 47 |
+
"""
|
| 48 |
+
parsed = mdurl.parse(url, slashes_denote_host=True)
|
| 49 |
+
|
| 50 |
+
# Encode hostnames in urls like:
|
| 51 |
+
# `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
|
| 52 |
+
#
|
| 53 |
+
# We don't encode unknown schemas, because it's likely that we encode
|
| 54 |
+
# something we shouldn't (e.g. `skype:name` treated as `skype:host`)
|
| 55 |
+
#
|
| 56 |
+
if parsed.hostname and (
|
| 57 |
+
not parsed.protocol or parsed.protocol in RECODE_HOSTNAME_FOR
|
| 58 |
+
):
|
| 59 |
+
with suppress(Exception):
|
| 60 |
+
parsed = parsed._replace(hostname=_punycode.to_unicode(parsed.hostname))
|
| 61 |
+
|
| 62 |
+
# add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720
|
| 63 |
+
return mdurl.decode(mdurl.format(parsed), mdurl.DECODE_DEFAULT_CHARS + "%")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
BAD_PROTO_RE = re.compile(r"^(vbscript|javascript|file|data):")
|
| 67 |
+
GOOD_DATA_RE = re.compile(r"^data:image\/(gif|png|jpeg|webp);")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def validateLink(url: str, validator: Callable[[str], bool] | None = None) -> bool:
|
| 71 |
+
"""Validate URL link is allowed in output.
|
| 72 |
+
|
| 73 |
+
This validator can prohibit more than really needed to prevent XSS.
|
| 74 |
+
It's a tradeoff to keep code simple and to be secure by default.
|
| 75 |
+
|
| 76 |
+
Note: url should be normalized at this point, and existing entities decoded.
|
| 77 |
+
"""
|
| 78 |
+
if validator is not None:
|
| 79 |
+
return validator(url)
|
| 80 |
+
url = url.strip().lower()
|
| 81 |
+
return bool(GOOD_DATA_RE.search(url)) if BAD_PROTO_RE.search(url) else True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/common/utils.py
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utilities for parsing source text"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
from re import Match
|
| 7 |
+
from typing import TypeVar
|
| 8 |
+
import unicodedata
|
| 9 |
+
|
| 10 |
+
from .entities import entities
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def charCodeAt(src: str, pos: int) -> int | None:
|
| 14 |
+
"""
|
| 15 |
+
Returns the Unicode value of the character at the specified location.
|
| 16 |
+
|
| 17 |
+
@param - index The zero-based index of the desired character.
|
| 18 |
+
If there is no character at the specified index, NaN is returned.
|
| 19 |
+
|
| 20 |
+
This was added for compatibility with python
|
| 21 |
+
"""
|
| 22 |
+
try:
|
| 23 |
+
return ord(src[pos])
|
| 24 |
+
except IndexError:
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def charStrAt(src: str, pos: int) -> str | None:
|
| 29 |
+
"""
|
| 30 |
+
Returns the Unicode value of the character at the specified location.
|
| 31 |
+
|
| 32 |
+
@param - index The zero-based index of the desired character.
|
| 33 |
+
If there is no character at the specified index, NaN is returned.
|
| 34 |
+
|
| 35 |
+
This was added for compatibility with python
|
| 36 |
+
"""
|
| 37 |
+
try:
|
| 38 |
+
return src[pos]
|
| 39 |
+
except IndexError:
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
_ItemTV = TypeVar("_ItemTV")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def arrayReplaceAt(
|
| 47 |
+
src: list[_ItemTV], pos: int, newElements: list[_ItemTV]
|
| 48 |
+
) -> list[_ItemTV]:
|
| 49 |
+
"""
|
| 50 |
+
Remove element from array and put another array at those position.
|
| 51 |
+
Useful for some operations with tokens
|
| 52 |
+
"""
|
| 53 |
+
return src[:pos] + newElements + src[pos + 1 :]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def isValidEntityCode(c: int) -> bool:
|
| 57 |
+
# broken sequence
|
| 58 |
+
if c >= 0xD800 and c <= 0xDFFF:
|
| 59 |
+
return False
|
| 60 |
+
# never used
|
| 61 |
+
if c >= 0xFDD0 and c <= 0xFDEF:
|
| 62 |
+
return False
|
| 63 |
+
if ((c & 0xFFFF) == 0xFFFF) or ((c & 0xFFFF) == 0xFFFE):
|
| 64 |
+
return False
|
| 65 |
+
# control codes
|
| 66 |
+
if c >= 0x00 and c <= 0x08:
|
| 67 |
+
return False
|
| 68 |
+
if c == 0x0B:
|
| 69 |
+
return False
|
| 70 |
+
if c >= 0x0E and c <= 0x1F:
|
| 71 |
+
return False
|
| 72 |
+
if c >= 0x7F and c <= 0x9F:
|
| 73 |
+
return False
|
| 74 |
+
# out of range
|
| 75 |
+
return not (c > 0x10FFFF)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def fromCodePoint(c: int) -> str:
|
| 79 |
+
"""Convert ordinal to unicode.
|
| 80 |
+
|
| 81 |
+
Note, in the original Javascript two string characters were required,
|
| 82 |
+
for codepoints larger than `0xFFFF`.
|
| 83 |
+
But Python 3 can represent any unicode codepoint in one character.
|
| 84 |
+
"""
|
| 85 |
+
return chr(c)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# UNESCAPE_MD_RE = re.compile(r'\\([!"#$%&\'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])')
|
| 89 |
+
# ENTITY_RE_g = re.compile(r'&([a-z#][a-z0-9]{1,31})', re.IGNORECASE)
|
| 90 |
+
UNESCAPE_ALL_RE = re.compile(
|
| 91 |
+
r'\\([!"#$%&\'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])' + "|" + r"&([a-z#][a-z0-9]{1,31});",
|
| 92 |
+
re.IGNORECASE,
|
| 93 |
+
)
|
| 94 |
+
DIGITAL_ENTITY_BASE10_RE = re.compile(r"#([0-9]{1,8})")
|
| 95 |
+
DIGITAL_ENTITY_BASE16_RE = re.compile(r"#x([a-f0-9]{1,8})", re.IGNORECASE)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def replaceEntityPattern(match: str, name: str) -> str:
|
| 99 |
+
"""Convert HTML entity patterns,
|
| 100 |
+
see https://spec.commonmark.org/0.30/#entity-references
|
| 101 |
+
"""
|
| 102 |
+
if name in entities:
|
| 103 |
+
return entities[name]
|
| 104 |
+
|
| 105 |
+
code: None | int = None
|
| 106 |
+
if pat := DIGITAL_ENTITY_BASE10_RE.fullmatch(name):
|
| 107 |
+
code = int(pat.group(1), 10)
|
| 108 |
+
elif pat := DIGITAL_ENTITY_BASE16_RE.fullmatch(name):
|
| 109 |
+
code = int(pat.group(1), 16)
|
| 110 |
+
|
| 111 |
+
if code is not None and isValidEntityCode(code):
|
| 112 |
+
return fromCodePoint(code)
|
| 113 |
+
|
| 114 |
+
return match
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def unescapeAll(string: str) -> str:
|
| 118 |
+
def replacer_func(match: Match[str]) -> str:
|
| 119 |
+
escaped = match.group(1)
|
| 120 |
+
if escaped:
|
| 121 |
+
return escaped
|
| 122 |
+
entity = match.group(2)
|
| 123 |
+
return replaceEntityPattern(match.group(), entity)
|
| 124 |
+
|
| 125 |
+
if "\\" not in string and "&" not in string:
|
| 126 |
+
return string
|
| 127 |
+
return UNESCAPE_ALL_RE.sub(replacer_func, string)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
ESCAPABLE = r"""\\!"#$%&'()*+,./:;<=>?@\[\]^`{}|_~-"""
|
| 131 |
+
ESCAPE_CHAR = re.compile(r"\\([" + ESCAPABLE + r"])")
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def stripEscape(string: str) -> str:
|
| 135 |
+
"""Strip escape \\ characters"""
|
| 136 |
+
return ESCAPE_CHAR.sub(r"\1", string)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def escapeHtml(raw: str) -> str:
|
| 140 |
+
"""Replace special characters "&", "<", ">" and '"' to HTML-safe sequences."""
|
| 141 |
+
# like html.escape, but without escaping single quotes
|
| 142 |
+
raw = raw.replace("&", "&") # Must be done first!
|
| 143 |
+
raw = raw.replace("<", "<")
|
| 144 |
+
raw = raw.replace(">", ">")
|
| 145 |
+
raw = raw.replace('"', """)
|
| 146 |
+
return raw
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# //////////////////////////////////////////////////////////////////////////////
|
| 150 |
+
|
| 151 |
+
REGEXP_ESCAPE_RE = re.compile(r"[.?*+^$[\]\\(){}|-]")
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def escapeRE(string: str) -> str:
|
| 155 |
+
string = REGEXP_ESCAPE_RE.sub("\\$&", string)
|
| 156 |
+
return string
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
# //////////////////////////////////////////////////////////////////////////////
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def isSpace(code: int | None) -> bool:
|
| 163 |
+
"""Check if character code is a whitespace."""
|
| 164 |
+
return code in (0x09, 0x20)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def isStrSpace(ch: str | None) -> bool:
|
| 168 |
+
"""Check if character is a whitespace."""
|
| 169 |
+
return ch in ("\t", " ")
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
MD_WHITESPACE = {
|
| 173 |
+
0x09, # \t
|
| 174 |
+
0x0A, # \n
|
| 175 |
+
0x0B, # \v
|
| 176 |
+
0x0C, # \f
|
| 177 |
+
0x0D, # \r
|
| 178 |
+
0x20, # space
|
| 179 |
+
0xA0,
|
| 180 |
+
0x1680,
|
| 181 |
+
0x202F,
|
| 182 |
+
0x205F,
|
| 183 |
+
0x3000,
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def isWhiteSpace(code: int) -> bool:
|
| 188 |
+
r"""Zs (unicode class) || [\t\f\v\r\n]"""
|
| 189 |
+
if code >= 0x2000 and code <= 0x200A:
|
| 190 |
+
return True
|
| 191 |
+
return code in MD_WHITESPACE
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
# //////////////////////////////////////////////////////////////////////////////
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def isPunctChar(ch: str) -> bool:
|
| 198 |
+
"""Check if character is a punctuation character."""
|
| 199 |
+
return unicodedata.category(ch).startswith(("P", "S"))
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
MD_ASCII_PUNCT = {
|
| 203 |
+
0x21, # /* ! */
|
| 204 |
+
0x22, # /* " */
|
| 205 |
+
0x23, # /* # */
|
| 206 |
+
0x24, # /* $ */
|
| 207 |
+
0x25, # /* % */
|
| 208 |
+
0x26, # /* & */
|
| 209 |
+
0x27, # /* ' */
|
| 210 |
+
0x28, # /* ( */
|
| 211 |
+
0x29, # /* ) */
|
| 212 |
+
0x2A, # /* * */
|
| 213 |
+
0x2B, # /* + */
|
| 214 |
+
0x2C, # /* , */
|
| 215 |
+
0x2D, # /* - */
|
| 216 |
+
0x2E, # /* . */
|
| 217 |
+
0x2F, # /* / */
|
| 218 |
+
0x3A, # /* : */
|
| 219 |
+
0x3B, # /* ; */
|
| 220 |
+
0x3C, # /* < */
|
| 221 |
+
0x3D, # /* = */
|
| 222 |
+
0x3E, # /* > */
|
| 223 |
+
0x3F, # /* ? */
|
| 224 |
+
0x40, # /* @ */
|
| 225 |
+
0x5B, # /* [ */
|
| 226 |
+
0x5C, # /* \ */
|
| 227 |
+
0x5D, # /* ] */
|
| 228 |
+
0x5E, # /* ^ */
|
| 229 |
+
0x5F, # /* _ */
|
| 230 |
+
0x60, # /* ` */
|
| 231 |
+
0x7B, # /* { */
|
| 232 |
+
0x7C, # /* | */
|
| 233 |
+
0x7D, # /* } */
|
| 234 |
+
0x7E, # /* ~ */
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def isMdAsciiPunct(ch: int) -> bool:
|
| 239 |
+
"""Markdown ASCII punctuation characters.
|
| 240 |
+
|
| 241 |
+
::
|
| 242 |
+
|
| 243 |
+
!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \\, ], ^, _, `, {, |, }, or ~
|
| 244 |
+
|
| 245 |
+
See http://spec.commonmark.org/0.15/#ascii-punctuation-character
|
| 246 |
+
|
| 247 |
+
Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
|
| 248 |
+
|
| 249 |
+
"""
|
| 250 |
+
return ch in MD_ASCII_PUNCT
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def normalizeReference(string: str) -> str:
|
| 254 |
+
"""Helper to unify [reference labels]."""
|
| 255 |
+
# Trim and collapse whitespace
|
| 256 |
+
#
|
| 257 |
+
string = re.sub(r"\s+", " ", string.strip())
|
| 258 |
+
|
| 259 |
+
# In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug
|
| 260 |
+
# fixed in v12 (couldn't find any details).
|
| 261 |
+
#
|
| 262 |
+
# So treat this one as a special case
|
| 263 |
+
# (remove this when node v10 is no longer supported).
|
| 264 |
+
#
|
| 265 |
+
# if ('ẞ'.toLowerCase() === 'Ṿ') {
|
| 266 |
+
# str = str.replace(/ẞ/g, 'ß')
|
| 267 |
+
# }
|
| 268 |
+
|
| 269 |
+
# .toLowerCase().toUpperCase() should get rid of all differences
|
| 270 |
+
# between letter variants.
|
| 271 |
+
#
|
| 272 |
+
# Simple .toLowerCase() doesn't normalize 125 code points correctly,
|
| 273 |
+
# and .toUpperCase doesn't normalize 6 of them (list of exceptions:
|
| 274 |
+
# İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently
|
| 275 |
+
# uppercased versions).
|
| 276 |
+
#
|
| 277 |
+
# Here's an example showing how it happens. Lets take greek letter omega:
|
| 278 |
+
# uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ)
|
| 279 |
+
#
|
| 280 |
+
# Unicode entries:
|
| 281 |
+
# 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8
|
| 282 |
+
# 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398
|
| 283 |
+
# 03D1;GREEK THETA SYMBOL;Ll;0;L;<compat> 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398
|
| 284 |
+
# 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L;<compat> 0398;;;;N;;;;03B8
|
| 285 |
+
#
|
| 286 |
+
# Case-insensitive comparison should treat all of them as equivalent.
|
| 287 |
+
#
|
| 288 |
+
# But .toLowerCase() doesn't change ϑ (it's already lowercase),
|
| 289 |
+
# and .toUpperCase() doesn't change ϴ (already uppercase).
|
| 290 |
+
#
|
| 291 |
+
# Applying first lower then upper case normalizes any character:
|
| 292 |
+
# '\u0398\u03f4\u03b8\u03d1'.toLowerCase().toUpperCase() === '\u0398\u0398\u0398\u0398'
|
| 293 |
+
#
|
| 294 |
+
# Note: this is equivalent to unicode case folding; unicode normalization
|
| 295 |
+
# is a different step that is not required here.
|
| 296 |
+
#
|
| 297 |
+
# Final result should be uppercased, because it's later stored in an object
|
| 298 |
+
# (this avoid a conflict with Object.prototype members,
|
| 299 |
+
# most notably, `__proto__`)
|
| 300 |
+
#
|
| 301 |
+
return string.lower().upper()
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
LINK_OPEN_RE = re.compile(r"^<a[>\s]", flags=re.IGNORECASE)
|
| 305 |
+
LINK_CLOSE_RE = re.compile(r"^</a\s*>", flags=re.IGNORECASE)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def isLinkOpen(string: str) -> bool:
|
| 309 |
+
return bool(LINK_OPEN_RE.search(string))
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def isLinkClose(string: str) -> bool:
|
| 313 |
+
return bool(LINK_CLOSE_RE.search(string))
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions for parsing Links"""
|
| 2 |
+
|
| 3 |
+
__all__ = ("parseLinkDestination", "parseLinkLabel", "parseLinkTitle")
|
| 4 |
+
from .parse_link_destination import parseLinkDestination
|
| 5 |
+
from .parse_link_label import parseLinkLabel
|
| 6 |
+
from .parse_link_title import parseLinkTitle
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/parse_link_destination.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Parse link destination
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from ..common.utils import charCodeAt, unescapeAll
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class _Result:
|
| 9 |
+
__slots__ = ("ok", "pos", "str")
|
| 10 |
+
|
| 11 |
+
def __init__(self) -> None:
|
| 12 |
+
self.ok = False
|
| 13 |
+
self.pos = 0
|
| 14 |
+
self.str = ""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result:
|
| 18 |
+
start = pos
|
| 19 |
+
result = _Result()
|
| 20 |
+
|
| 21 |
+
if charCodeAt(string, pos) == 0x3C: # /* < */
|
| 22 |
+
pos += 1
|
| 23 |
+
while pos < maximum:
|
| 24 |
+
code = charCodeAt(string, pos)
|
| 25 |
+
if code == 0x0A: # /* \n */)
|
| 26 |
+
return result
|
| 27 |
+
if code == 0x3C: # / * < * /
|
| 28 |
+
return result
|
| 29 |
+
if code == 0x3E: # /* > */) {
|
| 30 |
+
result.pos = pos + 1
|
| 31 |
+
result.str = unescapeAll(string[start + 1 : pos])
|
| 32 |
+
result.ok = True
|
| 33 |
+
return result
|
| 34 |
+
|
| 35 |
+
if code == 0x5C and pos + 1 < maximum: # \
|
| 36 |
+
pos += 2
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
pos += 1
|
| 40 |
+
|
| 41 |
+
# no closing '>'
|
| 42 |
+
return result
|
| 43 |
+
|
| 44 |
+
# this should be ... } else { ... branch
|
| 45 |
+
|
| 46 |
+
level = 0
|
| 47 |
+
while pos < maximum:
|
| 48 |
+
code = charCodeAt(string, pos)
|
| 49 |
+
|
| 50 |
+
if code is None or code == 0x20:
|
| 51 |
+
break
|
| 52 |
+
|
| 53 |
+
# ascii control characters
|
| 54 |
+
if code < 0x20 or code == 0x7F:
|
| 55 |
+
break
|
| 56 |
+
|
| 57 |
+
if code == 0x5C and pos + 1 < maximum:
|
| 58 |
+
if charCodeAt(string, pos + 1) == 0x20:
|
| 59 |
+
break
|
| 60 |
+
pos += 2
|
| 61 |
+
continue
|
| 62 |
+
|
| 63 |
+
if code == 0x28: # /* ( */)
|
| 64 |
+
level += 1
|
| 65 |
+
if level > 32:
|
| 66 |
+
return result
|
| 67 |
+
|
| 68 |
+
if code == 0x29: # /* ) */)
|
| 69 |
+
if level == 0:
|
| 70 |
+
break
|
| 71 |
+
level -= 1
|
| 72 |
+
|
| 73 |
+
pos += 1
|
| 74 |
+
|
| 75 |
+
if start == pos:
|
| 76 |
+
return result
|
| 77 |
+
if level != 0:
|
| 78 |
+
return result
|
| 79 |
+
|
| 80 |
+
result.str = unescapeAll(string[start:pos])
|
| 81 |
+
result.pos = pos
|
| 82 |
+
result.ok = True
|
| 83 |
+
return result
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/parse_link_label.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Parse link label
|
| 3 |
+
|
| 4 |
+
this function assumes that first character ("[") already matches
|
| 5 |
+
returns the end of the label
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from markdown_it.rules_inline import StateInline
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def parseLinkLabel(state: StateInline, start: int, disableNested: bool = False) -> int:
|
| 13 |
+
labelEnd = -1
|
| 14 |
+
oldPos = state.pos
|
| 15 |
+
found = False
|
| 16 |
+
|
| 17 |
+
state.pos = start + 1
|
| 18 |
+
level = 1
|
| 19 |
+
|
| 20 |
+
while state.pos < state.posMax:
|
| 21 |
+
marker = state.src[state.pos]
|
| 22 |
+
if marker == "]":
|
| 23 |
+
level -= 1
|
| 24 |
+
if level == 0:
|
| 25 |
+
found = True
|
| 26 |
+
break
|
| 27 |
+
|
| 28 |
+
prevPos = state.pos
|
| 29 |
+
state.md.inline.skipToken(state)
|
| 30 |
+
if marker == "[":
|
| 31 |
+
if prevPos == state.pos - 1:
|
| 32 |
+
# increase level if we find text `[`,
|
| 33 |
+
# which is not a part of any token
|
| 34 |
+
level += 1
|
| 35 |
+
elif disableNested:
|
| 36 |
+
state.pos = oldPos
|
| 37 |
+
return -1
|
| 38 |
+
if found:
|
| 39 |
+
labelEnd = state.pos
|
| 40 |
+
|
| 41 |
+
# restore old state
|
| 42 |
+
state.pos = oldPos
|
| 43 |
+
|
| 44 |
+
return labelEnd
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/helpers/parse_link_title.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parse link title"""
|
| 2 |
+
|
| 3 |
+
from ..common.utils import charCodeAt, unescapeAll
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class _State:
|
| 7 |
+
__slots__ = ("can_continue", "marker", "ok", "pos", "str")
|
| 8 |
+
|
| 9 |
+
def __init__(self) -> None:
|
| 10 |
+
self.ok = False
|
| 11 |
+
"""if `true`, this is a valid link title"""
|
| 12 |
+
self.can_continue = False
|
| 13 |
+
"""if `true`, this link can be continued on the next line"""
|
| 14 |
+
self.pos = 0
|
| 15 |
+
"""if `ok`, it's the position of the first character after the closing marker"""
|
| 16 |
+
self.str = ""
|
| 17 |
+
"""if `ok`, it's the unescaped title"""
|
| 18 |
+
self.marker = 0
|
| 19 |
+
"""expected closing marker character code"""
|
| 20 |
+
|
| 21 |
+
def __str__(self) -> str:
|
| 22 |
+
return self.str
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def parseLinkTitle(
|
| 26 |
+
string: str, start: int, maximum: int, prev_state: _State | None = None
|
| 27 |
+
) -> _State:
|
| 28 |
+
"""Parse link title within `str` in [start, max] range,
|
| 29 |
+
or continue previous parsing if `prev_state` is defined (equal to result of last execution).
|
| 30 |
+
"""
|
| 31 |
+
pos = start
|
| 32 |
+
state = _State()
|
| 33 |
+
|
| 34 |
+
if prev_state is not None:
|
| 35 |
+
# this is a continuation of a previous parseLinkTitle call on the next line,
|
| 36 |
+
# used in reference links only
|
| 37 |
+
state.str = prev_state.str
|
| 38 |
+
state.marker = prev_state.marker
|
| 39 |
+
else:
|
| 40 |
+
if pos >= maximum:
|
| 41 |
+
return state
|
| 42 |
+
|
| 43 |
+
marker = charCodeAt(string, pos)
|
| 44 |
+
|
| 45 |
+
# /* " */ /* ' */ /* ( */
|
| 46 |
+
if marker != 0x22 and marker != 0x27 and marker != 0x28:
|
| 47 |
+
return state
|
| 48 |
+
|
| 49 |
+
start += 1
|
| 50 |
+
pos += 1
|
| 51 |
+
|
| 52 |
+
# if opening marker is "(", switch it to closing marker ")"
|
| 53 |
+
if marker == 0x28:
|
| 54 |
+
marker = 0x29
|
| 55 |
+
|
| 56 |
+
state.marker = marker
|
| 57 |
+
|
| 58 |
+
while pos < maximum:
|
| 59 |
+
code = charCodeAt(string, pos)
|
| 60 |
+
if code == state.marker:
|
| 61 |
+
state.pos = pos + 1
|
| 62 |
+
state.str += unescapeAll(string[start:pos])
|
| 63 |
+
state.ok = True
|
| 64 |
+
return state
|
| 65 |
+
elif code == 0x28 and state.marker == 0x29: # /* ( */ /* ) */
|
| 66 |
+
return state
|
| 67 |
+
elif code == 0x5C and pos + 1 < maximum: # /* \ */
|
| 68 |
+
pos += 1
|
| 69 |
+
|
| 70 |
+
pos += 1
|
| 71 |
+
|
| 72 |
+
# no closing marker found, but this link title may continue on the next line (for references)
|
| 73 |
+
state.can_continue = True
|
| 74 |
+
state.str += unescapeAll(string[start:pos])
|
| 75 |
+
return state
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/main.py
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from collections.abc import Callable, Generator, Iterable, Mapping, MutableMapping
|
| 4 |
+
from contextlib import contextmanager
|
| 5 |
+
from typing import Any, Literal, overload
|
| 6 |
+
|
| 7 |
+
from . import helpers, presets
|
| 8 |
+
from .common import normalize_url, utils
|
| 9 |
+
from .parser_block import ParserBlock
|
| 10 |
+
from .parser_core import ParserCore
|
| 11 |
+
from .parser_inline import ParserInline
|
| 12 |
+
from .renderer import RendererHTML, RendererProtocol
|
| 13 |
+
from .rules_core.state_core import StateCore
|
| 14 |
+
from .token import Token
|
| 15 |
+
from .utils import EnvType, OptionsDict, OptionsType, PresetType
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
import linkify_it
|
| 19 |
+
except ModuleNotFoundError:
|
| 20 |
+
linkify_it = None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_PRESETS: dict[str, PresetType] = {
|
| 24 |
+
"default": presets.default.make(),
|
| 25 |
+
"js-default": presets.js_default.make(),
|
| 26 |
+
"zero": presets.zero.make(),
|
| 27 |
+
"commonmark": presets.commonmark.make(),
|
| 28 |
+
"gfm-like": presets.gfm_like.make(),
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class MarkdownIt:
|
| 33 |
+
def __init__(
|
| 34 |
+
self,
|
| 35 |
+
config: str | PresetType = "commonmark",
|
| 36 |
+
options_update: Mapping[str, Any] | None = None,
|
| 37 |
+
*,
|
| 38 |
+
renderer_cls: Callable[[MarkdownIt], RendererProtocol] = RendererHTML,
|
| 39 |
+
):
|
| 40 |
+
"""Main parser class
|
| 41 |
+
|
| 42 |
+
:param config: name of configuration to load or a pre-defined dictionary
|
| 43 |
+
:param options_update: dictionary that will be merged into ``config["options"]``
|
| 44 |
+
:param renderer_cls: the class to load as the renderer:
|
| 45 |
+
``self.renderer = renderer_cls(self)
|
| 46 |
+
"""
|
| 47 |
+
# add modules
|
| 48 |
+
self.utils = utils
|
| 49 |
+
self.helpers = helpers
|
| 50 |
+
|
| 51 |
+
# initialise classes
|
| 52 |
+
self.inline = ParserInline()
|
| 53 |
+
self.block = ParserBlock()
|
| 54 |
+
self.core = ParserCore()
|
| 55 |
+
self.renderer = renderer_cls(self)
|
| 56 |
+
self.linkify = linkify_it.LinkifyIt() if linkify_it else None
|
| 57 |
+
|
| 58 |
+
# set the configuration
|
| 59 |
+
if options_update and not isinstance(options_update, Mapping):
|
| 60 |
+
# catch signature change where renderer_cls was not used as a key-word
|
| 61 |
+
raise TypeError(
|
| 62 |
+
f"options_update should be a mapping: {options_update}"
|
| 63 |
+
"\n(Perhaps you intended this to be the renderer_cls?)"
|
| 64 |
+
)
|
| 65 |
+
self.configure(config, options_update=options_update)
|
| 66 |
+
|
| 67 |
+
def __repr__(self) -> str:
|
| 68 |
+
return f"{self.__class__.__module__}.{self.__class__.__name__}()"
|
| 69 |
+
|
| 70 |
+
@overload
|
| 71 |
+
def __getitem__(self, name: Literal["inline"]) -> ParserInline: ...
|
| 72 |
+
|
| 73 |
+
@overload
|
| 74 |
+
def __getitem__(self, name: Literal["block"]) -> ParserBlock: ...
|
| 75 |
+
|
| 76 |
+
@overload
|
| 77 |
+
def __getitem__(self, name: Literal["core"]) -> ParserCore: ...
|
| 78 |
+
|
| 79 |
+
@overload
|
| 80 |
+
def __getitem__(self, name: Literal["renderer"]) -> RendererProtocol: ...
|
| 81 |
+
|
| 82 |
+
@overload
|
| 83 |
+
def __getitem__(self, name: str) -> Any: ...
|
| 84 |
+
|
| 85 |
+
def __getitem__(self, name: str) -> Any:
|
| 86 |
+
return {
|
| 87 |
+
"inline": self.inline,
|
| 88 |
+
"block": self.block,
|
| 89 |
+
"core": self.core,
|
| 90 |
+
"renderer": self.renderer,
|
| 91 |
+
}[name]
|
| 92 |
+
|
| 93 |
+
def set(self, options: OptionsType) -> None:
|
| 94 |
+
"""Set parser options (in the same format as in constructor).
|
| 95 |
+
Probably, you will never need it, but you can change options after constructor call.
|
| 96 |
+
|
| 97 |
+
__Note:__ To achieve the best possible performance, don't modify a
|
| 98 |
+
`markdown-it` instance options on the fly. If you need multiple configurations
|
| 99 |
+
it's best to create multiple instances and initialize each with separate config.
|
| 100 |
+
"""
|
| 101 |
+
self.options = OptionsDict(options)
|
| 102 |
+
|
| 103 |
+
def configure(
|
| 104 |
+
self, presets: str | PresetType, options_update: Mapping[str, Any] | None = None
|
| 105 |
+
) -> MarkdownIt:
|
| 106 |
+
"""Batch load of all options and component settings.
|
| 107 |
+
This is an internal method, and you probably will not need it.
|
| 108 |
+
But if you will - see available presets and data structure
|
| 109 |
+
[here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)
|
| 110 |
+
|
| 111 |
+
We strongly recommend to use presets instead of direct config loads.
|
| 112 |
+
That will give better compatibility with next versions.
|
| 113 |
+
"""
|
| 114 |
+
if isinstance(presets, str):
|
| 115 |
+
if presets not in _PRESETS:
|
| 116 |
+
raise KeyError(f"Wrong `markdown-it` preset '{presets}', check name")
|
| 117 |
+
config = _PRESETS[presets]
|
| 118 |
+
else:
|
| 119 |
+
config = presets
|
| 120 |
+
|
| 121 |
+
if not config:
|
| 122 |
+
raise ValueError("Wrong `markdown-it` config, can't be empty")
|
| 123 |
+
|
| 124 |
+
options = config.get("options", {}) or {}
|
| 125 |
+
if options_update:
|
| 126 |
+
options = {**options, **options_update} # type: ignore
|
| 127 |
+
|
| 128 |
+
self.set(options) # type: ignore
|
| 129 |
+
|
| 130 |
+
if "components" in config:
|
| 131 |
+
for name, component in config["components"].items():
|
| 132 |
+
rules = component.get("rules", None)
|
| 133 |
+
if rules:
|
| 134 |
+
self[name].ruler.enableOnly(rules)
|
| 135 |
+
rules2 = component.get("rules2", None)
|
| 136 |
+
if rules2:
|
| 137 |
+
self[name].ruler2.enableOnly(rules2)
|
| 138 |
+
|
| 139 |
+
return self
|
| 140 |
+
|
| 141 |
+
def get_all_rules(self) -> dict[str, list[str]]:
|
| 142 |
+
"""Return the names of all active rules."""
|
| 143 |
+
rules = {
|
| 144 |
+
chain: self[chain].ruler.get_all_rules()
|
| 145 |
+
for chain in ["core", "block", "inline"]
|
| 146 |
+
}
|
| 147 |
+
rules["inline2"] = self.inline.ruler2.get_all_rules()
|
| 148 |
+
return rules
|
| 149 |
+
|
| 150 |
+
def get_active_rules(self) -> dict[str, list[str]]:
|
| 151 |
+
"""Return the names of all active rules."""
|
| 152 |
+
rules = {
|
| 153 |
+
chain: self[chain].ruler.get_active_rules()
|
| 154 |
+
for chain in ["core", "block", "inline"]
|
| 155 |
+
}
|
| 156 |
+
rules["inline2"] = self.inline.ruler2.get_active_rules()
|
| 157 |
+
return rules
|
| 158 |
+
|
| 159 |
+
def enable(
|
| 160 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 161 |
+
) -> MarkdownIt:
|
| 162 |
+
"""Enable list or rules. (chainable)
|
| 163 |
+
|
| 164 |
+
:param names: rule name or list of rule names to enable.
|
| 165 |
+
:param ignoreInvalid: set `true` to ignore errors when rule not found.
|
| 166 |
+
|
| 167 |
+
It will automatically find appropriate components,
|
| 168 |
+
containing rules with given names. If rule not found, and `ignoreInvalid`
|
| 169 |
+
not set - throws exception.
|
| 170 |
+
|
| 171 |
+
Example::
|
| 172 |
+
|
| 173 |
+
md = MarkdownIt().enable(['sub', 'sup']).disable('smartquotes')
|
| 174 |
+
|
| 175 |
+
"""
|
| 176 |
+
result = []
|
| 177 |
+
|
| 178 |
+
if isinstance(names, str):
|
| 179 |
+
names = [names]
|
| 180 |
+
|
| 181 |
+
for chain in ["core", "block", "inline"]:
|
| 182 |
+
result.extend(self[chain].ruler.enable(names, True))
|
| 183 |
+
result.extend(self.inline.ruler2.enable(names, True))
|
| 184 |
+
|
| 185 |
+
missed = [name for name in names if name not in result]
|
| 186 |
+
if missed and not ignoreInvalid:
|
| 187 |
+
raise ValueError(f"MarkdownIt. Failed to enable unknown rule(s): {missed}")
|
| 188 |
+
|
| 189 |
+
return self
|
| 190 |
+
|
| 191 |
+
def disable(
|
| 192 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 193 |
+
) -> MarkdownIt:
|
| 194 |
+
"""The same as [[MarkdownIt.enable]], but turn specified rules off. (chainable)
|
| 195 |
+
|
| 196 |
+
:param names: rule name or list of rule names to disable.
|
| 197 |
+
:param ignoreInvalid: set `true` to ignore errors when rule not found.
|
| 198 |
+
|
| 199 |
+
"""
|
| 200 |
+
result = []
|
| 201 |
+
|
| 202 |
+
if isinstance(names, str):
|
| 203 |
+
names = [names]
|
| 204 |
+
|
| 205 |
+
for chain in ["core", "block", "inline"]:
|
| 206 |
+
result.extend(self[chain].ruler.disable(names, True))
|
| 207 |
+
result.extend(self.inline.ruler2.disable(names, True))
|
| 208 |
+
|
| 209 |
+
missed = [name for name in names if name not in result]
|
| 210 |
+
if missed and not ignoreInvalid:
|
| 211 |
+
raise ValueError(f"MarkdownIt. Failed to disable unknown rule(s): {missed}")
|
| 212 |
+
return self
|
| 213 |
+
|
| 214 |
+
@contextmanager
|
| 215 |
+
def reset_rules(self) -> Generator[None, None, None]:
|
| 216 |
+
"""A context manager, that will reset the current enabled rules on exit."""
|
| 217 |
+
chain_rules = self.get_active_rules()
|
| 218 |
+
yield
|
| 219 |
+
for chain, rules in chain_rules.items():
|
| 220 |
+
if chain != "inline2":
|
| 221 |
+
self[chain].ruler.enableOnly(rules)
|
| 222 |
+
self.inline.ruler2.enableOnly(chain_rules["inline2"])
|
| 223 |
+
|
| 224 |
+
def add_render_rule(
|
| 225 |
+
self, name: str, function: Callable[..., Any], fmt: str = "html"
|
| 226 |
+
) -> None:
|
| 227 |
+
"""Add a rule for rendering a particular Token type.
|
| 228 |
+
|
| 229 |
+
Only applied when ``renderer.__output__ == fmt``
|
| 230 |
+
"""
|
| 231 |
+
if self.renderer.__output__ == fmt:
|
| 232 |
+
self.renderer.rules[name] = function.__get__(self.renderer) # type: ignore
|
| 233 |
+
|
| 234 |
+
def use(
|
| 235 |
+
self, plugin: Callable[..., None], *params: Any, **options: Any
|
| 236 |
+
) -> MarkdownIt:
|
| 237 |
+
"""Load specified plugin with given params into current parser instance. (chainable)
|
| 238 |
+
|
| 239 |
+
It's just a sugar to call `plugin(md, params)` with curring.
|
| 240 |
+
|
| 241 |
+
Example::
|
| 242 |
+
|
| 243 |
+
def func(tokens, idx):
|
| 244 |
+
tokens[idx].content = tokens[idx].content.replace('foo', 'bar')
|
| 245 |
+
md = MarkdownIt().use(plugin, 'foo_replace', 'text', func)
|
| 246 |
+
|
| 247 |
+
"""
|
| 248 |
+
plugin(self, *params, **options)
|
| 249 |
+
return self
|
| 250 |
+
|
| 251 |
+
def parse(self, src: str, env: EnvType | None = None) -> list[Token]:
|
| 252 |
+
"""Parse the source string to a token stream
|
| 253 |
+
|
| 254 |
+
:param src: source string
|
| 255 |
+
:param env: environment sandbox
|
| 256 |
+
|
| 257 |
+
Parse input string and return list of block tokens (special token type
|
| 258 |
+
"inline" will contain list of inline tokens).
|
| 259 |
+
|
| 260 |
+
`env` is used to pass data between "distributed" rules and return additional
|
| 261 |
+
metadata like reference info, needed for the renderer. It also can be used to
|
| 262 |
+
inject data in specific cases. Usually, you will be ok to pass `{}`,
|
| 263 |
+
and then pass updated object to renderer.
|
| 264 |
+
"""
|
| 265 |
+
env = {} if env is None else env
|
| 266 |
+
if not isinstance(env, MutableMapping):
|
| 267 |
+
raise TypeError(f"Input data should be a MutableMapping, not {type(env)}")
|
| 268 |
+
if not isinstance(src, str):
|
| 269 |
+
raise TypeError(f"Input data should be a string, not {type(src)}")
|
| 270 |
+
state = StateCore(src, self, env)
|
| 271 |
+
self.core.process(state)
|
| 272 |
+
return state.tokens
|
| 273 |
+
|
| 274 |
+
def render(self, src: str, env: EnvType | None = None) -> Any:
|
| 275 |
+
"""Render markdown string into html. It does all magic for you :).
|
| 276 |
+
|
| 277 |
+
:param src: source string
|
| 278 |
+
:param env: environment sandbox
|
| 279 |
+
:returns: The output of the loaded renderer
|
| 280 |
+
|
| 281 |
+
`env` can be used to inject additional metadata (`{}` by default).
|
| 282 |
+
But you will not need it with high probability. See also comment
|
| 283 |
+
in [[MarkdownIt.parse]].
|
| 284 |
+
"""
|
| 285 |
+
env = {} if env is None else env
|
| 286 |
+
return self.renderer.render(self.parse(src, env), self.options, env)
|
| 287 |
+
|
| 288 |
+
def parseInline(self, src: str, env: EnvType | None = None) -> list[Token]:
|
| 289 |
+
"""The same as [[MarkdownIt.parse]] but skip all block rules.
|
| 290 |
+
|
| 291 |
+
:param src: source string
|
| 292 |
+
:param env: environment sandbox
|
| 293 |
+
|
| 294 |
+
It returns the
|
| 295 |
+
block tokens list with the single `inline` element, containing parsed inline
|
| 296 |
+
tokens in `children` property. Also updates `env` object.
|
| 297 |
+
"""
|
| 298 |
+
env = {} if env is None else env
|
| 299 |
+
if not isinstance(env, MutableMapping):
|
| 300 |
+
raise TypeError(f"Input data should be an MutableMapping, not {type(env)}")
|
| 301 |
+
if not isinstance(src, str):
|
| 302 |
+
raise TypeError(f"Input data should be a string, not {type(src)}")
|
| 303 |
+
state = StateCore(src, self, env)
|
| 304 |
+
state.inlineMode = True
|
| 305 |
+
self.core.process(state)
|
| 306 |
+
return state.tokens
|
| 307 |
+
|
| 308 |
+
def renderInline(self, src: str, env: EnvType | None = None) -> Any:
|
| 309 |
+
"""Similar to [[MarkdownIt.render]] but for single paragraph content.
|
| 310 |
+
|
| 311 |
+
:param src: source string
|
| 312 |
+
:param env: environment sandbox
|
| 313 |
+
|
| 314 |
+
Similar to [[MarkdownIt.render]] but for single paragraph content. Result
|
| 315 |
+
will NOT be wrapped into `<p>` tags.
|
| 316 |
+
"""
|
| 317 |
+
env = {} if env is None else env
|
| 318 |
+
return self.renderer.render(self.parseInline(src, env), self.options, env)
|
| 319 |
+
|
| 320 |
+
# link methods
|
| 321 |
+
|
| 322 |
+
def validateLink(self, url: str) -> bool:
|
| 323 |
+
"""Validate if the URL link is allowed in output.
|
| 324 |
+
|
| 325 |
+
This validator can prohibit more than really needed to prevent XSS.
|
| 326 |
+
It's a tradeoff to keep code simple and to be secure by default.
|
| 327 |
+
|
| 328 |
+
Note: the url should be normalized at this point, and existing entities decoded.
|
| 329 |
+
"""
|
| 330 |
+
return normalize_url.validateLink(url)
|
| 331 |
+
|
| 332 |
+
def normalizeLink(self, url: str) -> str:
|
| 333 |
+
"""Normalize destination URLs in links
|
| 334 |
+
|
| 335 |
+
::
|
| 336 |
+
|
| 337 |
+
[label]: destination 'title'
|
| 338 |
+
^^^^^^^^^^^
|
| 339 |
+
"""
|
| 340 |
+
return normalize_url.normalizeLink(url)
|
| 341 |
+
|
| 342 |
+
def normalizeLinkText(self, link: str) -> str:
|
| 343 |
+
"""Normalize autolink content
|
| 344 |
+
|
| 345 |
+
::
|
| 346 |
+
|
| 347 |
+
<destination>
|
| 348 |
+
~~~~~~~~~~~
|
| 349 |
+
"""
|
| 350 |
+
return normalize_url.normalizeLinkText(link)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/parser_block.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Block-level tokenizer."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from collections.abc import Callable
|
| 6 |
+
import logging
|
| 7 |
+
from typing import TYPE_CHECKING
|
| 8 |
+
|
| 9 |
+
from . import rules_block
|
| 10 |
+
from .ruler import Ruler
|
| 11 |
+
from .rules_block.state_block import StateBlock
|
| 12 |
+
from .token import Token
|
| 13 |
+
from .utils import EnvType
|
| 14 |
+
|
| 15 |
+
if TYPE_CHECKING:
|
| 16 |
+
from markdown_it import MarkdownIt
|
| 17 |
+
|
| 18 |
+
LOGGER = logging.getLogger(__name__)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
RuleFuncBlockType = Callable[[StateBlock, int, int, bool], bool]
|
| 22 |
+
"""(state: StateBlock, startLine: int, endLine: int, silent: bool) -> matched: bool)
|
| 23 |
+
|
| 24 |
+
`silent` disables token generation, useful for lookahead.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
_rules: list[tuple[str, RuleFuncBlockType, list[str]]] = [
|
| 28 |
+
# First 2 params - rule name & source. Secondary array - list of rules,
|
| 29 |
+
# which can be terminated by this one.
|
| 30 |
+
("table", rules_block.table, ["paragraph", "reference"]),
|
| 31 |
+
("code", rules_block.code, []),
|
| 32 |
+
("fence", rules_block.fence, ["paragraph", "reference", "blockquote", "list"]),
|
| 33 |
+
(
|
| 34 |
+
"blockquote",
|
| 35 |
+
rules_block.blockquote,
|
| 36 |
+
["paragraph", "reference", "blockquote", "list"],
|
| 37 |
+
),
|
| 38 |
+
("hr", rules_block.hr, ["paragraph", "reference", "blockquote", "list"]),
|
| 39 |
+
("list", rules_block.list_block, ["paragraph", "reference", "blockquote"]),
|
| 40 |
+
("reference", rules_block.reference, []),
|
| 41 |
+
("html_block", rules_block.html_block, ["paragraph", "reference", "blockquote"]),
|
| 42 |
+
("heading", rules_block.heading, ["paragraph", "reference", "blockquote"]),
|
| 43 |
+
("lheading", rules_block.lheading, []),
|
| 44 |
+
("paragraph", rules_block.paragraph, []),
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class ParserBlock:
|
| 49 |
+
"""
|
| 50 |
+
ParserBlock#ruler -> Ruler
|
| 51 |
+
|
| 52 |
+
[[Ruler]] instance. Keep configuration of block rules.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def __init__(self) -> None:
|
| 56 |
+
self.ruler = Ruler[RuleFuncBlockType]()
|
| 57 |
+
for name, rule, alt in _rules:
|
| 58 |
+
self.ruler.push(name, rule, {"alt": alt})
|
| 59 |
+
|
| 60 |
+
def tokenize(self, state: StateBlock, startLine: int, endLine: int) -> None:
|
| 61 |
+
"""Generate tokens for input range."""
|
| 62 |
+
rules = self.ruler.getRules("")
|
| 63 |
+
line = startLine
|
| 64 |
+
maxNesting = state.md.options.maxNesting
|
| 65 |
+
hasEmptyLines = False
|
| 66 |
+
|
| 67 |
+
while line < endLine:
|
| 68 |
+
state.line = line = state.skipEmptyLines(line)
|
| 69 |
+
if line >= endLine:
|
| 70 |
+
break
|
| 71 |
+
if state.sCount[line] < state.blkIndent:
|
| 72 |
+
# Termination condition for nested calls.
|
| 73 |
+
# Nested calls currently used for blockquotes & lists
|
| 74 |
+
break
|
| 75 |
+
if state.level >= maxNesting:
|
| 76 |
+
# If nesting level exceeded - skip tail to the end.
|
| 77 |
+
# That's not ordinary situation and we should not care about content.
|
| 78 |
+
state.line = endLine
|
| 79 |
+
break
|
| 80 |
+
|
| 81 |
+
# Try all possible rules.
|
| 82 |
+
# On success, rule should:
|
| 83 |
+
# - update `state.line`
|
| 84 |
+
# - update `state.tokens`
|
| 85 |
+
# - return True
|
| 86 |
+
for rule in rules:
|
| 87 |
+
if rule(state, line, endLine, False):
|
| 88 |
+
break
|
| 89 |
+
|
| 90 |
+
# set state.tight if we had an empty line before current tag
|
| 91 |
+
# i.e. latest empty line should not count
|
| 92 |
+
state.tight = not hasEmptyLines
|
| 93 |
+
|
| 94 |
+
line = state.line
|
| 95 |
+
|
| 96 |
+
# paragraph might "eat" one newline after it in nested lists
|
| 97 |
+
if (line - 1) < endLine and state.isEmpty(line - 1):
|
| 98 |
+
hasEmptyLines = True
|
| 99 |
+
|
| 100 |
+
if line < endLine and state.isEmpty(line):
|
| 101 |
+
hasEmptyLines = True
|
| 102 |
+
line += 1
|
| 103 |
+
state.line = line
|
| 104 |
+
|
| 105 |
+
def parse(
|
| 106 |
+
self, src: str, md: MarkdownIt, env: EnvType, outTokens: list[Token]
|
| 107 |
+
) -> list[Token] | None:
|
| 108 |
+
"""Process input string and push block tokens into `outTokens`."""
|
| 109 |
+
if not src:
|
| 110 |
+
return None
|
| 111 |
+
state = StateBlock(src, md, env, outTokens)
|
| 112 |
+
self.tokenize(state, state.line, state.lineMax)
|
| 113 |
+
return state.tokens
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/parser_core.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
* class Core
|
| 3 |
+
*
|
| 4 |
+
* Top-level rules executor. Glues block/inline parsers and does intermediate
|
| 5 |
+
* transformations.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
from collections.abc import Callable
|
| 11 |
+
|
| 12 |
+
from .ruler import Ruler
|
| 13 |
+
from .rules_core import (
|
| 14 |
+
block,
|
| 15 |
+
inline,
|
| 16 |
+
linkify,
|
| 17 |
+
normalize,
|
| 18 |
+
replace,
|
| 19 |
+
smartquotes,
|
| 20 |
+
text_join,
|
| 21 |
+
)
|
| 22 |
+
from .rules_core.state_core import StateCore
|
| 23 |
+
|
| 24 |
+
RuleFuncCoreType = Callable[[StateCore], None]
|
| 25 |
+
|
| 26 |
+
_rules: list[tuple[str, RuleFuncCoreType]] = [
|
| 27 |
+
("normalize", normalize),
|
| 28 |
+
("block", block),
|
| 29 |
+
("inline", inline),
|
| 30 |
+
("linkify", linkify),
|
| 31 |
+
("replacements", replace),
|
| 32 |
+
("smartquotes", smartquotes),
|
| 33 |
+
("text_join", text_join),
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class ParserCore:
|
| 38 |
+
def __init__(self) -> None:
|
| 39 |
+
self.ruler = Ruler[RuleFuncCoreType]()
|
| 40 |
+
for name, rule in _rules:
|
| 41 |
+
self.ruler.push(name, rule)
|
| 42 |
+
|
| 43 |
+
def process(self, state: StateCore) -> None:
|
| 44 |
+
"""Executes core chain rules."""
|
| 45 |
+
for rule in self.ruler.getRules(""):
|
| 46 |
+
rule(state)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/parser_inline.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tokenizes paragraph content."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from collections.abc import Callable
|
| 6 |
+
from typing import TYPE_CHECKING
|
| 7 |
+
|
| 8 |
+
from . import rules_inline
|
| 9 |
+
from .ruler import Ruler
|
| 10 |
+
from .rules_inline.state_inline import StateInline
|
| 11 |
+
from .token import Token
|
| 12 |
+
from .utils import EnvType
|
| 13 |
+
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from markdown_it import MarkdownIt
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Parser rules
|
| 19 |
+
RuleFuncInlineType = Callable[[StateInline, bool], bool]
|
| 20 |
+
"""(state: StateInline, silent: bool) -> matched: bool)
|
| 21 |
+
|
| 22 |
+
`silent` disables token generation, useful for lookahead.
|
| 23 |
+
"""
|
| 24 |
+
_rules: list[tuple[str, RuleFuncInlineType]] = [
|
| 25 |
+
("text", rules_inline.text),
|
| 26 |
+
("linkify", rules_inline.linkify),
|
| 27 |
+
("newline", rules_inline.newline),
|
| 28 |
+
("escape", rules_inline.escape),
|
| 29 |
+
("backticks", rules_inline.backtick),
|
| 30 |
+
("strikethrough", rules_inline.strikethrough.tokenize),
|
| 31 |
+
("emphasis", rules_inline.emphasis.tokenize),
|
| 32 |
+
("link", rules_inline.link),
|
| 33 |
+
("image", rules_inline.image),
|
| 34 |
+
("autolink", rules_inline.autolink),
|
| 35 |
+
("html_inline", rules_inline.html_inline),
|
| 36 |
+
("entity", rules_inline.entity),
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
# Note `rule2` ruleset was created specifically for emphasis/strikethrough
|
| 40 |
+
# post-processing and may be changed in the future.
|
| 41 |
+
#
|
| 42 |
+
# Don't use this for anything except pairs (plugins working with `balance_pairs`).
|
| 43 |
+
#
|
| 44 |
+
RuleFuncInline2Type = Callable[[StateInline], None]
|
| 45 |
+
_rules2: list[tuple[str, RuleFuncInline2Type]] = [
|
| 46 |
+
("balance_pairs", rules_inline.link_pairs),
|
| 47 |
+
("strikethrough", rules_inline.strikethrough.postProcess),
|
| 48 |
+
("emphasis", rules_inline.emphasis.postProcess),
|
| 49 |
+
# rules for pairs separate '**' into its own text tokens, which may be left unused,
|
| 50 |
+
# rule below merges unused segments back with the rest of the text
|
| 51 |
+
("fragments_join", rules_inline.fragments_join),
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class ParserInline:
|
| 56 |
+
def __init__(self) -> None:
|
| 57 |
+
self.ruler = Ruler[RuleFuncInlineType]()
|
| 58 |
+
for name, rule in _rules:
|
| 59 |
+
self.ruler.push(name, rule)
|
| 60 |
+
# Second ruler used for post-processing (e.g. in emphasis-like rules)
|
| 61 |
+
self.ruler2 = Ruler[RuleFuncInline2Type]()
|
| 62 |
+
for name, rule2 in _rules2:
|
| 63 |
+
self.ruler2.push(name, rule2)
|
| 64 |
+
|
| 65 |
+
def skipToken(self, state: StateInline) -> None:
|
| 66 |
+
"""Skip single token by running all rules in validation mode;
|
| 67 |
+
returns `True` if any rule reported success
|
| 68 |
+
"""
|
| 69 |
+
ok = False
|
| 70 |
+
pos = state.pos
|
| 71 |
+
rules = self.ruler.getRules("")
|
| 72 |
+
maxNesting = state.md.options["maxNesting"]
|
| 73 |
+
cache = state.cache
|
| 74 |
+
|
| 75 |
+
if pos in cache:
|
| 76 |
+
state.pos = cache[pos]
|
| 77 |
+
return
|
| 78 |
+
|
| 79 |
+
if state.level < maxNesting:
|
| 80 |
+
for rule in rules:
|
| 81 |
+
# Increment state.level and decrement it later to limit recursion.
|
| 82 |
+
# It's harmless to do here, because no tokens are created.
|
| 83 |
+
# But ideally, we'd need a separate private state variable for this purpose.
|
| 84 |
+
state.level += 1
|
| 85 |
+
ok = rule(state, True)
|
| 86 |
+
state.level -= 1
|
| 87 |
+
if ok:
|
| 88 |
+
break
|
| 89 |
+
else:
|
| 90 |
+
# Too much nesting, just skip until the end of the paragraph.
|
| 91 |
+
#
|
| 92 |
+
# NOTE: this will cause links to behave incorrectly in the following case,
|
| 93 |
+
# when an amount of `[` is exactly equal to `maxNesting + 1`:
|
| 94 |
+
#
|
| 95 |
+
# [[[[[[[[[[[[[[[[[[[[[foo]()
|
| 96 |
+
#
|
| 97 |
+
# TODO: remove this workaround when CM standard will allow nested links
|
| 98 |
+
# (we can replace it by preventing links from being parsed in
|
| 99 |
+
# validation mode)
|
| 100 |
+
#
|
| 101 |
+
state.pos = state.posMax
|
| 102 |
+
|
| 103 |
+
if not ok:
|
| 104 |
+
state.pos += 1
|
| 105 |
+
cache[pos] = state.pos
|
| 106 |
+
|
| 107 |
+
def tokenize(self, state: StateInline) -> None:
|
| 108 |
+
"""Generate tokens for input range."""
|
| 109 |
+
ok = False
|
| 110 |
+
rules = self.ruler.getRules("")
|
| 111 |
+
end = state.posMax
|
| 112 |
+
maxNesting = state.md.options["maxNesting"]
|
| 113 |
+
|
| 114 |
+
while state.pos < end:
|
| 115 |
+
# Try all possible rules.
|
| 116 |
+
# On success, rule should:
|
| 117 |
+
#
|
| 118 |
+
# - update `state.pos`
|
| 119 |
+
# - update `state.tokens`
|
| 120 |
+
# - return true
|
| 121 |
+
|
| 122 |
+
if state.level < maxNesting:
|
| 123 |
+
for rule in rules:
|
| 124 |
+
ok = rule(state, False)
|
| 125 |
+
if ok:
|
| 126 |
+
break
|
| 127 |
+
|
| 128 |
+
if ok:
|
| 129 |
+
if state.pos >= end:
|
| 130 |
+
break
|
| 131 |
+
continue
|
| 132 |
+
|
| 133 |
+
state.pending += state.src[state.pos]
|
| 134 |
+
state.pos += 1
|
| 135 |
+
|
| 136 |
+
if state.pending:
|
| 137 |
+
state.pushPending()
|
| 138 |
+
|
| 139 |
+
def parse(
|
| 140 |
+
self, src: str, md: MarkdownIt, env: EnvType, tokens: list[Token]
|
| 141 |
+
) -> list[Token]:
|
| 142 |
+
"""Process input string and push inline tokens into `tokens`"""
|
| 143 |
+
state = StateInline(src, md, env, tokens)
|
| 144 |
+
self.tokenize(state)
|
| 145 |
+
rules2 = self.ruler2.getRules("")
|
| 146 |
+
for rule in rules2:
|
| 147 |
+
rule(state)
|
| 148 |
+
return state.tokens
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/port.yaml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- package: markdown-it/markdown-it
|
| 2 |
+
version: 14.1.0
|
| 3 |
+
commit: 0fe7ccb4b7f30236fb05f623be6924961d296d3d
|
| 4 |
+
date: Mar 19, 2024
|
| 5 |
+
notes:
|
| 6 |
+
- Rename variables that use python built-in names, e.g.
|
| 7 |
+
- `max` -> `maximum`
|
| 8 |
+
- `len` -> `length`
|
| 9 |
+
- `str` -> `string`
|
| 10 |
+
- |
|
| 11 |
+
Convert JS `for` loops to `while` loops
|
| 12 |
+
this is generally the main difference between the codes,
|
| 13 |
+
because in python you can't do e.g. `for {i=1;i<x;i++} {}`
|
| 14 |
+
- |
|
| 15 |
+
`env` is a common Python dictionary, and so does not have attribute access to keys,
|
| 16 |
+
as with JavaScript dictionaries.
|
| 17 |
+
`options` have attribute access only to core markdownit configuration options
|
| 18 |
+
- |
|
| 19 |
+
`Token.attrs` is a dictionary, instead of a list of lists.
|
| 20 |
+
Upstream the list format is only used to guarantee order: https://github.com/markdown-it/markdown-it/issues/142,
|
| 21 |
+
but in Python 3.7+ order of dictionaries is guaranteed.
|
| 22 |
+
One should anyhow use the `attrGet`, `attrSet`, `attrPush` and `attrJoin` methods
|
| 23 |
+
to manipulate `Token.attrs`, which have an identical signature to those upstream.
|
| 24 |
+
- Use python version of `charCodeAt`
|
| 25 |
+
- |
|
| 26 |
+
Use `str` units instead of `int`s to represent Unicode codepoints.
|
| 27 |
+
This provides a significant performance boost
|
| 28 |
+
- |
|
| 29 |
+
In markdown_it/rules_block/reference.py,
|
| 30 |
+
record line range in state.env["references"] and add state.env["duplicate_refs"]
|
| 31 |
+
This is to allow renderers to report on issues regarding references
|
| 32 |
+
- |
|
| 33 |
+
The `MarkdownIt.__init__` signature is slightly different for updating options,
|
| 34 |
+
since you must always specify the config first, e.g.
|
| 35 |
+
use `MarkdownIt("commonmark", {"html": False})` instead of `MarkdownIt({"html": False})`
|
| 36 |
+
- The default configuration preset for `MarkdownIt` is "commonmark" not "default"
|
| 37 |
+
- Allow custom renderer to be passed to `MarkdownIt`
|
| 38 |
+
- |
|
| 39 |
+
change render method signatures
|
| 40 |
+
`func(tokens, idx, options, env, slf)` to
|
| 41 |
+
`func(self, tokens, idx, options, env)`
|
| 42 |
+
- |
|
| 43 |
+
Extensions add render methods by format
|
| 44 |
+
`MarkdownIt.add_render_rule(name, function, fmt="html")`,
|
| 45 |
+
rather than `MarkdownIt.renderer.rules[name] = function`
|
| 46 |
+
and renderers should declare a class property `__output__ = "html"`.
|
| 47 |
+
This allows for extensibility to more than just HTML renderers
|
| 48 |
+
- inline tokens in tables are assigned a map (this is helpful for propagation to children)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ("commonmark", "default", "gfm_like", "js_default", "zero")
|
| 2 |
+
|
| 3 |
+
from ..utils import PresetType
|
| 4 |
+
from . import commonmark, default, zero
|
| 5 |
+
|
| 6 |
+
js_default = default
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class gfm_like: # noqa: N801
|
| 10 |
+
"""GitHub Flavoured Markdown (GFM) like.
|
| 11 |
+
|
| 12 |
+
This adds the linkify, table and strikethrough components to CommmonMark.
|
| 13 |
+
|
| 14 |
+
Note, it lacks task-list items and raw HTML filtering,
|
| 15 |
+
to meet the the full GFM specification
|
| 16 |
+
(see https://github.github.com/gfm/#autolinks-extension-).
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
@staticmethod
|
| 20 |
+
def make() -> PresetType:
|
| 21 |
+
config = commonmark.make()
|
| 22 |
+
config["components"]["core"]["rules"].append("linkify")
|
| 23 |
+
config["components"]["block"]["rules"].append("table")
|
| 24 |
+
config["components"]["inline"]["rules"].extend(["strikethrough", "linkify"])
|
| 25 |
+
config["components"]["inline"]["rules2"].append("strikethrough")
|
| 26 |
+
config["options"]["linkify"] = True
|
| 27 |
+
config["options"]["html"] = True
|
| 28 |
+
return config
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/commonmark.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Commonmark default options.
|
| 2 |
+
|
| 3 |
+
This differs to presets.default,
|
| 4 |
+
primarily in that it allows HTML and does not enable components:
|
| 5 |
+
|
| 6 |
+
- block: table
|
| 7 |
+
- inline: strikethrough
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from ..utils import PresetType
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def make() -> PresetType:
|
| 14 |
+
return {
|
| 15 |
+
"options": {
|
| 16 |
+
"maxNesting": 20, # Internal protection, recursion limit
|
| 17 |
+
"html": True, # Enable HTML tags in source,
|
| 18 |
+
# this is just a shorthand for .enable(["html_inline", "html_block"])
|
| 19 |
+
# used by the linkify rule:
|
| 20 |
+
"linkify": False, # autoconvert URL-like texts to links
|
| 21 |
+
# used by the replacements and smartquotes rules
|
| 22 |
+
# Enable some language-neutral replacements + quotes beautification
|
| 23 |
+
"typographer": False,
|
| 24 |
+
# used by the smartquotes rule:
|
| 25 |
+
# Double + single quotes replacement pairs, when typographer enabled,
|
| 26 |
+
# and smartquotes on. Could be either a String or an Array.
|
| 27 |
+
#
|
| 28 |
+
# For example, you can use '«»„“' for Russian, '„“‚‘' for German,
|
| 29 |
+
# and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
|
| 30 |
+
"quotes": "\u201c\u201d\u2018\u2019", # /* “”‘’ */
|
| 31 |
+
# Renderer specific; these options are used directly in the HTML renderer
|
| 32 |
+
"xhtmlOut": True, # Use '/' to close single tags (<br />)
|
| 33 |
+
"breaks": False, # Convert '\n' in paragraphs into <br>
|
| 34 |
+
"langPrefix": "language-", # CSS language prefix for fenced blocks
|
| 35 |
+
# Highlighter function. Should return escaped HTML,
|
| 36 |
+
# or '' if the source string is not changed and should be escaped externally.
|
| 37 |
+
# If result starts with <pre... internal wrapper is skipped.
|
| 38 |
+
#
|
| 39 |
+
# function (/*str, lang, attrs*/) { return ''; }
|
| 40 |
+
#
|
| 41 |
+
"highlight": None,
|
| 42 |
+
},
|
| 43 |
+
"components": {
|
| 44 |
+
"core": {"rules": ["normalize", "block", "inline", "text_join"]},
|
| 45 |
+
"block": {
|
| 46 |
+
"rules": [
|
| 47 |
+
"blockquote",
|
| 48 |
+
"code",
|
| 49 |
+
"fence",
|
| 50 |
+
"heading",
|
| 51 |
+
"hr",
|
| 52 |
+
"html_block",
|
| 53 |
+
"lheading",
|
| 54 |
+
"list",
|
| 55 |
+
"reference",
|
| 56 |
+
"paragraph",
|
| 57 |
+
]
|
| 58 |
+
},
|
| 59 |
+
"inline": {
|
| 60 |
+
"rules": [
|
| 61 |
+
"autolink",
|
| 62 |
+
"backticks",
|
| 63 |
+
"emphasis",
|
| 64 |
+
"entity",
|
| 65 |
+
"escape",
|
| 66 |
+
"html_inline",
|
| 67 |
+
"image",
|
| 68 |
+
"link",
|
| 69 |
+
"newline",
|
| 70 |
+
"text",
|
| 71 |
+
],
|
| 72 |
+
"rules2": ["balance_pairs", "emphasis", "fragments_join"],
|
| 73 |
+
},
|
| 74 |
+
},
|
| 75 |
+
}
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/default.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""markdown-it default options."""
|
| 2 |
+
|
| 3 |
+
from ..utils import PresetType
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def make() -> PresetType:
|
| 7 |
+
return {
|
| 8 |
+
"options": {
|
| 9 |
+
"maxNesting": 100, # Internal protection, recursion limit
|
| 10 |
+
"html": False, # Enable HTML tags in source
|
| 11 |
+
# this is just a shorthand for .disable(["html_inline", "html_block"])
|
| 12 |
+
# used by the linkify rule:
|
| 13 |
+
"linkify": False, # autoconvert URL-like texts to links
|
| 14 |
+
# used by the replacements and smartquotes rules:
|
| 15 |
+
# Enable some language-neutral replacements + quotes beautification
|
| 16 |
+
"typographer": False,
|
| 17 |
+
# used by the smartquotes rule:
|
| 18 |
+
# Double + single quotes replacement pairs, when typographer enabled,
|
| 19 |
+
# and smartquotes on. Could be either a String or an Array.
|
| 20 |
+
# For example, you can use '«»„“' for Russian, '„“‚‘' for German,
|
| 21 |
+
# and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
|
| 22 |
+
"quotes": "\u201c\u201d\u2018\u2019", # /* “”‘’ */
|
| 23 |
+
# Renderer specific; these options are used directly in the HTML renderer
|
| 24 |
+
"xhtmlOut": False, # Use '/' to close single tags (<br />)
|
| 25 |
+
"breaks": False, # Convert '\n' in paragraphs into <br>
|
| 26 |
+
"langPrefix": "language-", # CSS language prefix for fenced blocks
|
| 27 |
+
# Highlighter function. Should return escaped HTML,
|
| 28 |
+
# or '' if the source string is not changed and should be escaped externally.
|
| 29 |
+
# If result starts with <pre... internal wrapper is skipped.
|
| 30 |
+
#
|
| 31 |
+
# function (/*str, lang, attrs*/) { return ''; }
|
| 32 |
+
#
|
| 33 |
+
"highlight": None,
|
| 34 |
+
},
|
| 35 |
+
"components": {"core": {}, "block": {}, "inline": {}},
|
| 36 |
+
}
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/presets/zero.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
"Zero" preset, with nothing enabled. Useful for manual configuring of simple
|
| 3 |
+
modes. For example, to parse bold/italic only.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from ..utils import PresetType
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def make() -> PresetType:
|
| 10 |
+
return {
|
| 11 |
+
"options": {
|
| 12 |
+
"maxNesting": 20, # Internal protection, recursion limit
|
| 13 |
+
"html": False, # Enable HTML tags in source
|
| 14 |
+
# this is just a shorthand for .disable(["html_inline", "html_block"])
|
| 15 |
+
# used by the linkify rule:
|
| 16 |
+
"linkify": False, # autoconvert URL-like texts to links
|
| 17 |
+
# used by the replacements and smartquotes rules:
|
| 18 |
+
# Enable some language-neutral replacements + quotes beautification
|
| 19 |
+
"typographer": False,
|
| 20 |
+
# used by the smartquotes rule:
|
| 21 |
+
# Double + single quotes replacement pairs, when typographer enabled,
|
| 22 |
+
# and smartquotes on. Could be either a String or an Array.
|
| 23 |
+
# For example, you can use '«»„“' for Russian, '„“‚‘' for German,
|
| 24 |
+
# and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp).
|
| 25 |
+
"quotes": "\u201c\u201d\u2018\u2019", # /* “”‘’ */
|
| 26 |
+
# Renderer specific; these options are used directly in the HTML renderer
|
| 27 |
+
"xhtmlOut": False, # Use '/' to close single tags (<br />)
|
| 28 |
+
"breaks": False, # Convert '\n' in paragraphs into <br>
|
| 29 |
+
"langPrefix": "language-", # CSS language prefix for fenced blocks
|
| 30 |
+
# Highlighter function. Should return escaped HTML,
|
| 31 |
+
# or '' if the source string is not changed and should be escaped externally.
|
| 32 |
+
# If result starts with <pre... internal wrapper is skipped.
|
| 33 |
+
# function (/*str, lang, attrs*/) { return ''; }
|
| 34 |
+
"highlight": None,
|
| 35 |
+
},
|
| 36 |
+
"components": {
|
| 37 |
+
"core": {"rules": ["normalize", "block", "inline", "text_join"]},
|
| 38 |
+
"block": {"rules": ["paragraph"]},
|
| 39 |
+
"inline": {
|
| 40 |
+
"rules": ["text"],
|
| 41 |
+
"rules2": ["balance_pairs", "fragments_join"],
|
| 42 |
+
},
|
| 43 |
+
},
|
| 44 |
+
}
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Marker file for PEP 561
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/renderer.py
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
class Renderer
|
| 3 |
+
|
| 4 |
+
Generates HTML from parsed token stream. Each instance has independent
|
| 5 |
+
copy of rules. Those can be rewritten with ease. Also, you can add new
|
| 6 |
+
rules if you create plugin and adds new token types.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
from collections.abc import Sequence
|
| 12 |
+
import inspect
|
| 13 |
+
from typing import Any, ClassVar, Protocol
|
| 14 |
+
|
| 15 |
+
from .common.utils import escapeHtml, unescapeAll
|
| 16 |
+
from .token import Token
|
| 17 |
+
from .utils import EnvType, OptionsDict
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class RendererProtocol(Protocol):
|
| 21 |
+
__output__: ClassVar[str]
|
| 22 |
+
|
| 23 |
+
def render(
|
| 24 |
+
self, tokens: Sequence[Token], options: OptionsDict, env: EnvType
|
| 25 |
+
) -> Any: ...
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class RendererHTML(RendererProtocol):
|
| 29 |
+
"""Contains render rules for tokens. Can be updated and extended.
|
| 30 |
+
|
| 31 |
+
Example:
|
| 32 |
+
|
| 33 |
+
Each rule is called as independent static function with fixed signature:
|
| 34 |
+
|
| 35 |
+
::
|
| 36 |
+
|
| 37 |
+
class Renderer:
|
| 38 |
+
def token_type_name(self, tokens, idx, options, env) {
|
| 39 |
+
# ...
|
| 40 |
+
return renderedHTML
|
| 41 |
+
|
| 42 |
+
::
|
| 43 |
+
|
| 44 |
+
class CustomRenderer(RendererHTML):
|
| 45 |
+
def strong_open(self, tokens, idx, options, env):
|
| 46 |
+
return '<b>'
|
| 47 |
+
def strong_close(self, tokens, idx, options, env):
|
| 48 |
+
return '</b>'
|
| 49 |
+
|
| 50 |
+
md = MarkdownIt(renderer_cls=CustomRenderer)
|
| 51 |
+
|
| 52 |
+
result = md.render(...)
|
| 53 |
+
|
| 54 |
+
See https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js
|
| 55 |
+
for more details and examples.
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
__output__ = "html"
|
| 59 |
+
|
| 60 |
+
def __init__(self, parser: Any = None):
|
| 61 |
+
self.rules = {
|
| 62 |
+
k: v
|
| 63 |
+
for k, v in inspect.getmembers(self, predicate=inspect.ismethod)
|
| 64 |
+
if not (k.startswith("render") or k.startswith("_"))
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
def render(
|
| 68 |
+
self, tokens: Sequence[Token], options: OptionsDict, env: EnvType
|
| 69 |
+
) -> str:
|
| 70 |
+
"""Takes token stream and generates HTML.
|
| 71 |
+
|
| 72 |
+
:param tokens: list on block tokens to render
|
| 73 |
+
:param options: params of parser instance
|
| 74 |
+
:param env: additional data from parsed input
|
| 75 |
+
|
| 76 |
+
"""
|
| 77 |
+
result = ""
|
| 78 |
+
|
| 79 |
+
for i, token in enumerate(tokens):
|
| 80 |
+
if token.type == "inline":
|
| 81 |
+
if token.children:
|
| 82 |
+
result += self.renderInline(token.children, options, env)
|
| 83 |
+
elif token.type in self.rules:
|
| 84 |
+
result += self.rules[token.type](tokens, i, options, env)
|
| 85 |
+
else:
|
| 86 |
+
result += self.renderToken(tokens, i, options, env)
|
| 87 |
+
|
| 88 |
+
return result
|
| 89 |
+
|
| 90 |
+
def renderInline(
|
| 91 |
+
self, tokens: Sequence[Token], options: OptionsDict, env: EnvType
|
| 92 |
+
) -> str:
|
| 93 |
+
"""The same as ``render``, but for single token of `inline` type.
|
| 94 |
+
|
| 95 |
+
:param tokens: list on block tokens to render
|
| 96 |
+
:param options: params of parser instance
|
| 97 |
+
:param env: additional data from parsed input (references, for example)
|
| 98 |
+
"""
|
| 99 |
+
result = ""
|
| 100 |
+
|
| 101 |
+
for i, token in enumerate(tokens):
|
| 102 |
+
if token.type in self.rules:
|
| 103 |
+
result += self.rules[token.type](tokens, i, options, env)
|
| 104 |
+
else:
|
| 105 |
+
result += self.renderToken(tokens, i, options, env)
|
| 106 |
+
|
| 107 |
+
return result
|
| 108 |
+
|
| 109 |
+
def renderToken(
|
| 110 |
+
self,
|
| 111 |
+
tokens: Sequence[Token],
|
| 112 |
+
idx: int,
|
| 113 |
+
options: OptionsDict,
|
| 114 |
+
env: EnvType,
|
| 115 |
+
) -> str:
|
| 116 |
+
"""Default token renderer.
|
| 117 |
+
|
| 118 |
+
Can be overridden by custom function
|
| 119 |
+
|
| 120 |
+
:param idx: token index to render
|
| 121 |
+
:param options: params of parser instance
|
| 122 |
+
"""
|
| 123 |
+
result = ""
|
| 124 |
+
needLf = False
|
| 125 |
+
token = tokens[idx]
|
| 126 |
+
|
| 127 |
+
# Tight list paragraphs
|
| 128 |
+
if token.hidden:
|
| 129 |
+
return ""
|
| 130 |
+
|
| 131 |
+
# Insert a newline between hidden paragraph and subsequent opening
|
| 132 |
+
# block-level tag.
|
| 133 |
+
#
|
| 134 |
+
# For example, here we should insert a newline before blockquote:
|
| 135 |
+
# - a
|
| 136 |
+
# >
|
| 137 |
+
#
|
| 138 |
+
if token.block and token.nesting != -1 and idx and tokens[idx - 1].hidden:
|
| 139 |
+
result += "\n"
|
| 140 |
+
|
| 141 |
+
# Add token name, e.g. `<img`
|
| 142 |
+
result += ("</" if token.nesting == -1 else "<") + token.tag
|
| 143 |
+
|
| 144 |
+
# Encode attributes, e.g. `<img src="foo"`
|
| 145 |
+
result += self.renderAttrs(token)
|
| 146 |
+
|
| 147 |
+
# Add a slash for self-closing tags, e.g. `<img src="foo" /`
|
| 148 |
+
if token.nesting == 0 and options["xhtmlOut"]:
|
| 149 |
+
result += " /"
|
| 150 |
+
|
| 151 |
+
# Check if we need to add a newline after this tag
|
| 152 |
+
if token.block:
|
| 153 |
+
needLf = True
|
| 154 |
+
|
| 155 |
+
if token.nesting == 1 and (idx + 1 < len(tokens)):
|
| 156 |
+
nextToken = tokens[idx + 1]
|
| 157 |
+
|
| 158 |
+
if nextToken.type == "inline" or nextToken.hidden:
|
| 159 |
+
# Block-level tag containing an inline tag.
|
| 160 |
+
#
|
| 161 |
+
needLf = False
|
| 162 |
+
|
| 163 |
+
elif nextToken.nesting == -1 and nextToken.tag == token.tag:
|
| 164 |
+
# Opening tag + closing tag of the same type. E.g. `<li></li>`.
|
| 165 |
+
#
|
| 166 |
+
needLf = False
|
| 167 |
+
|
| 168 |
+
result += ">\n" if needLf else ">"
|
| 169 |
+
|
| 170 |
+
return result
|
| 171 |
+
|
| 172 |
+
@staticmethod
|
| 173 |
+
def renderAttrs(token: Token) -> str:
|
| 174 |
+
"""Render token attributes to string."""
|
| 175 |
+
result = ""
|
| 176 |
+
|
| 177 |
+
for key, value in token.attrItems():
|
| 178 |
+
result += " " + escapeHtml(key) + '="' + escapeHtml(str(value)) + '"'
|
| 179 |
+
|
| 180 |
+
return result
|
| 181 |
+
|
| 182 |
+
def renderInlineAsText(
|
| 183 |
+
self,
|
| 184 |
+
tokens: Sequence[Token] | None,
|
| 185 |
+
options: OptionsDict,
|
| 186 |
+
env: EnvType,
|
| 187 |
+
) -> str:
|
| 188 |
+
"""Special kludge for image `alt` attributes to conform CommonMark spec.
|
| 189 |
+
|
| 190 |
+
Don't try to use it! Spec requires to show `alt` content with stripped markup,
|
| 191 |
+
instead of simple escaping.
|
| 192 |
+
|
| 193 |
+
:param tokens: list on block tokens to render
|
| 194 |
+
:param options: params of parser instance
|
| 195 |
+
:param env: additional data from parsed input
|
| 196 |
+
"""
|
| 197 |
+
result = ""
|
| 198 |
+
|
| 199 |
+
for token in tokens or []:
|
| 200 |
+
if token.type == "text":
|
| 201 |
+
result += token.content
|
| 202 |
+
elif token.type == "image":
|
| 203 |
+
if token.children:
|
| 204 |
+
result += self.renderInlineAsText(token.children, options, env)
|
| 205 |
+
elif token.type == "softbreak":
|
| 206 |
+
result += "\n"
|
| 207 |
+
|
| 208 |
+
return result
|
| 209 |
+
|
| 210 |
+
###################################################
|
| 211 |
+
|
| 212 |
+
def code_inline(
|
| 213 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 214 |
+
) -> str:
|
| 215 |
+
token = tokens[idx]
|
| 216 |
+
return (
|
| 217 |
+
"<code"
|
| 218 |
+
+ self.renderAttrs(token)
|
| 219 |
+
+ ">"
|
| 220 |
+
+ escapeHtml(tokens[idx].content)
|
| 221 |
+
+ "</code>"
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
def code_block(
|
| 225 |
+
self,
|
| 226 |
+
tokens: Sequence[Token],
|
| 227 |
+
idx: int,
|
| 228 |
+
options: OptionsDict,
|
| 229 |
+
env: EnvType,
|
| 230 |
+
) -> str:
|
| 231 |
+
token = tokens[idx]
|
| 232 |
+
|
| 233 |
+
return (
|
| 234 |
+
"<pre"
|
| 235 |
+
+ self.renderAttrs(token)
|
| 236 |
+
+ "><code>"
|
| 237 |
+
+ escapeHtml(tokens[idx].content)
|
| 238 |
+
+ "</code></pre>\n"
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
def fence(
|
| 242 |
+
self,
|
| 243 |
+
tokens: Sequence[Token],
|
| 244 |
+
idx: int,
|
| 245 |
+
options: OptionsDict,
|
| 246 |
+
env: EnvType,
|
| 247 |
+
) -> str:
|
| 248 |
+
token = tokens[idx]
|
| 249 |
+
info = unescapeAll(token.info).strip() if token.info else ""
|
| 250 |
+
langName = ""
|
| 251 |
+
langAttrs = ""
|
| 252 |
+
|
| 253 |
+
if info:
|
| 254 |
+
arr = info.split(maxsplit=1)
|
| 255 |
+
langName = arr[0]
|
| 256 |
+
if len(arr) == 2:
|
| 257 |
+
langAttrs = arr[1]
|
| 258 |
+
|
| 259 |
+
if options.highlight:
|
| 260 |
+
highlighted = options.highlight(
|
| 261 |
+
token.content, langName, langAttrs
|
| 262 |
+
) or escapeHtml(token.content)
|
| 263 |
+
else:
|
| 264 |
+
highlighted = escapeHtml(token.content)
|
| 265 |
+
|
| 266 |
+
if highlighted.startswith("<pre"):
|
| 267 |
+
return highlighted + "\n"
|
| 268 |
+
|
| 269 |
+
# If language exists, inject class gently, without modifying original token.
|
| 270 |
+
# May be, one day we will add .deepClone() for token and simplify this part, but
|
| 271 |
+
# now we prefer to keep things local.
|
| 272 |
+
if info:
|
| 273 |
+
# Fake token just to render attributes
|
| 274 |
+
tmpToken = Token(type="", tag="", nesting=0, attrs=token.attrs.copy())
|
| 275 |
+
tmpToken.attrJoin("class", options.langPrefix + langName)
|
| 276 |
+
|
| 277 |
+
return (
|
| 278 |
+
"<pre><code"
|
| 279 |
+
+ self.renderAttrs(tmpToken)
|
| 280 |
+
+ ">"
|
| 281 |
+
+ highlighted
|
| 282 |
+
+ "</code></pre>\n"
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
return (
|
| 286 |
+
"<pre><code"
|
| 287 |
+
+ self.renderAttrs(token)
|
| 288 |
+
+ ">"
|
| 289 |
+
+ highlighted
|
| 290 |
+
+ "</code></pre>\n"
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
def image(
|
| 294 |
+
self,
|
| 295 |
+
tokens: Sequence[Token],
|
| 296 |
+
idx: int,
|
| 297 |
+
options: OptionsDict,
|
| 298 |
+
env: EnvType,
|
| 299 |
+
) -> str:
|
| 300 |
+
token = tokens[idx]
|
| 301 |
+
|
| 302 |
+
# "alt" attr MUST be set, even if empty. Because it's mandatory and
|
| 303 |
+
# should be placed on proper position for tests.
|
| 304 |
+
if token.children:
|
| 305 |
+
token.attrSet("alt", self.renderInlineAsText(token.children, options, env))
|
| 306 |
+
else:
|
| 307 |
+
token.attrSet("alt", "")
|
| 308 |
+
|
| 309 |
+
return self.renderToken(tokens, idx, options, env)
|
| 310 |
+
|
| 311 |
+
def hardbreak(
|
| 312 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 313 |
+
) -> str:
|
| 314 |
+
return "<br />\n" if options.xhtmlOut else "<br>\n"
|
| 315 |
+
|
| 316 |
+
def softbreak(
|
| 317 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 318 |
+
) -> str:
|
| 319 |
+
return (
|
| 320 |
+
("<br />\n" if options.xhtmlOut else "<br>\n") if options.breaks else "\n"
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
+
def text(
|
| 324 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 325 |
+
) -> str:
|
| 326 |
+
return escapeHtml(tokens[idx].content)
|
| 327 |
+
|
| 328 |
+
def html_block(
|
| 329 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 330 |
+
) -> str:
|
| 331 |
+
return tokens[idx].content
|
| 332 |
+
|
| 333 |
+
def html_inline(
|
| 334 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 335 |
+
) -> str:
|
| 336 |
+
return tokens[idx].content
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/ruler.py
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
class Ruler
|
| 3 |
+
|
| 4 |
+
Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and
|
| 5 |
+
[[MarkdownIt#inline]] to manage sequences of functions (rules):
|
| 6 |
+
|
| 7 |
+
- keep rules in defined order
|
| 8 |
+
- assign the name to each rule
|
| 9 |
+
- enable/disable rules
|
| 10 |
+
- add/replace rules
|
| 11 |
+
- allow assign rules to additional named chains (in the same)
|
| 12 |
+
- caching lists of active rules
|
| 13 |
+
|
| 14 |
+
You will not need use this class directly until write plugins. For simple
|
| 15 |
+
rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and
|
| 16 |
+
[[MarkdownIt.use]].
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
from __future__ import annotations
|
| 20 |
+
|
| 21 |
+
from collections.abc import Iterable
|
| 22 |
+
from dataclasses import dataclass, field
|
| 23 |
+
from typing import TYPE_CHECKING, Generic, TypedDict, TypeVar
|
| 24 |
+
import warnings
|
| 25 |
+
|
| 26 |
+
from .utils import EnvType
|
| 27 |
+
|
| 28 |
+
if TYPE_CHECKING:
|
| 29 |
+
from markdown_it import MarkdownIt
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class StateBase:
|
| 33 |
+
def __init__(self, src: str, md: MarkdownIt, env: EnvType):
|
| 34 |
+
self.src = src
|
| 35 |
+
self.env = env
|
| 36 |
+
self.md = md
|
| 37 |
+
|
| 38 |
+
@property
|
| 39 |
+
def src(self) -> str:
|
| 40 |
+
return self._src
|
| 41 |
+
|
| 42 |
+
@src.setter
|
| 43 |
+
def src(self, value: str) -> None:
|
| 44 |
+
self._src = value
|
| 45 |
+
self._srcCharCode: tuple[int, ...] | None = None
|
| 46 |
+
|
| 47 |
+
@property
|
| 48 |
+
def srcCharCode(self) -> tuple[int, ...]:
|
| 49 |
+
warnings.warn(
|
| 50 |
+
"StateBase.srcCharCode is deprecated. Use StateBase.src instead.",
|
| 51 |
+
DeprecationWarning,
|
| 52 |
+
stacklevel=2,
|
| 53 |
+
)
|
| 54 |
+
if self._srcCharCode is None:
|
| 55 |
+
self._srcCharCode = tuple(ord(c) for c in self._src)
|
| 56 |
+
return self._srcCharCode
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class RuleOptionsType(TypedDict, total=False):
|
| 60 |
+
alt: list[str]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
RuleFuncTv = TypeVar("RuleFuncTv")
|
| 64 |
+
"""A rule function, whose signature is dependent on the state type."""
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@dataclass(slots=True)
|
| 68 |
+
class Rule(Generic[RuleFuncTv]):
|
| 69 |
+
name: str
|
| 70 |
+
enabled: bool
|
| 71 |
+
fn: RuleFuncTv = field(repr=False)
|
| 72 |
+
alt: list[str]
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class Ruler(Generic[RuleFuncTv]):
|
| 76 |
+
def __init__(self) -> None:
|
| 77 |
+
# List of added rules.
|
| 78 |
+
self.__rules__: list[Rule[RuleFuncTv]] = []
|
| 79 |
+
# Cached rule chains.
|
| 80 |
+
# First level - chain name, '' for default.
|
| 81 |
+
# Second level - diginal anchor for fast filtering by charcodes.
|
| 82 |
+
self.__cache__: dict[str, list[RuleFuncTv]] | None = None
|
| 83 |
+
|
| 84 |
+
def __find__(self, name: str) -> int:
|
| 85 |
+
"""Find rule index by name"""
|
| 86 |
+
for i, rule in enumerate(self.__rules__):
|
| 87 |
+
if rule.name == name:
|
| 88 |
+
return i
|
| 89 |
+
return -1
|
| 90 |
+
|
| 91 |
+
def __compile__(self) -> None:
|
| 92 |
+
"""Build rules lookup cache"""
|
| 93 |
+
chains = {""}
|
| 94 |
+
# collect unique names
|
| 95 |
+
for rule in self.__rules__:
|
| 96 |
+
if not rule.enabled:
|
| 97 |
+
continue
|
| 98 |
+
for name in rule.alt:
|
| 99 |
+
chains.add(name)
|
| 100 |
+
self.__cache__ = {}
|
| 101 |
+
for chain in chains:
|
| 102 |
+
self.__cache__[chain] = []
|
| 103 |
+
for rule in self.__rules__:
|
| 104 |
+
if not rule.enabled:
|
| 105 |
+
continue
|
| 106 |
+
if chain and (chain not in rule.alt):
|
| 107 |
+
continue
|
| 108 |
+
self.__cache__[chain].append(rule.fn)
|
| 109 |
+
|
| 110 |
+
def at(
|
| 111 |
+
self, ruleName: str, fn: RuleFuncTv, options: RuleOptionsType | None = None
|
| 112 |
+
) -> None:
|
| 113 |
+
"""Replace rule by name with new function & options.
|
| 114 |
+
|
| 115 |
+
:param ruleName: rule name to replace.
|
| 116 |
+
:param fn: new rule function.
|
| 117 |
+
:param options: new rule options (not mandatory).
|
| 118 |
+
:raises: KeyError if name not found
|
| 119 |
+
"""
|
| 120 |
+
index = self.__find__(ruleName)
|
| 121 |
+
options = options or {}
|
| 122 |
+
if index == -1:
|
| 123 |
+
raise KeyError(f"Parser rule not found: {ruleName}")
|
| 124 |
+
self.__rules__[index].fn = fn
|
| 125 |
+
self.__rules__[index].alt = options.get("alt", [])
|
| 126 |
+
self.__cache__ = None
|
| 127 |
+
|
| 128 |
+
def before(
|
| 129 |
+
self,
|
| 130 |
+
beforeName: str,
|
| 131 |
+
ruleName: str,
|
| 132 |
+
fn: RuleFuncTv,
|
| 133 |
+
options: RuleOptionsType | None = None,
|
| 134 |
+
) -> None:
|
| 135 |
+
"""Add new rule to chain before one with given name.
|
| 136 |
+
|
| 137 |
+
:param beforeName: new rule will be added before this one.
|
| 138 |
+
:param ruleName: new rule will be added before this one.
|
| 139 |
+
:param fn: new rule function.
|
| 140 |
+
:param options: new rule options (not mandatory).
|
| 141 |
+
:raises: KeyError if name not found
|
| 142 |
+
"""
|
| 143 |
+
index = self.__find__(beforeName)
|
| 144 |
+
options = options or {}
|
| 145 |
+
if index == -1:
|
| 146 |
+
raise KeyError(f"Parser rule not found: {beforeName}")
|
| 147 |
+
self.__rules__.insert(
|
| 148 |
+
index, Rule[RuleFuncTv](ruleName, True, fn, options.get("alt", []))
|
| 149 |
+
)
|
| 150 |
+
self.__cache__ = None
|
| 151 |
+
|
| 152 |
+
def after(
|
| 153 |
+
self,
|
| 154 |
+
afterName: str,
|
| 155 |
+
ruleName: str,
|
| 156 |
+
fn: RuleFuncTv,
|
| 157 |
+
options: RuleOptionsType | None = None,
|
| 158 |
+
) -> None:
|
| 159 |
+
"""Add new rule to chain after one with given name.
|
| 160 |
+
|
| 161 |
+
:param afterName: new rule will be added after this one.
|
| 162 |
+
:param ruleName: new rule will be added after this one.
|
| 163 |
+
:param fn: new rule function.
|
| 164 |
+
:param options: new rule options (not mandatory).
|
| 165 |
+
:raises: KeyError if name not found
|
| 166 |
+
"""
|
| 167 |
+
index = self.__find__(afterName)
|
| 168 |
+
options = options or {}
|
| 169 |
+
if index == -1:
|
| 170 |
+
raise KeyError(f"Parser rule not found: {afterName}")
|
| 171 |
+
self.__rules__.insert(
|
| 172 |
+
index + 1, Rule[RuleFuncTv](ruleName, True, fn, options.get("alt", []))
|
| 173 |
+
)
|
| 174 |
+
self.__cache__ = None
|
| 175 |
+
|
| 176 |
+
def push(
|
| 177 |
+
self, ruleName: str, fn: RuleFuncTv, options: RuleOptionsType | None = None
|
| 178 |
+
) -> None:
|
| 179 |
+
"""Push new rule to the end of chain.
|
| 180 |
+
|
| 181 |
+
:param ruleName: new rule will be added to the end of chain.
|
| 182 |
+
:param fn: new rule function.
|
| 183 |
+
:param options: new rule options (not mandatory).
|
| 184 |
+
|
| 185 |
+
"""
|
| 186 |
+
self.__rules__.append(
|
| 187 |
+
Rule[RuleFuncTv](ruleName, True, fn, (options or {}).get("alt", []))
|
| 188 |
+
)
|
| 189 |
+
self.__cache__ = None
|
| 190 |
+
|
| 191 |
+
def enable(
|
| 192 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 193 |
+
) -> list[str]:
|
| 194 |
+
"""Enable rules with given names.
|
| 195 |
+
|
| 196 |
+
:param names: name or list of rule names to enable.
|
| 197 |
+
:param ignoreInvalid: ignore errors when rule not found
|
| 198 |
+
:raises: KeyError if name not found and not ignoreInvalid
|
| 199 |
+
:return: list of found rule names
|
| 200 |
+
"""
|
| 201 |
+
if isinstance(names, str):
|
| 202 |
+
names = [names]
|
| 203 |
+
result: list[str] = []
|
| 204 |
+
for name in names:
|
| 205 |
+
idx = self.__find__(name)
|
| 206 |
+
if (idx < 0) and ignoreInvalid:
|
| 207 |
+
continue
|
| 208 |
+
if (idx < 0) and not ignoreInvalid:
|
| 209 |
+
raise KeyError(f"Rules manager: invalid rule name {name}")
|
| 210 |
+
self.__rules__[idx].enabled = True
|
| 211 |
+
result.append(name)
|
| 212 |
+
self.__cache__ = None
|
| 213 |
+
return result
|
| 214 |
+
|
| 215 |
+
def enableOnly(
|
| 216 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 217 |
+
) -> list[str]:
|
| 218 |
+
"""Enable rules with given names, and disable everything else.
|
| 219 |
+
|
| 220 |
+
:param names: name or list of rule names to enable.
|
| 221 |
+
:param ignoreInvalid: ignore errors when rule not found
|
| 222 |
+
:raises: KeyError if name not found and not ignoreInvalid
|
| 223 |
+
:return: list of found rule names
|
| 224 |
+
"""
|
| 225 |
+
if isinstance(names, str):
|
| 226 |
+
names = [names]
|
| 227 |
+
for rule in self.__rules__:
|
| 228 |
+
rule.enabled = False
|
| 229 |
+
return self.enable(names, ignoreInvalid)
|
| 230 |
+
|
| 231 |
+
def disable(
|
| 232 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 233 |
+
) -> list[str]:
|
| 234 |
+
"""Disable rules with given names.
|
| 235 |
+
|
| 236 |
+
:param names: name or list of rule names to enable.
|
| 237 |
+
:param ignoreInvalid: ignore errors when rule not found
|
| 238 |
+
:raises: KeyError if name not found and not ignoreInvalid
|
| 239 |
+
:return: list of found rule names
|
| 240 |
+
"""
|
| 241 |
+
if isinstance(names, str):
|
| 242 |
+
names = [names]
|
| 243 |
+
result = []
|
| 244 |
+
for name in names:
|
| 245 |
+
idx = self.__find__(name)
|
| 246 |
+
if (idx < 0) and ignoreInvalid:
|
| 247 |
+
continue
|
| 248 |
+
if (idx < 0) and not ignoreInvalid:
|
| 249 |
+
raise KeyError(f"Rules manager: invalid rule name {name}")
|
| 250 |
+
self.__rules__[idx].enabled = False
|
| 251 |
+
result.append(name)
|
| 252 |
+
self.__cache__ = None
|
| 253 |
+
return result
|
| 254 |
+
|
| 255 |
+
def getRules(self, chainName: str = "") -> list[RuleFuncTv]:
|
| 256 |
+
"""Return array of active functions (rules) for given chain name.
|
| 257 |
+
It analyzes rules configuration, compiles caches if not exists and returns result.
|
| 258 |
+
|
| 259 |
+
Default chain name is `''` (empty string). It can't be skipped.
|
| 260 |
+
That's done intentionally, to keep signature monomorphic for high speed.
|
| 261 |
+
|
| 262 |
+
"""
|
| 263 |
+
if self.__cache__ is None:
|
| 264 |
+
self.__compile__()
|
| 265 |
+
assert self.__cache__ is not None
|
| 266 |
+
# Chain can be empty, if rules disabled. But we still have to return Array.
|
| 267 |
+
return self.__cache__.get(chainName, []) or []
|
| 268 |
+
|
| 269 |
+
def get_all_rules(self) -> list[str]:
|
| 270 |
+
"""Return all available rule names."""
|
| 271 |
+
return [r.name for r in self.__rules__]
|
| 272 |
+
|
| 273 |
+
def get_active_rules(self) -> list[str]:
|
| 274 |
+
"""Return the active rule names."""
|
| 275 |
+
return [r.name for r in self.__rules__ if r.enabled]
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = (
|
| 2 |
+
"StateBlock",
|
| 3 |
+
"blockquote",
|
| 4 |
+
"code",
|
| 5 |
+
"fence",
|
| 6 |
+
"heading",
|
| 7 |
+
"hr",
|
| 8 |
+
"html_block",
|
| 9 |
+
"lheading",
|
| 10 |
+
"list_block",
|
| 11 |
+
"paragraph",
|
| 12 |
+
"reference",
|
| 13 |
+
"table",
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
from .blockquote import blockquote
|
| 17 |
+
from .code import code
|
| 18 |
+
from .fence import fence
|
| 19 |
+
from .heading import heading
|
| 20 |
+
from .hr import hr
|
| 21 |
+
from .html_block import html_block
|
| 22 |
+
from .lheading import lheading
|
| 23 |
+
from .list import list_block
|
| 24 |
+
from .paragraph import paragraph
|
| 25 |
+
from .reference import reference
|
| 26 |
+
from .state_block import StateBlock
|
| 27 |
+
from .table import table
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/blockquote.py
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Block quotes
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
from ..common.utils import isStrSpace
|
| 7 |
+
from .state_block import StateBlock
|
| 8 |
+
|
| 9 |
+
LOGGER = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 13 |
+
LOGGER.debug(
|
| 14 |
+
"entering blockquote: %s, %s, %s, %s", state, startLine, endLine, silent
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
oldLineMax = state.lineMax
|
| 18 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 19 |
+
max = state.eMarks[startLine]
|
| 20 |
+
|
| 21 |
+
if state.is_code_block(startLine):
|
| 22 |
+
return False
|
| 23 |
+
|
| 24 |
+
# check the block quote marker
|
| 25 |
+
try:
|
| 26 |
+
if state.src[pos] != ">":
|
| 27 |
+
return False
|
| 28 |
+
except IndexError:
|
| 29 |
+
return False
|
| 30 |
+
pos += 1
|
| 31 |
+
|
| 32 |
+
# we know that it's going to be a valid blockquote,
|
| 33 |
+
# so no point trying to find the end of it in silent mode
|
| 34 |
+
if silent:
|
| 35 |
+
return True
|
| 36 |
+
|
| 37 |
+
# set offset past spaces and ">"
|
| 38 |
+
initial = offset = state.sCount[startLine] + 1
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
second_char: str | None = state.src[pos]
|
| 42 |
+
except IndexError:
|
| 43 |
+
second_char = None
|
| 44 |
+
|
| 45 |
+
# skip one optional space after '>'
|
| 46 |
+
if second_char == " ":
|
| 47 |
+
# ' > test '
|
| 48 |
+
# ^ -- position start of line here:
|
| 49 |
+
pos += 1
|
| 50 |
+
initial += 1
|
| 51 |
+
offset += 1
|
| 52 |
+
adjustTab = False
|
| 53 |
+
spaceAfterMarker = True
|
| 54 |
+
elif second_char == "\t":
|
| 55 |
+
spaceAfterMarker = True
|
| 56 |
+
|
| 57 |
+
if (state.bsCount[startLine] + offset) % 4 == 3:
|
| 58 |
+
# ' >\t test '
|
| 59 |
+
# ^ -- position start of line here (tab has width==1)
|
| 60 |
+
pos += 1
|
| 61 |
+
initial += 1
|
| 62 |
+
offset += 1
|
| 63 |
+
adjustTab = False
|
| 64 |
+
else:
|
| 65 |
+
# ' >\t test '
|
| 66 |
+
# ^ -- position start of line here + shift bsCount slightly
|
| 67 |
+
# to make extra space appear
|
| 68 |
+
adjustTab = True
|
| 69 |
+
|
| 70 |
+
else:
|
| 71 |
+
spaceAfterMarker = False
|
| 72 |
+
|
| 73 |
+
oldBMarks = [state.bMarks[startLine]]
|
| 74 |
+
state.bMarks[startLine] = pos
|
| 75 |
+
|
| 76 |
+
while pos < max:
|
| 77 |
+
ch = state.src[pos]
|
| 78 |
+
|
| 79 |
+
if isStrSpace(ch):
|
| 80 |
+
if ch == "\t":
|
| 81 |
+
offset += (
|
| 82 |
+
4
|
| 83 |
+
- (offset + state.bsCount[startLine] + (1 if adjustTab else 0)) % 4
|
| 84 |
+
)
|
| 85 |
+
else:
|
| 86 |
+
offset += 1
|
| 87 |
+
|
| 88 |
+
else:
|
| 89 |
+
break
|
| 90 |
+
|
| 91 |
+
pos += 1
|
| 92 |
+
|
| 93 |
+
oldBSCount = [state.bsCount[startLine]]
|
| 94 |
+
state.bsCount[startLine] = (
|
| 95 |
+
state.sCount[startLine] + 1 + (1 if spaceAfterMarker else 0)
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
lastLineEmpty = pos >= max
|
| 99 |
+
|
| 100 |
+
oldSCount = [state.sCount[startLine]]
|
| 101 |
+
state.sCount[startLine] = offset - initial
|
| 102 |
+
|
| 103 |
+
oldTShift = [state.tShift[startLine]]
|
| 104 |
+
state.tShift[startLine] = pos - state.bMarks[startLine]
|
| 105 |
+
|
| 106 |
+
terminatorRules = state.md.block.ruler.getRules("blockquote")
|
| 107 |
+
|
| 108 |
+
oldParentType = state.parentType
|
| 109 |
+
state.parentType = "blockquote"
|
| 110 |
+
|
| 111 |
+
# Search the end of the block
|
| 112 |
+
#
|
| 113 |
+
# Block ends with either:
|
| 114 |
+
# 1. an empty line outside:
|
| 115 |
+
# ```
|
| 116 |
+
# > test
|
| 117 |
+
#
|
| 118 |
+
# ```
|
| 119 |
+
# 2. an empty line inside:
|
| 120 |
+
# ```
|
| 121 |
+
# >
|
| 122 |
+
# test
|
| 123 |
+
# ```
|
| 124 |
+
# 3. another tag:
|
| 125 |
+
# ```
|
| 126 |
+
# > test
|
| 127 |
+
# - - -
|
| 128 |
+
# ```
|
| 129 |
+
|
| 130 |
+
# for (nextLine = startLine + 1; nextLine < endLine; nextLine++) {
|
| 131 |
+
nextLine = startLine + 1
|
| 132 |
+
while nextLine < endLine:
|
| 133 |
+
# check if it's outdented, i.e. it's inside list item and indented
|
| 134 |
+
# less than said list item:
|
| 135 |
+
#
|
| 136 |
+
# ```
|
| 137 |
+
# 1. anything
|
| 138 |
+
# > current blockquote
|
| 139 |
+
# 2. checking this line
|
| 140 |
+
# ```
|
| 141 |
+
isOutdented = state.sCount[nextLine] < state.blkIndent
|
| 142 |
+
|
| 143 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 144 |
+
max = state.eMarks[nextLine]
|
| 145 |
+
|
| 146 |
+
if pos >= max:
|
| 147 |
+
# Case 1: line is not inside the blockquote, and this line is empty.
|
| 148 |
+
break
|
| 149 |
+
|
| 150 |
+
evaluatesTrue = state.src[pos] == ">" and not isOutdented
|
| 151 |
+
pos += 1
|
| 152 |
+
if evaluatesTrue:
|
| 153 |
+
# This line is inside the blockquote.
|
| 154 |
+
|
| 155 |
+
# set offset past spaces and ">"
|
| 156 |
+
initial = offset = state.sCount[nextLine] + 1
|
| 157 |
+
|
| 158 |
+
try:
|
| 159 |
+
next_char: str | None = state.src[pos]
|
| 160 |
+
except IndexError:
|
| 161 |
+
next_char = None
|
| 162 |
+
|
| 163 |
+
# skip one optional space after '>'
|
| 164 |
+
if next_char == " ":
|
| 165 |
+
# ' > test '
|
| 166 |
+
# ^ -- position start of line here:
|
| 167 |
+
pos += 1
|
| 168 |
+
initial += 1
|
| 169 |
+
offset += 1
|
| 170 |
+
adjustTab = False
|
| 171 |
+
spaceAfterMarker = True
|
| 172 |
+
elif next_char == "\t":
|
| 173 |
+
spaceAfterMarker = True
|
| 174 |
+
|
| 175 |
+
if (state.bsCount[nextLine] + offset) % 4 == 3:
|
| 176 |
+
# ' >\t test '
|
| 177 |
+
# ^ -- position start of line here (tab has width==1)
|
| 178 |
+
pos += 1
|
| 179 |
+
initial += 1
|
| 180 |
+
offset += 1
|
| 181 |
+
adjustTab = False
|
| 182 |
+
else:
|
| 183 |
+
# ' >\t test '
|
| 184 |
+
# ^ -- position start of line here + shift bsCount slightly
|
| 185 |
+
# to make extra space appear
|
| 186 |
+
adjustTab = True
|
| 187 |
+
|
| 188 |
+
else:
|
| 189 |
+
spaceAfterMarker = False
|
| 190 |
+
|
| 191 |
+
oldBMarks.append(state.bMarks[nextLine])
|
| 192 |
+
state.bMarks[nextLine] = pos
|
| 193 |
+
|
| 194 |
+
while pos < max:
|
| 195 |
+
ch = state.src[pos]
|
| 196 |
+
|
| 197 |
+
if isStrSpace(ch):
|
| 198 |
+
if ch == "\t":
|
| 199 |
+
offset += (
|
| 200 |
+
4
|
| 201 |
+
- (
|
| 202 |
+
offset
|
| 203 |
+
+ state.bsCount[nextLine]
|
| 204 |
+
+ (1 if adjustTab else 0)
|
| 205 |
+
)
|
| 206 |
+
% 4
|
| 207 |
+
)
|
| 208 |
+
else:
|
| 209 |
+
offset += 1
|
| 210 |
+
else:
|
| 211 |
+
break
|
| 212 |
+
|
| 213 |
+
pos += 1
|
| 214 |
+
|
| 215 |
+
lastLineEmpty = pos >= max
|
| 216 |
+
|
| 217 |
+
oldBSCount.append(state.bsCount[nextLine])
|
| 218 |
+
state.bsCount[nextLine] = (
|
| 219 |
+
state.sCount[nextLine] + 1 + (1 if spaceAfterMarker else 0)
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
oldSCount.append(state.sCount[nextLine])
|
| 223 |
+
state.sCount[nextLine] = offset - initial
|
| 224 |
+
|
| 225 |
+
oldTShift.append(state.tShift[nextLine])
|
| 226 |
+
state.tShift[nextLine] = pos - state.bMarks[nextLine]
|
| 227 |
+
|
| 228 |
+
nextLine += 1
|
| 229 |
+
continue
|
| 230 |
+
|
| 231 |
+
# Case 2: line is not inside the blockquote, and the last line was empty.
|
| 232 |
+
if lastLineEmpty:
|
| 233 |
+
break
|
| 234 |
+
|
| 235 |
+
# Case 3: another tag found.
|
| 236 |
+
terminate = False
|
| 237 |
+
|
| 238 |
+
for terminatorRule in terminatorRules:
|
| 239 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 240 |
+
terminate = True
|
| 241 |
+
break
|
| 242 |
+
|
| 243 |
+
if terminate:
|
| 244 |
+
# Quirk to enforce "hard termination mode" for paragraphs;
|
| 245 |
+
# normally if you call `tokenize(state, startLine, nextLine)`,
|
| 246 |
+
# paragraphs will look below nextLine for paragraph continuation,
|
| 247 |
+
# but if blockquote is terminated by another tag, they shouldn't
|
| 248 |
+
state.lineMax = nextLine
|
| 249 |
+
|
| 250 |
+
if state.blkIndent != 0:
|
| 251 |
+
# state.blkIndent was non-zero, we now set it to zero,
|
| 252 |
+
# so we need to re-calculate all offsets to appear as
|
| 253 |
+
# if indent wasn't changed
|
| 254 |
+
oldBMarks.append(state.bMarks[nextLine])
|
| 255 |
+
oldBSCount.append(state.bsCount[nextLine])
|
| 256 |
+
oldTShift.append(state.tShift[nextLine])
|
| 257 |
+
oldSCount.append(state.sCount[nextLine])
|
| 258 |
+
state.sCount[nextLine] -= state.blkIndent
|
| 259 |
+
|
| 260 |
+
break
|
| 261 |
+
|
| 262 |
+
oldBMarks.append(state.bMarks[nextLine])
|
| 263 |
+
oldBSCount.append(state.bsCount[nextLine])
|
| 264 |
+
oldTShift.append(state.tShift[nextLine])
|
| 265 |
+
oldSCount.append(state.sCount[nextLine])
|
| 266 |
+
|
| 267 |
+
# A negative indentation means that this is a paragraph continuation
|
| 268 |
+
#
|
| 269 |
+
state.sCount[nextLine] = -1
|
| 270 |
+
|
| 271 |
+
nextLine += 1
|
| 272 |
+
|
| 273 |
+
oldIndent = state.blkIndent
|
| 274 |
+
state.blkIndent = 0
|
| 275 |
+
|
| 276 |
+
token = state.push("blockquote_open", "blockquote", 1)
|
| 277 |
+
token.markup = ">"
|
| 278 |
+
token.map = lines = [startLine, 0]
|
| 279 |
+
|
| 280 |
+
state.md.block.tokenize(state, startLine, nextLine)
|
| 281 |
+
|
| 282 |
+
token = state.push("blockquote_close", "blockquote", -1)
|
| 283 |
+
token.markup = ">"
|
| 284 |
+
|
| 285 |
+
state.lineMax = oldLineMax
|
| 286 |
+
state.parentType = oldParentType
|
| 287 |
+
lines[1] = state.line
|
| 288 |
+
|
| 289 |
+
# Restore original tShift; this might not be necessary since the parser
|
| 290 |
+
# has already been here, but just to make sure we can do that.
|
| 291 |
+
for i, item in enumerate(oldTShift):
|
| 292 |
+
state.bMarks[i + startLine] = oldBMarks[i]
|
| 293 |
+
state.tShift[i + startLine] = item
|
| 294 |
+
state.sCount[i + startLine] = oldSCount[i]
|
| 295 |
+
state.bsCount[i + startLine] = oldBSCount[i]
|
| 296 |
+
|
| 297 |
+
state.blkIndent = oldIndent
|
| 298 |
+
|
| 299 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/code.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Code block (4 spaces padded)."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
from .state_block import StateBlock
|
| 6 |
+
|
| 7 |
+
LOGGER = logging.getLogger(__name__)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def code(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 11 |
+
LOGGER.debug("entering code: %s, %s, %s, %s", state, startLine, endLine, silent)
|
| 12 |
+
|
| 13 |
+
if not state.is_code_block(startLine):
|
| 14 |
+
return False
|
| 15 |
+
|
| 16 |
+
last = nextLine = startLine + 1
|
| 17 |
+
|
| 18 |
+
while nextLine < endLine:
|
| 19 |
+
if state.isEmpty(nextLine):
|
| 20 |
+
nextLine += 1
|
| 21 |
+
continue
|
| 22 |
+
|
| 23 |
+
if state.is_code_block(nextLine):
|
| 24 |
+
nextLine += 1
|
| 25 |
+
last = nextLine
|
| 26 |
+
continue
|
| 27 |
+
|
| 28 |
+
break
|
| 29 |
+
|
| 30 |
+
state.line = last
|
| 31 |
+
|
| 32 |
+
token = state.push("code_block", "code", 0)
|
| 33 |
+
token.content = state.getLines(startLine, last, 4 + state.blkIndent, False) + "\n"
|
| 34 |
+
token.map = [startLine, state.line]
|
| 35 |
+
|
| 36 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/fence.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# fences (``` lang, ~~~ lang)
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
from .state_block import StateBlock
|
| 5 |
+
|
| 6 |
+
LOGGER = logging.getLogger(__name__)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def fence(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 10 |
+
LOGGER.debug("entering fence: %s, %s, %s, %s", state, startLine, endLine, silent)
|
| 11 |
+
|
| 12 |
+
haveEndMarker = False
|
| 13 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 14 |
+
maximum = state.eMarks[startLine]
|
| 15 |
+
|
| 16 |
+
if state.is_code_block(startLine):
|
| 17 |
+
return False
|
| 18 |
+
|
| 19 |
+
if pos + 3 > maximum:
|
| 20 |
+
return False
|
| 21 |
+
|
| 22 |
+
marker = state.src[pos]
|
| 23 |
+
|
| 24 |
+
if marker not in ("~", "`"):
|
| 25 |
+
return False
|
| 26 |
+
|
| 27 |
+
# scan marker length
|
| 28 |
+
mem = pos
|
| 29 |
+
pos = state.skipCharsStr(pos, marker)
|
| 30 |
+
|
| 31 |
+
length = pos - mem
|
| 32 |
+
|
| 33 |
+
if length < 3:
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
markup = state.src[mem:pos]
|
| 37 |
+
params = state.src[pos:maximum]
|
| 38 |
+
|
| 39 |
+
if marker == "`" and marker in params:
|
| 40 |
+
return False
|
| 41 |
+
|
| 42 |
+
# Since start is found, we can report success here in validation mode
|
| 43 |
+
if silent:
|
| 44 |
+
return True
|
| 45 |
+
|
| 46 |
+
# search end of block
|
| 47 |
+
nextLine = startLine
|
| 48 |
+
|
| 49 |
+
while True:
|
| 50 |
+
nextLine += 1
|
| 51 |
+
if nextLine >= endLine:
|
| 52 |
+
# unclosed block should be autoclosed by end of document.
|
| 53 |
+
# also block seems to be autoclosed by end of parent
|
| 54 |
+
break
|
| 55 |
+
|
| 56 |
+
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 57 |
+
maximum = state.eMarks[nextLine]
|
| 58 |
+
|
| 59 |
+
if pos < maximum and state.sCount[nextLine] < state.blkIndent:
|
| 60 |
+
# non-empty line with negative indent should stop the list:
|
| 61 |
+
# - ```
|
| 62 |
+
# test
|
| 63 |
+
break
|
| 64 |
+
|
| 65 |
+
try:
|
| 66 |
+
if state.src[pos] != marker:
|
| 67 |
+
continue
|
| 68 |
+
except IndexError:
|
| 69 |
+
break
|
| 70 |
+
|
| 71 |
+
if state.is_code_block(nextLine):
|
| 72 |
+
continue
|
| 73 |
+
|
| 74 |
+
pos = state.skipCharsStr(pos, marker)
|
| 75 |
+
|
| 76 |
+
# closing code fence must be at least as long as the opening one
|
| 77 |
+
if pos - mem < length:
|
| 78 |
+
continue
|
| 79 |
+
|
| 80 |
+
# make sure tail has spaces only
|
| 81 |
+
pos = state.skipSpaces(pos)
|
| 82 |
+
|
| 83 |
+
if pos < maximum:
|
| 84 |
+
continue
|
| 85 |
+
|
| 86 |
+
haveEndMarker = True
|
| 87 |
+
# found!
|
| 88 |
+
break
|
| 89 |
+
|
| 90 |
+
# If a fence has heading spaces, they should be removed from its inner block
|
| 91 |
+
length = state.sCount[startLine]
|
| 92 |
+
|
| 93 |
+
state.line = nextLine + (1 if haveEndMarker else 0)
|
| 94 |
+
|
| 95 |
+
token = state.push("fence", "code", 0)
|
| 96 |
+
token.info = params
|
| 97 |
+
token.content = state.getLines(startLine + 1, nextLine, length, True)
|
| 98 |
+
token.markup = markup
|
| 99 |
+
token.map = [startLine, state.line]
|
| 100 |
+
|
| 101 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/heading.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Atex heading (#, ##, ...)"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
from ..common.utils import isStrSpace
|
| 8 |
+
from .state_block import StateBlock
|
| 9 |
+
|
| 10 |
+
LOGGER = logging.getLogger(__name__)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def heading(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 14 |
+
LOGGER.debug("entering heading: %s, %s, %s, %s", state, startLine, endLine, silent)
|
| 15 |
+
|
| 16 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 17 |
+
maximum = state.eMarks[startLine]
|
| 18 |
+
|
| 19 |
+
if state.is_code_block(startLine):
|
| 20 |
+
return False
|
| 21 |
+
|
| 22 |
+
ch: str | None = state.src[pos]
|
| 23 |
+
|
| 24 |
+
if ch != "#" or pos >= maximum:
|
| 25 |
+
return False
|
| 26 |
+
|
| 27 |
+
# count heading level
|
| 28 |
+
level = 1
|
| 29 |
+
pos += 1
|
| 30 |
+
try:
|
| 31 |
+
ch = state.src[pos]
|
| 32 |
+
except IndexError:
|
| 33 |
+
ch = None
|
| 34 |
+
while ch == "#" and pos < maximum and level <= 6:
|
| 35 |
+
level += 1
|
| 36 |
+
pos += 1
|
| 37 |
+
try:
|
| 38 |
+
ch = state.src[pos]
|
| 39 |
+
except IndexError:
|
| 40 |
+
ch = None
|
| 41 |
+
|
| 42 |
+
if level > 6 or (pos < maximum and not isStrSpace(ch)):
|
| 43 |
+
return False
|
| 44 |
+
|
| 45 |
+
if silent:
|
| 46 |
+
return True
|
| 47 |
+
|
| 48 |
+
# Let's cut tails like ' ### ' from the end of string
|
| 49 |
+
|
| 50 |
+
maximum = state.skipSpacesBack(maximum, pos)
|
| 51 |
+
tmp = state.skipCharsStrBack(maximum, "#", pos)
|
| 52 |
+
if tmp > pos and isStrSpace(state.src[tmp - 1]):
|
| 53 |
+
maximum = tmp
|
| 54 |
+
|
| 55 |
+
state.line = startLine + 1
|
| 56 |
+
|
| 57 |
+
token = state.push("heading_open", "h" + str(level), 1)
|
| 58 |
+
token.markup = "########"[:level]
|
| 59 |
+
token.map = [startLine, state.line]
|
| 60 |
+
|
| 61 |
+
token = state.push("inline", "", 0)
|
| 62 |
+
token.content = state.src[pos:maximum].strip()
|
| 63 |
+
token.map = [startLine, state.line]
|
| 64 |
+
token.children = []
|
| 65 |
+
|
| 66 |
+
token = state.push("heading_close", "h" + str(level), -1)
|
| 67 |
+
token.markup = "########"[:level]
|
| 68 |
+
|
| 69 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/hr.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Horizontal rule
|
| 2 |
+
|
| 3 |
+
At least 3 of these characters on a line * - _
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import logging
|
| 7 |
+
|
| 8 |
+
from ..common.utils import isStrSpace
|
| 9 |
+
from .state_block import StateBlock
|
| 10 |
+
|
| 11 |
+
LOGGER = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def hr(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 15 |
+
LOGGER.debug("entering hr: %s, %s, %s, %s", state, startLine, endLine, silent)
|
| 16 |
+
|
| 17 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 18 |
+
maximum = state.eMarks[startLine]
|
| 19 |
+
|
| 20 |
+
if state.is_code_block(startLine):
|
| 21 |
+
return False
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
marker = state.src[pos]
|
| 25 |
+
except IndexError:
|
| 26 |
+
return False
|
| 27 |
+
pos += 1
|
| 28 |
+
|
| 29 |
+
# Check hr marker
|
| 30 |
+
if marker not in ("*", "-", "_"):
|
| 31 |
+
return False
|
| 32 |
+
|
| 33 |
+
# markers can be mixed with spaces, but there should be at least 3 of them
|
| 34 |
+
|
| 35 |
+
cnt = 1
|
| 36 |
+
while pos < maximum:
|
| 37 |
+
ch = state.src[pos]
|
| 38 |
+
pos += 1
|
| 39 |
+
if ch != marker and not isStrSpace(ch):
|
| 40 |
+
return False
|
| 41 |
+
if ch == marker:
|
| 42 |
+
cnt += 1
|
| 43 |
+
|
| 44 |
+
if cnt < 3:
|
| 45 |
+
return False
|
| 46 |
+
|
| 47 |
+
if silent:
|
| 48 |
+
return True
|
| 49 |
+
|
| 50 |
+
state.line = startLine + 1
|
| 51 |
+
|
| 52 |
+
token = state.push("hr", "hr", 0)
|
| 53 |
+
token.map = [startLine, state.line]
|
| 54 |
+
token.markup = marker * (cnt + 1)
|
| 55 |
+
|
| 56 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/html_block.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HTML block
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
import re
|
| 6 |
+
|
| 7 |
+
from ..common.html_blocks import block_names
|
| 8 |
+
from ..common.html_re import HTML_OPEN_CLOSE_TAG_STR
|
| 9 |
+
from .state_block import StateBlock
|
| 10 |
+
|
| 11 |
+
LOGGER = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
# An array of opening and corresponding closing sequences for html tags,
|
| 14 |
+
# last argument defines whether it can terminate a paragraph or not
|
| 15 |
+
HTML_SEQUENCES: list[tuple[re.Pattern[str], re.Pattern[str], bool]] = [
|
| 16 |
+
(
|
| 17 |
+
re.compile(r"^<(script|pre|style|textarea)(?=(\s|>|$))", re.IGNORECASE),
|
| 18 |
+
re.compile(r"<\/(script|pre|style|textarea)>", re.IGNORECASE),
|
| 19 |
+
True,
|
| 20 |
+
),
|
| 21 |
+
(re.compile(r"^<!--"), re.compile(r"-->"), True),
|
| 22 |
+
(re.compile(r"^<\?"), re.compile(r"\?>"), True),
|
| 23 |
+
(re.compile(r"^<![A-Z]"), re.compile(r">"), True),
|
| 24 |
+
(re.compile(r"^<!\[CDATA\["), re.compile(r"\]\]>"), True),
|
| 25 |
+
(
|
| 26 |
+
re.compile("^</?(" + "|".join(block_names) + ")(?=(\\s|/?>|$))", re.IGNORECASE),
|
| 27 |
+
re.compile(r"^$"),
|
| 28 |
+
True,
|
| 29 |
+
),
|
| 30 |
+
(re.compile(HTML_OPEN_CLOSE_TAG_STR + "\\s*$"), re.compile(r"^$"), False),
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def html_block(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 35 |
+
LOGGER.debug(
|
| 36 |
+
"entering html_block: %s, %s, %s, %s", state, startLine, endLine, silent
|
| 37 |
+
)
|
| 38 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 39 |
+
maximum = state.eMarks[startLine]
|
| 40 |
+
|
| 41 |
+
if state.is_code_block(startLine):
|
| 42 |
+
return False
|
| 43 |
+
|
| 44 |
+
if not state.md.options.get("html", None):
|
| 45 |
+
return False
|
| 46 |
+
|
| 47 |
+
if state.src[pos] != "<":
|
| 48 |
+
return False
|
| 49 |
+
|
| 50 |
+
lineText = state.src[pos:maximum]
|
| 51 |
+
|
| 52 |
+
html_seq = None
|
| 53 |
+
for HTML_SEQUENCE in HTML_SEQUENCES:
|
| 54 |
+
if HTML_SEQUENCE[0].search(lineText):
|
| 55 |
+
html_seq = HTML_SEQUENCE
|
| 56 |
+
break
|
| 57 |
+
|
| 58 |
+
if not html_seq:
|
| 59 |
+
return False
|
| 60 |
+
|
| 61 |
+
if silent:
|
| 62 |
+
# true if this sequence can be a terminator, false otherwise
|
| 63 |
+
return html_seq[2]
|
| 64 |
+
|
| 65 |
+
nextLine = startLine + 1
|
| 66 |
+
|
| 67 |
+
# If we are here - we detected HTML block.
|
| 68 |
+
# Let's roll down till block end.
|
| 69 |
+
if not html_seq[1].search(lineText):
|
| 70 |
+
while nextLine < endLine:
|
| 71 |
+
if state.sCount[nextLine] < state.blkIndent:
|
| 72 |
+
break
|
| 73 |
+
|
| 74 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 75 |
+
maximum = state.eMarks[nextLine]
|
| 76 |
+
lineText = state.src[pos:maximum]
|
| 77 |
+
|
| 78 |
+
if html_seq[1].search(lineText):
|
| 79 |
+
if len(lineText) != 0:
|
| 80 |
+
nextLine += 1
|
| 81 |
+
break
|
| 82 |
+
nextLine += 1
|
| 83 |
+
|
| 84 |
+
state.line = nextLine
|
| 85 |
+
|
| 86 |
+
token = state.push("html_block", "", 0)
|
| 87 |
+
token.map = [startLine, nextLine]
|
| 88 |
+
token.content = state.getLines(startLine, nextLine, state.blkIndent, True)
|
| 89 |
+
|
| 90 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/lheading.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# lheading (---, ==)
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
from .state_block import StateBlock
|
| 5 |
+
|
| 6 |
+
LOGGER = logging.getLogger(__name__)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def lheading(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 10 |
+
LOGGER.debug("entering lheading: %s, %s, %s, %s", state, startLine, endLine, silent)
|
| 11 |
+
|
| 12 |
+
level = None
|
| 13 |
+
nextLine = startLine + 1
|
| 14 |
+
ruler = state.md.block.ruler
|
| 15 |
+
terminatorRules = ruler.getRules("paragraph")
|
| 16 |
+
|
| 17 |
+
if state.is_code_block(startLine):
|
| 18 |
+
return False
|
| 19 |
+
|
| 20 |
+
oldParentType = state.parentType
|
| 21 |
+
state.parentType = "paragraph" # use paragraph to match terminatorRules
|
| 22 |
+
|
| 23 |
+
# jump line-by-line until empty one or EOF
|
| 24 |
+
while nextLine < endLine and not state.isEmpty(nextLine):
|
| 25 |
+
# this would be a code block normally, but after paragraph
|
| 26 |
+
# it's considered a lazy continuation regardless of what's there
|
| 27 |
+
if state.sCount[nextLine] - state.blkIndent > 3:
|
| 28 |
+
nextLine += 1
|
| 29 |
+
continue
|
| 30 |
+
|
| 31 |
+
# Check for underline in setext header
|
| 32 |
+
if state.sCount[nextLine] >= state.blkIndent:
|
| 33 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 34 |
+
maximum = state.eMarks[nextLine]
|
| 35 |
+
|
| 36 |
+
if pos < maximum:
|
| 37 |
+
marker = state.src[pos]
|
| 38 |
+
|
| 39 |
+
if marker in ("-", "="):
|
| 40 |
+
pos = state.skipCharsStr(pos, marker)
|
| 41 |
+
pos = state.skipSpaces(pos)
|
| 42 |
+
|
| 43 |
+
# /* = */
|
| 44 |
+
if pos >= maximum:
|
| 45 |
+
level = 1 if marker == "=" else 2
|
| 46 |
+
break
|
| 47 |
+
|
| 48 |
+
# quirk for blockquotes, this line should already be checked by that rule
|
| 49 |
+
if state.sCount[nextLine] < 0:
|
| 50 |
+
nextLine += 1
|
| 51 |
+
continue
|
| 52 |
+
|
| 53 |
+
# Some tags can terminate paragraph without empty line.
|
| 54 |
+
terminate = False
|
| 55 |
+
for terminatorRule in terminatorRules:
|
| 56 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 57 |
+
terminate = True
|
| 58 |
+
break
|
| 59 |
+
if terminate:
|
| 60 |
+
break
|
| 61 |
+
|
| 62 |
+
nextLine += 1
|
| 63 |
+
|
| 64 |
+
if not level:
|
| 65 |
+
# Didn't find valid underline
|
| 66 |
+
return False
|
| 67 |
+
|
| 68 |
+
content = state.getLines(startLine, nextLine, state.blkIndent, False).strip()
|
| 69 |
+
|
| 70 |
+
state.line = nextLine + 1
|
| 71 |
+
|
| 72 |
+
token = state.push("heading_open", "h" + str(level), 1)
|
| 73 |
+
token.markup = marker
|
| 74 |
+
token.map = [startLine, state.line]
|
| 75 |
+
|
| 76 |
+
token = state.push("inline", "", 0)
|
| 77 |
+
token.content = content
|
| 78 |
+
token.map = [startLine, state.line - 1]
|
| 79 |
+
token.children = []
|
| 80 |
+
|
| 81 |
+
token = state.push("heading_close", "h" + str(level), -1)
|
| 82 |
+
token.markup = marker
|
| 83 |
+
|
| 84 |
+
state.parentType = oldParentType
|
| 85 |
+
|
| 86 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/list.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Lists
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
from ..common.utils import isStrSpace
|
| 5 |
+
from .state_block import StateBlock
|
| 6 |
+
|
| 7 |
+
LOGGER = logging.getLogger(__name__)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# Search `[-+*][\n ]`, returns next pos after marker on success
|
| 11 |
+
# or -1 on fail.
|
| 12 |
+
def skipBulletListMarker(state: StateBlock, startLine: int) -> int:
|
| 13 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 14 |
+
maximum = state.eMarks[startLine]
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
marker = state.src[pos]
|
| 18 |
+
except IndexError:
|
| 19 |
+
return -1
|
| 20 |
+
pos += 1
|
| 21 |
+
|
| 22 |
+
if marker not in ("*", "-", "+"):
|
| 23 |
+
return -1
|
| 24 |
+
|
| 25 |
+
if pos < maximum:
|
| 26 |
+
ch = state.src[pos]
|
| 27 |
+
|
| 28 |
+
if not isStrSpace(ch):
|
| 29 |
+
# " -test " - is not a list item
|
| 30 |
+
return -1
|
| 31 |
+
|
| 32 |
+
return pos
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Search `\d+[.)][\n ]`, returns next pos after marker on success
|
| 36 |
+
# or -1 on fail.
|
| 37 |
+
def skipOrderedListMarker(state: StateBlock, startLine: int) -> int:
|
| 38 |
+
start = state.bMarks[startLine] + state.tShift[startLine]
|
| 39 |
+
pos = start
|
| 40 |
+
maximum = state.eMarks[startLine]
|
| 41 |
+
|
| 42 |
+
# List marker should have at least 2 chars (digit + dot)
|
| 43 |
+
if pos + 1 >= maximum:
|
| 44 |
+
return -1
|
| 45 |
+
|
| 46 |
+
ch = state.src[pos]
|
| 47 |
+
pos += 1
|
| 48 |
+
|
| 49 |
+
ch_ord = ord(ch)
|
| 50 |
+
# /* 0 */ /* 9 */
|
| 51 |
+
if ch_ord < 0x30 or ch_ord > 0x39:
|
| 52 |
+
return -1
|
| 53 |
+
|
| 54 |
+
while True:
|
| 55 |
+
# EOL -> fail
|
| 56 |
+
if pos >= maximum:
|
| 57 |
+
return -1
|
| 58 |
+
|
| 59 |
+
ch = state.src[pos]
|
| 60 |
+
pos += 1
|
| 61 |
+
|
| 62 |
+
# /* 0 */ /* 9 */
|
| 63 |
+
ch_ord = ord(ch)
|
| 64 |
+
if ch_ord >= 0x30 and ch_ord <= 0x39:
|
| 65 |
+
# List marker should have no more than 9 digits
|
| 66 |
+
# (prevents integer overflow in browsers)
|
| 67 |
+
if pos - start >= 10:
|
| 68 |
+
return -1
|
| 69 |
+
|
| 70 |
+
continue
|
| 71 |
+
|
| 72 |
+
# found valid marker
|
| 73 |
+
if ch in (")", "."):
|
| 74 |
+
break
|
| 75 |
+
|
| 76 |
+
return -1
|
| 77 |
+
|
| 78 |
+
if pos < maximum:
|
| 79 |
+
ch = state.src[pos]
|
| 80 |
+
|
| 81 |
+
if not isStrSpace(ch):
|
| 82 |
+
# " 1.test " - is not a list item
|
| 83 |
+
return -1
|
| 84 |
+
|
| 85 |
+
return pos
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def markTightParagraphs(state: StateBlock, idx: int) -> None:
|
| 89 |
+
level = state.level + 2
|
| 90 |
+
|
| 91 |
+
i = idx + 2
|
| 92 |
+
length = len(state.tokens) - 2
|
| 93 |
+
while i < length:
|
| 94 |
+
if state.tokens[i].level == level and state.tokens[i].type == "paragraph_open":
|
| 95 |
+
state.tokens[i + 2].hidden = True
|
| 96 |
+
state.tokens[i].hidden = True
|
| 97 |
+
i += 2
|
| 98 |
+
i += 1
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def list_block(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 102 |
+
LOGGER.debug("entering list: %s, %s, %s, %s", state, startLine, endLine, silent)
|
| 103 |
+
|
| 104 |
+
isTerminatingParagraph = False
|
| 105 |
+
tight = True
|
| 106 |
+
|
| 107 |
+
if state.is_code_block(startLine):
|
| 108 |
+
return False
|
| 109 |
+
|
| 110 |
+
# Special case:
|
| 111 |
+
# - item 1
|
| 112 |
+
# - item 2
|
| 113 |
+
# - item 3
|
| 114 |
+
# - item 4
|
| 115 |
+
# - this one is a paragraph continuation
|
| 116 |
+
if (
|
| 117 |
+
state.listIndent >= 0
|
| 118 |
+
and state.sCount[startLine] - state.listIndent >= 4
|
| 119 |
+
and state.sCount[startLine] < state.blkIndent
|
| 120 |
+
):
|
| 121 |
+
return False
|
| 122 |
+
|
| 123 |
+
# limit conditions when list can interrupt
|
| 124 |
+
# a paragraph (validation mode only)
|
| 125 |
+
# Next list item should still terminate previous list item
|
| 126 |
+
#
|
| 127 |
+
# This code can fail if plugins use blkIndent as well as lists,
|
| 128 |
+
# but I hope the spec gets fixed long before that happens.
|
| 129 |
+
#
|
| 130 |
+
if (
|
| 131 |
+
silent
|
| 132 |
+
and state.parentType == "paragraph"
|
| 133 |
+
and state.sCount[startLine] >= state.blkIndent
|
| 134 |
+
):
|
| 135 |
+
isTerminatingParagraph = True
|
| 136 |
+
|
| 137 |
+
# Detect list type and position after marker
|
| 138 |
+
posAfterMarker = skipOrderedListMarker(state, startLine)
|
| 139 |
+
if posAfterMarker >= 0:
|
| 140 |
+
isOrdered = True
|
| 141 |
+
start = state.bMarks[startLine] + state.tShift[startLine]
|
| 142 |
+
markerValue = int(state.src[start : posAfterMarker - 1])
|
| 143 |
+
|
| 144 |
+
# If we're starting a new ordered list right after
|
| 145 |
+
# a paragraph, it should start with 1.
|
| 146 |
+
if isTerminatingParagraph and markerValue != 1:
|
| 147 |
+
return False
|
| 148 |
+
else:
|
| 149 |
+
posAfterMarker = skipBulletListMarker(state, startLine)
|
| 150 |
+
if posAfterMarker >= 0:
|
| 151 |
+
isOrdered = False
|
| 152 |
+
else:
|
| 153 |
+
return False
|
| 154 |
+
|
| 155 |
+
# If we're starting a new unordered list right after
|
| 156 |
+
# a paragraph, first line should not be empty.
|
| 157 |
+
if (
|
| 158 |
+
isTerminatingParagraph
|
| 159 |
+
and state.skipSpaces(posAfterMarker) >= state.eMarks[startLine]
|
| 160 |
+
):
|
| 161 |
+
return False
|
| 162 |
+
|
| 163 |
+
# We should terminate list on style change. Remember first one to compare.
|
| 164 |
+
markerChar = state.src[posAfterMarker - 1]
|
| 165 |
+
|
| 166 |
+
# For validation mode we can terminate immediately
|
| 167 |
+
if silent:
|
| 168 |
+
return True
|
| 169 |
+
|
| 170 |
+
# Start list
|
| 171 |
+
listTokIdx = len(state.tokens)
|
| 172 |
+
|
| 173 |
+
if isOrdered:
|
| 174 |
+
token = state.push("ordered_list_open", "ol", 1)
|
| 175 |
+
if markerValue != 1:
|
| 176 |
+
token.attrs = {"start": markerValue}
|
| 177 |
+
|
| 178 |
+
else:
|
| 179 |
+
token = state.push("bullet_list_open", "ul", 1)
|
| 180 |
+
|
| 181 |
+
token.map = listLines = [startLine, 0]
|
| 182 |
+
token.markup = markerChar
|
| 183 |
+
|
| 184 |
+
#
|
| 185 |
+
# Iterate list items
|
| 186 |
+
#
|
| 187 |
+
|
| 188 |
+
nextLine = startLine
|
| 189 |
+
prevEmptyEnd = False
|
| 190 |
+
terminatorRules = state.md.block.ruler.getRules("list")
|
| 191 |
+
|
| 192 |
+
oldParentType = state.parentType
|
| 193 |
+
state.parentType = "list"
|
| 194 |
+
|
| 195 |
+
while nextLine < endLine:
|
| 196 |
+
pos = posAfterMarker
|
| 197 |
+
maximum = state.eMarks[nextLine]
|
| 198 |
+
|
| 199 |
+
initial = offset = (
|
| 200 |
+
state.sCount[nextLine]
|
| 201 |
+
+ posAfterMarker
|
| 202 |
+
- (state.bMarks[startLine] + state.tShift[startLine])
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
while pos < maximum:
|
| 206 |
+
ch = state.src[pos]
|
| 207 |
+
|
| 208 |
+
if ch == "\t":
|
| 209 |
+
offset += 4 - (offset + state.bsCount[nextLine]) % 4
|
| 210 |
+
elif ch == " ":
|
| 211 |
+
offset += 1
|
| 212 |
+
else:
|
| 213 |
+
break
|
| 214 |
+
|
| 215 |
+
pos += 1
|
| 216 |
+
|
| 217 |
+
contentStart = pos
|
| 218 |
+
|
| 219 |
+
# trimming space in "- \n 3" case, indent is 1 here
|
| 220 |
+
indentAfterMarker = 1 if contentStart >= maximum else offset - initial
|
| 221 |
+
|
| 222 |
+
# If we have more than 4 spaces, the indent is 1
|
| 223 |
+
# (the rest is just indented code block)
|
| 224 |
+
if indentAfterMarker > 4:
|
| 225 |
+
indentAfterMarker = 1
|
| 226 |
+
|
| 227 |
+
# " - test"
|
| 228 |
+
# ^^^^^ - calculating total length of this thing
|
| 229 |
+
indent = initial + indentAfterMarker
|
| 230 |
+
|
| 231 |
+
# Run subparser & write tokens
|
| 232 |
+
token = state.push("list_item_open", "li", 1)
|
| 233 |
+
token.markup = markerChar
|
| 234 |
+
token.map = itemLines = [startLine, 0]
|
| 235 |
+
if isOrdered:
|
| 236 |
+
token.info = state.src[start : posAfterMarker - 1]
|
| 237 |
+
|
| 238 |
+
# change current state, then restore it after parser subcall
|
| 239 |
+
oldTight = state.tight
|
| 240 |
+
oldTShift = state.tShift[startLine]
|
| 241 |
+
oldSCount = state.sCount[startLine]
|
| 242 |
+
|
| 243 |
+
# - example list
|
| 244 |
+
# ^ listIndent position will be here
|
| 245 |
+
# ^ blkIndent position will be here
|
| 246 |
+
#
|
| 247 |
+
oldListIndent = state.listIndent
|
| 248 |
+
state.listIndent = state.blkIndent
|
| 249 |
+
state.blkIndent = indent
|
| 250 |
+
|
| 251 |
+
state.tight = True
|
| 252 |
+
state.tShift[startLine] = contentStart - state.bMarks[startLine]
|
| 253 |
+
state.sCount[startLine] = offset
|
| 254 |
+
|
| 255 |
+
if contentStart >= maximum and state.isEmpty(startLine + 1):
|
| 256 |
+
# workaround for this case
|
| 257 |
+
# (list item is empty, list terminates before "foo"):
|
| 258 |
+
# ~~~~~~~~
|
| 259 |
+
# -
|
| 260 |
+
#
|
| 261 |
+
# foo
|
| 262 |
+
# ~~~~~~~~
|
| 263 |
+
state.line = min(state.line + 2, endLine)
|
| 264 |
+
else:
|
| 265 |
+
# NOTE in list.js this was:
|
| 266 |
+
# state.md.block.tokenize(state, startLine, endLine, True)
|
| 267 |
+
# but tokeniz does not take the final parameter
|
| 268 |
+
state.md.block.tokenize(state, startLine, endLine)
|
| 269 |
+
|
| 270 |
+
# If any of list item is tight, mark list as tight
|
| 271 |
+
if (not state.tight) or prevEmptyEnd:
|
| 272 |
+
tight = False
|
| 273 |
+
|
| 274 |
+
# Item become loose if finish with empty line,
|
| 275 |
+
# but we should filter last element, because it means list finish
|
| 276 |
+
prevEmptyEnd = (state.line - startLine) > 1 and state.isEmpty(state.line - 1)
|
| 277 |
+
|
| 278 |
+
state.blkIndent = state.listIndent
|
| 279 |
+
state.listIndent = oldListIndent
|
| 280 |
+
state.tShift[startLine] = oldTShift
|
| 281 |
+
state.sCount[startLine] = oldSCount
|
| 282 |
+
state.tight = oldTight
|
| 283 |
+
|
| 284 |
+
token = state.push("list_item_close", "li", -1)
|
| 285 |
+
token.markup = markerChar
|
| 286 |
+
|
| 287 |
+
nextLine = startLine = state.line
|
| 288 |
+
itemLines[1] = nextLine
|
| 289 |
+
|
| 290 |
+
if nextLine >= endLine:
|
| 291 |
+
break
|
| 292 |
+
|
| 293 |
+
contentStart = state.bMarks[startLine]
|
| 294 |
+
|
| 295 |
+
#
|
| 296 |
+
# Try to check if list is terminated or continued.
|
| 297 |
+
#
|
| 298 |
+
if state.sCount[nextLine] < state.blkIndent:
|
| 299 |
+
break
|
| 300 |
+
|
| 301 |
+
if state.is_code_block(startLine):
|
| 302 |
+
break
|
| 303 |
+
|
| 304 |
+
# fail if terminating block found
|
| 305 |
+
terminate = False
|
| 306 |
+
for terminatorRule in terminatorRules:
|
| 307 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 308 |
+
terminate = True
|
| 309 |
+
break
|
| 310 |
+
|
| 311 |
+
if terminate:
|
| 312 |
+
break
|
| 313 |
+
|
| 314 |
+
# fail if list has another type
|
| 315 |
+
if isOrdered:
|
| 316 |
+
posAfterMarker = skipOrderedListMarker(state, nextLine)
|
| 317 |
+
if posAfterMarker < 0:
|
| 318 |
+
break
|
| 319 |
+
start = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 320 |
+
else:
|
| 321 |
+
posAfterMarker = skipBulletListMarker(state, nextLine)
|
| 322 |
+
if posAfterMarker < 0:
|
| 323 |
+
break
|
| 324 |
+
|
| 325 |
+
if markerChar != state.src[posAfterMarker - 1]:
|
| 326 |
+
break
|
| 327 |
+
|
| 328 |
+
# Finalize list
|
| 329 |
+
if isOrdered:
|
| 330 |
+
token = state.push("ordered_list_close", "ol", -1)
|
| 331 |
+
else:
|
| 332 |
+
token = state.push("bullet_list_close", "ul", -1)
|
| 333 |
+
|
| 334 |
+
token.markup = markerChar
|
| 335 |
+
|
| 336 |
+
listLines[1] = nextLine
|
| 337 |
+
state.line = nextLine
|
| 338 |
+
|
| 339 |
+
state.parentType = oldParentType
|
| 340 |
+
|
| 341 |
+
# mark paragraphs tight if needed
|
| 342 |
+
if tight:
|
| 343 |
+
markTightParagraphs(state, listTokIdx)
|
| 344 |
+
|
| 345 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/paragraph.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Paragraph."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
from .state_block import StateBlock
|
| 6 |
+
|
| 7 |
+
LOGGER = logging.getLogger(__name__)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def paragraph(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 11 |
+
LOGGER.debug(
|
| 12 |
+
"entering paragraph: %s, %s, %s, %s", state, startLine, endLine, silent
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
nextLine = startLine + 1
|
| 16 |
+
ruler = state.md.block.ruler
|
| 17 |
+
terminatorRules = ruler.getRules("paragraph")
|
| 18 |
+
endLine = state.lineMax
|
| 19 |
+
|
| 20 |
+
oldParentType = state.parentType
|
| 21 |
+
state.parentType = "paragraph"
|
| 22 |
+
|
| 23 |
+
# jump line-by-line until empty one or EOF
|
| 24 |
+
while nextLine < endLine:
|
| 25 |
+
if state.isEmpty(nextLine):
|
| 26 |
+
break
|
| 27 |
+
# this would be a code block normally, but after paragraph
|
| 28 |
+
# it's considered a lazy continuation regardless of what's there
|
| 29 |
+
if state.sCount[nextLine] - state.blkIndent > 3:
|
| 30 |
+
nextLine += 1
|
| 31 |
+
continue
|
| 32 |
+
|
| 33 |
+
# quirk for blockquotes, this line should already be checked by that rule
|
| 34 |
+
if state.sCount[nextLine] < 0:
|
| 35 |
+
nextLine += 1
|
| 36 |
+
continue
|
| 37 |
+
|
| 38 |
+
# Some tags can terminate paragraph without empty line.
|
| 39 |
+
terminate = False
|
| 40 |
+
for terminatorRule in terminatorRules:
|
| 41 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 42 |
+
terminate = True
|
| 43 |
+
break
|
| 44 |
+
|
| 45 |
+
if terminate:
|
| 46 |
+
break
|
| 47 |
+
|
| 48 |
+
nextLine += 1
|
| 49 |
+
|
| 50 |
+
content = state.getLines(startLine, nextLine, state.blkIndent, False).strip()
|
| 51 |
+
|
| 52 |
+
state.line = nextLine
|
| 53 |
+
|
| 54 |
+
token = state.push("paragraph_open", "p", 1)
|
| 55 |
+
token.map = [startLine, state.line]
|
| 56 |
+
|
| 57 |
+
token = state.push("inline", "", 0)
|
| 58 |
+
token.content = content
|
| 59 |
+
token.map = [startLine, state.line]
|
| 60 |
+
token.children = []
|
| 61 |
+
|
| 62 |
+
token = state.push("paragraph_close", "p", -1)
|
| 63 |
+
|
| 64 |
+
state.parentType = oldParentType
|
| 65 |
+
|
| 66 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/reference.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
+
from ..common.utils import charCodeAt, isSpace, normalizeReference
|
| 4 |
+
from .state_block import StateBlock
|
| 5 |
+
|
| 6 |
+
LOGGER = logging.getLogger(__name__)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def reference(state: StateBlock, startLine: int, _endLine: int, silent: bool) -> bool:
|
| 10 |
+
LOGGER.debug(
|
| 11 |
+
"entering reference: %s, %s, %s, %s", state, startLine, _endLine, silent
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 15 |
+
maximum = state.eMarks[startLine]
|
| 16 |
+
nextLine = startLine + 1
|
| 17 |
+
|
| 18 |
+
if state.is_code_block(startLine):
|
| 19 |
+
return False
|
| 20 |
+
|
| 21 |
+
if state.src[pos] != "[":
|
| 22 |
+
return False
|
| 23 |
+
|
| 24 |
+
string = state.src[pos : maximum + 1]
|
| 25 |
+
|
| 26 |
+
# string = state.getLines(startLine, nextLine, state.blkIndent, False).strip()
|
| 27 |
+
maximum = len(string)
|
| 28 |
+
|
| 29 |
+
labelEnd = None
|
| 30 |
+
pos = 1
|
| 31 |
+
while pos < maximum:
|
| 32 |
+
ch = charCodeAt(string, pos)
|
| 33 |
+
if ch == 0x5B: # /* [ */
|
| 34 |
+
return False
|
| 35 |
+
elif ch == 0x5D: # /* ] */
|
| 36 |
+
labelEnd = pos
|
| 37 |
+
break
|
| 38 |
+
elif ch == 0x0A: # /* \n */
|
| 39 |
+
if (lineContent := getNextLine(state, nextLine)) is not None:
|
| 40 |
+
string += lineContent
|
| 41 |
+
maximum = len(string)
|
| 42 |
+
nextLine += 1
|
| 43 |
+
elif ch == 0x5C: # /* \ */
|
| 44 |
+
pos += 1
|
| 45 |
+
if (
|
| 46 |
+
pos < maximum
|
| 47 |
+
and charCodeAt(string, pos) == 0x0A
|
| 48 |
+
and (lineContent := getNextLine(state, nextLine)) is not None
|
| 49 |
+
):
|
| 50 |
+
string += lineContent
|
| 51 |
+
maximum = len(string)
|
| 52 |
+
nextLine += 1
|
| 53 |
+
pos += 1
|
| 54 |
+
|
| 55 |
+
if (
|
| 56 |
+
labelEnd is None or labelEnd < 0 or charCodeAt(string, labelEnd + 1) != 0x3A
|
| 57 |
+
): # /* : */
|
| 58 |
+
return False
|
| 59 |
+
|
| 60 |
+
# [label]: destination 'title'
|
| 61 |
+
# ^^^ skip optional whitespace here
|
| 62 |
+
pos = labelEnd + 2
|
| 63 |
+
while pos < maximum:
|
| 64 |
+
ch = charCodeAt(string, pos)
|
| 65 |
+
if ch == 0x0A:
|
| 66 |
+
if (lineContent := getNextLine(state, nextLine)) is not None:
|
| 67 |
+
string += lineContent
|
| 68 |
+
maximum = len(string)
|
| 69 |
+
nextLine += 1
|
| 70 |
+
elif isSpace(ch):
|
| 71 |
+
pass
|
| 72 |
+
else:
|
| 73 |
+
break
|
| 74 |
+
pos += 1
|
| 75 |
+
|
| 76 |
+
# [label]: destination 'title'
|
| 77 |
+
# ^^^^^^^^^^^ parse this
|
| 78 |
+
destRes = state.md.helpers.parseLinkDestination(string, pos, maximum)
|
| 79 |
+
if not destRes.ok:
|
| 80 |
+
return False
|
| 81 |
+
|
| 82 |
+
href = state.md.normalizeLink(destRes.str)
|
| 83 |
+
if not state.md.validateLink(href):
|
| 84 |
+
return False
|
| 85 |
+
|
| 86 |
+
pos = destRes.pos
|
| 87 |
+
|
| 88 |
+
# save cursor state, we could require to rollback later
|
| 89 |
+
destEndPos = pos
|
| 90 |
+
destEndLineNo = nextLine
|
| 91 |
+
|
| 92 |
+
# [label]: destination 'title'
|
| 93 |
+
# ^^^ skipping those spaces
|
| 94 |
+
start = pos
|
| 95 |
+
while pos < maximum:
|
| 96 |
+
ch = charCodeAt(string, pos)
|
| 97 |
+
if ch == 0x0A:
|
| 98 |
+
if (lineContent := getNextLine(state, nextLine)) is not None:
|
| 99 |
+
string += lineContent
|
| 100 |
+
maximum = len(string)
|
| 101 |
+
nextLine += 1
|
| 102 |
+
elif isSpace(ch):
|
| 103 |
+
pass
|
| 104 |
+
else:
|
| 105 |
+
break
|
| 106 |
+
pos += 1
|
| 107 |
+
|
| 108 |
+
# [label]: destination 'title'
|
| 109 |
+
# ^^^^^^^ parse this
|
| 110 |
+
titleRes = state.md.helpers.parseLinkTitle(string, pos, maximum, None)
|
| 111 |
+
while titleRes.can_continue:
|
| 112 |
+
if (lineContent := getNextLine(state, nextLine)) is None:
|
| 113 |
+
break
|
| 114 |
+
string += lineContent
|
| 115 |
+
pos = maximum
|
| 116 |
+
maximum = len(string)
|
| 117 |
+
nextLine += 1
|
| 118 |
+
titleRes = state.md.helpers.parseLinkTitle(string, pos, maximum, titleRes)
|
| 119 |
+
|
| 120 |
+
if pos < maximum and start != pos and titleRes.ok:
|
| 121 |
+
title = titleRes.str
|
| 122 |
+
pos = titleRes.pos
|
| 123 |
+
else:
|
| 124 |
+
title = ""
|
| 125 |
+
pos = destEndPos
|
| 126 |
+
nextLine = destEndLineNo
|
| 127 |
+
|
| 128 |
+
# skip trailing spaces until the rest of the line
|
| 129 |
+
while pos < maximum:
|
| 130 |
+
ch = charCodeAt(string, pos)
|
| 131 |
+
if not isSpace(ch):
|
| 132 |
+
break
|
| 133 |
+
pos += 1
|
| 134 |
+
|
| 135 |
+
if pos < maximum and charCodeAt(string, pos) != 0x0A and title:
|
| 136 |
+
# garbage at the end of the line after title,
|
| 137 |
+
# but it could still be a valid reference if we roll back
|
| 138 |
+
title = ""
|
| 139 |
+
pos = destEndPos
|
| 140 |
+
nextLine = destEndLineNo
|
| 141 |
+
while pos < maximum:
|
| 142 |
+
ch = charCodeAt(string, pos)
|
| 143 |
+
if not isSpace(ch):
|
| 144 |
+
break
|
| 145 |
+
pos += 1
|
| 146 |
+
|
| 147 |
+
if pos < maximum and charCodeAt(string, pos) != 0x0A:
|
| 148 |
+
# garbage at the end of the line
|
| 149 |
+
return False
|
| 150 |
+
|
| 151 |
+
label = normalizeReference(string[1:labelEnd])
|
| 152 |
+
if not label:
|
| 153 |
+
# CommonMark 0.20 disallows empty labels
|
| 154 |
+
return False
|
| 155 |
+
|
| 156 |
+
# Reference can not terminate anything. This check is for safety only.
|
| 157 |
+
if silent:
|
| 158 |
+
return True
|
| 159 |
+
|
| 160 |
+
if "references" not in state.env:
|
| 161 |
+
state.env["references"] = {}
|
| 162 |
+
|
| 163 |
+
state.line = nextLine
|
| 164 |
+
|
| 165 |
+
# note, this is not part of markdown-it JS, but is useful for renderers
|
| 166 |
+
if state.md.options.get("inline_definitions", False):
|
| 167 |
+
token = state.push("definition", "", 0)
|
| 168 |
+
token.meta = {
|
| 169 |
+
"id": label,
|
| 170 |
+
"title": title,
|
| 171 |
+
"url": href,
|
| 172 |
+
"label": string[1:labelEnd],
|
| 173 |
+
}
|
| 174 |
+
token.map = [startLine, state.line]
|
| 175 |
+
|
| 176 |
+
if label not in state.env["references"]:
|
| 177 |
+
state.env["references"][label] = {
|
| 178 |
+
"title": title,
|
| 179 |
+
"href": href,
|
| 180 |
+
"map": [startLine, state.line],
|
| 181 |
+
}
|
| 182 |
+
else:
|
| 183 |
+
state.env.setdefault("duplicate_refs", []).append(
|
| 184 |
+
{
|
| 185 |
+
"title": title,
|
| 186 |
+
"href": href,
|
| 187 |
+
"label": label,
|
| 188 |
+
"map": [startLine, state.line],
|
| 189 |
+
}
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
return True
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def getNextLine(state: StateBlock, nextLine: int) -> None | str:
|
| 196 |
+
endLine = state.lineMax
|
| 197 |
+
|
| 198 |
+
if nextLine >= endLine or state.isEmpty(nextLine):
|
| 199 |
+
# empty line or end of input
|
| 200 |
+
return None
|
| 201 |
+
|
| 202 |
+
isContinuation = False
|
| 203 |
+
|
| 204 |
+
# this would be a code block normally, but after paragraph
|
| 205 |
+
# it's considered a lazy continuation regardless of what's there
|
| 206 |
+
if state.is_code_block(nextLine):
|
| 207 |
+
isContinuation = True
|
| 208 |
+
|
| 209 |
+
# quirk for blockquotes, this line should already be checked by that rule
|
| 210 |
+
if state.sCount[nextLine] < 0:
|
| 211 |
+
isContinuation = True
|
| 212 |
+
|
| 213 |
+
if not isContinuation:
|
| 214 |
+
terminatorRules = state.md.block.ruler.getRules("reference")
|
| 215 |
+
oldParentType = state.parentType
|
| 216 |
+
state.parentType = "reference"
|
| 217 |
+
|
| 218 |
+
# Some tags can terminate paragraph without empty line.
|
| 219 |
+
terminate = False
|
| 220 |
+
for terminatorRule in terminatorRules:
|
| 221 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 222 |
+
terminate = True
|
| 223 |
+
break
|
| 224 |
+
|
| 225 |
+
state.parentType = oldParentType
|
| 226 |
+
|
| 227 |
+
if terminate:
|
| 228 |
+
# terminated by another block
|
| 229 |
+
return None
|
| 230 |
+
|
| 231 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 232 |
+
maximum = state.eMarks[nextLine]
|
| 233 |
+
|
| 234 |
+
# max + 1 explicitly includes the newline
|
| 235 |
+
return state.src[pos : maximum + 1]
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/state_block.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING, Literal
|
| 4 |
+
|
| 5 |
+
from ..common.utils import isStrSpace
|
| 6 |
+
from ..ruler import StateBase
|
| 7 |
+
from ..token import Token
|
| 8 |
+
from ..utils import EnvType
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from markdown_it.main import MarkdownIt
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class StateBlock(StateBase):
|
| 15 |
+
def __init__(
|
| 16 |
+
self, src: str, md: MarkdownIt, env: EnvType, tokens: list[Token]
|
| 17 |
+
) -> None:
|
| 18 |
+
self.src = src
|
| 19 |
+
|
| 20 |
+
# link to parser instance
|
| 21 |
+
self.md = md
|
| 22 |
+
|
| 23 |
+
self.env = env
|
| 24 |
+
|
| 25 |
+
#
|
| 26 |
+
# Internal state variables
|
| 27 |
+
#
|
| 28 |
+
|
| 29 |
+
self.tokens = tokens
|
| 30 |
+
|
| 31 |
+
self.bMarks: list[int] = [] # line begin offsets for fast jumps
|
| 32 |
+
self.eMarks: list[int] = [] # line end offsets for fast jumps
|
| 33 |
+
# offsets of the first non-space characters (tabs not expanded)
|
| 34 |
+
self.tShift: list[int] = []
|
| 35 |
+
self.sCount: list[int] = [] # indents for each line (tabs expanded)
|
| 36 |
+
|
| 37 |
+
# An amount of virtual spaces (tabs expanded) between beginning
|
| 38 |
+
# of each line (bMarks) and real beginning of that line.
|
| 39 |
+
#
|
| 40 |
+
# It exists only as a hack because blockquotes override bMarks
|
| 41 |
+
# losing information in the process.
|
| 42 |
+
#
|
| 43 |
+
# It's used only when expanding tabs, you can think about it as
|
| 44 |
+
# an initial tab length, e.g. bsCount=21 applied to string `\t123`
|
| 45 |
+
# means first tab should be expanded to 4-21%4 === 3 spaces.
|
| 46 |
+
#
|
| 47 |
+
self.bsCount: list[int] = []
|
| 48 |
+
|
| 49 |
+
# block parser variables
|
| 50 |
+
self.blkIndent = 0 # required block content indent (for example, if we are
|
| 51 |
+
# inside a list, it would be positioned after list marker)
|
| 52 |
+
self.line = 0 # line index in src
|
| 53 |
+
self.lineMax = 0 # lines count
|
| 54 |
+
self.tight = False # loose/tight mode for lists
|
| 55 |
+
self.ddIndent = -1 # indent of the current dd block (-1 if there isn't any)
|
| 56 |
+
self.listIndent = -1 # indent of the current list block (-1 if there isn't any)
|
| 57 |
+
|
| 58 |
+
# can be 'blockquote', 'list', 'root', 'paragraph' or 'reference'
|
| 59 |
+
# used in lists to determine if they interrupt a paragraph
|
| 60 |
+
self.parentType = "root"
|
| 61 |
+
|
| 62 |
+
self.level = 0
|
| 63 |
+
|
| 64 |
+
# renderer
|
| 65 |
+
self.result = ""
|
| 66 |
+
|
| 67 |
+
# Create caches
|
| 68 |
+
# Generate markers.
|
| 69 |
+
indent_found = False
|
| 70 |
+
|
| 71 |
+
start = pos = indent = offset = 0
|
| 72 |
+
length = len(self.src)
|
| 73 |
+
|
| 74 |
+
for pos, character in enumerate(self.src):
|
| 75 |
+
if not indent_found:
|
| 76 |
+
if isStrSpace(character):
|
| 77 |
+
indent += 1
|
| 78 |
+
|
| 79 |
+
if character == "\t":
|
| 80 |
+
offset += 4 - offset % 4
|
| 81 |
+
else:
|
| 82 |
+
offset += 1
|
| 83 |
+
continue
|
| 84 |
+
else:
|
| 85 |
+
indent_found = True
|
| 86 |
+
|
| 87 |
+
if character == "\n" or pos == length - 1:
|
| 88 |
+
if character != "\n":
|
| 89 |
+
pos += 1
|
| 90 |
+
self.bMarks.append(start)
|
| 91 |
+
self.eMarks.append(pos)
|
| 92 |
+
self.tShift.append(indent)
|
| 93 |
+
self.sCount.append(offset)
|
| 94 |
+
self.bsCount.append(0)
|
| 95 |
+
|
| 96 |
+
indent_found = False
|
| 97 |
+
indent = 0
|
| 98 |
+
offset = 0
|
| 99 |
+
start = pos + 1
|
| 100 |
+
|
| 101 |
+
# Push fake entry to simplify cache bounds checks
|
| 102 |
+
self.bMarks.append(length)
|
| 103 |
+
self.eMarks.append(length)
|
| 104 |
+
self.tShift.append(0)
|
| 105 |
+
self.sCount.append(0)
|
| 106 |
+
self.bsCount.append(0)
|
| 107 |
+
|
| 108 |
+
self.lineMax = len(self.bMarks) - 1 # don't count last fake line
|
| 109 |
+
|
| 110 |
+
# pre-check if code blocks are enabled, to speed up is_code_block method
|
| 111 |
+
self._code_enabled = "code" in self.md["block"].ruler.get_active_rules()
|
| 112 |
+
|
| 113 |
+
def __repr__(self) -> str:
|
| 114 |
+
return (
|
| 115 |
+
f"{self.__class__.__name__}"
|
| 116 |
+
f"(line={self.line},level={self.level},tokens={len(self.tokens)})"
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
def push(self, ttype: str, tag: str, nesting: Literal[-1, 0, 1]) -> Token:
|
| 120 |
+
"""Push new token to "stream"."""
|
| 121 |
+
token = Token(ttype, tag, nesting)
|
| 122 |
+
token.block = True
|
| 123 |
+
if nesting < 0:
|
| 124 |
+
self.level -= 1 # closing tag
|
| 125 |
+
token.level = self.level
|
| 126 |
+
if nesting > 0:
|
| 127 |
+
self.level += 1 # opening tag
|
| 128 |
+
self.tokens.append(token)
|
| 129 |
+
return token
|
| 130 |
+
|
| 131 |
+
def isEmpty(self, line: int) -> bool:
|
| 132 |
+
"""."""
|
| 133 |
+
return (self.bMarks[line] + self.tShift[line]) >= self.eMarks[line]
|
| 134 |
+
|
| 135 |
+
def skipEmptyLines(self, from_pos: int) -> int:
|
| 136 |
+
"""."""
|
| 137 |
+
while from_pos < self.lineMax:
|
| 138 |
+
try:
|
| 139 |
+
if (self.bMarks[from_pos] + self.tShift[from_pos]) < self.eMarks[
|
| 140 |
+
from_pos
|
| 141 |
+
]:
|
| 142 |
+
break
|
| 143 |
+
except IndexError:
|
| 144 |
+
pass
|
| 145 |
+
from_pos += 1
|
| 146 |
+
return from_pos
|
| 147 |
+
|
| 148 |
+
def skipSpaces(self, pos: int) -> int:
|
| 149 |
+
"""Skip spaces from given position."""
|
| 150 |
+
while True:
|
| 151 |
+
try:
|
| 152 |
+
current = self.src[pos]
|
| 153 |
+
except IndexError:
|
| 154 |
+
break
|
| 155 |
+
if not isStrSpace(current):
|
| 156 |
+
break
|
| 157 |
+
pos += 1
|
| 158 |
+
return pos
|
| 159 |
+
|
| 160 |
+
def skipSpacesBack(self, pos: int, minimum: int) -> int:
|
| 161 |
+
"""Skip spaces from given position in reverse."""
|
| 162 |
+
if pos <= minimum:
|
| 163 |
+
return pos
|
| 164 |
+
while pos > minimum:
|
| 165 |
+
pos -= 1
|
| 166 |
+
if not isStrSpace(self.src[pos]):
|
| 167 |
+
return pos + 1
|
| 168 |
+
return pos
|
| 169 |
+
|
| 170 |
+
def skipChars(self, pos: int, code: int) -> int:
|
| 171 |
+
"""Skip character code from given position."""
|
| 172 |
+
while True:
|
| 173 |
+
try:
|
| 174 |
+
current = self.srcCharCode[pos]
|
| 175 |
+
except IndexError:
|
| 176 |
+
break
|
| 177 |
+
if current != code:
|
| 178 |
+
break
|
| 179 |
+
pos += 1
|
| 180 |
+
return pos
|
| 181 |
+
|
| 182 |
+
def skipCharsStr(self, pos: int, ch: str) -> int:
|
| 183 |
+
"""Skip character string from given position."""
|
| 184 |
+
while True:
|
| 185 |
+
try:
|
| 186 |
+
current = self.src[pos]
|
| 187 |
+
except IndexError:
|
| 188 |
+
break
|
| 189 |
+
if current != ch:
|
| 190 |
+
break
|
| 191 |
+
pos += 1
|
| 192 |
+
return pos
|
| 193 |
+
|
| 194 |
+
def skipCharsBack(self, pos: int, code: int, minimum: int) -> int:
|
| 195 |
+
"""Skip character code reverse from given position - 1."""
|
| 196 |
+
if pos <= minimum:
|
| 197 |
+
return pos
|
| 198 |
+
while pos > minimum:
|
| 199 |
+
pos -= 1
|
| 200 |
+
if code != self.srcCharCode[pos]:
|
| 201 |
+
return pos + 1
|
| 202 |
+
return pos
|
| 203 |
+
|
| 204 |
+
def skipCharsStrBack(self, pos: int, ch: str, minimum: int) -> int:
|
| 205 |
+
"""Skip character string reverse from given position - 1."""
|
| 206 |
+
if pos <= minimum:
|
| 207 |
+
return pos
|
| 208 |
+
while pos > minimum:
|
| 209 |
+
pos -= 1
|
| 210 |
+
if ch != self.src[pos]:
|
| 211 |
+
return pos + 1
|
| 212 |
+
return pos
|
| 213 |
+
|
| 214 |
+
def getLines(self, begin: int, end: int, indent: int, keepLastLF: bool) -> str:
|
| 215 |
+
"""Cut lines range from source."""
|
| 216 |
+
line = begin
|
| 217 |
+
if begin >= end:
|
| 218 |
+
return ""
|
| 219 |
+
|
| 220 |
+
queue = [""] * (end - begin)
|
| 221 |
+
|
| 222 |
+
i = 1
|
| 223 |
+
while line < end:
|
| 224 |
+
lineIndent = 0
|
| 225 |
+
lineStart = first = self.bMarks[line]
|
| 226 |
+
last = (
|
| 227 |
+
self.eMarks[line] + 1
|
| 228 |
+
if line + 1 < end or keepLastLF
|
| 229 |
+
else self.eMarks[line]
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
while (first < last) and (lineIndent < indent):
|
| 233 |
+
ch = self.src[first]
|
| 234 |
+
if isStrSpace(ch):
|
| 235 |
+
if ch == "\t":
|
| 236 |
+
lineIndent += 4 - (lineIndent + self.bsCount[line]) % 4
|
| 237 |
+
else:
|
| 238 |
+
lineIndent += 1
|
| 239 |
+
elif first - lineStart < self.tShift[line]:
|
| 240 |
+
lineIndent += 1
|
| 241 |
+
else:
|
| 242 |
+
break
|
| 243 |
+
first += 1
|
| 244 |
+
|
| 245 |
+
if lineIndent > indent:
|
| 246 |
+
# partially expanding tabs in code blocks, e.g '\t\tfoobar'
|
| 247 |
+
# with indent=2 becomes ' \tfoobar'
|
| 248 |
+
queue[i - 1] = (" " * (lineIndent - indent)) + self.src[first:last]
|
| 249 |
+
else:
|
| 250 |
+
queue[i - 1] = self.src[first:last]
|
| 251 |
+
|
| 252 |
+
line += 1
|
| 253 |
+
i += 1
|
| 254 |
+
|
| 255 |
+
return "".join(queue)
|
| 256 |
+
|
| 257 |
+
def is_code_block(self, line: int) -> bool:
|
| 258 |
+
"""Check if line is a code block,
|
| 259 |
+
i.e. the code block rule is enabled and text is indented by more than 3 spaces.
|
| 260 |
+
"""
|
| 261 |
+
return self._code_enabled and (self.sCount[line] - self.blkIndent) >= 4
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_block/table.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GFM table, https://github.github.com/gfm/#tables-extension-
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
from ..common.utils import charStrAt, isStrSpace
|
| 7 |
+
from .state_block import StateBlock
|
| 8 |
+
|
| 9 |
+
headerLineRe = re.compile(r"^:?-+:?$")
|
| 10 |
+
enclosingPipesRe = re.compile(r"^\||\|$")
|
| 11 |
+
|
| 12 |
+
# Limit the amount of empty autocompleted cells in a table,
|
| 13 |
+
# see https://github.com/markdown-it/markdown-it/issues/1000,
|
| 14 |
+
# Both pulldown-cmark and commonmark-hs limit the number of cells this way to ~200k.
|
| 15 |
+
# We set it to 65k, which can expand user input by a factor of x370
|
| 16 |
+
# (256x256 square is 1.8kB expanded into 650kB).
|
| 17 |
+
MAX_AUTOCOMPLETED_CELLS = 0x10000
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def getLine(state: StateBlock, line: int) -> str:
|
| 21 |
+
pos = state.bMarks[line] + state.tShift[line]
|
| 22 |
+
maximum = state.eMarks[line]
|
| 23 |
+
|
| 24 |
+
# return state.src.substr(pos, max - pos)
|
| 25 |
+
return state.src[pos:maximum]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def escapedSplit(string: str) -> list[str]:
|
| 29 |
+
result: list[str] = []
|
| 30 |
+
pos = 0
|
| 31 |
+
max = len(string)
|
| 32 |
+
isEscaped = False
|
| 33 |
+
lastPos = 0
|
| 34 |
+
current = ""
|
| 35 |
+
ch = charStrAt(string, pos)
|
| 36 |
+
|
| 37 |
+
while pos < max:
|
| 38 |
+
if ch == "|":
|
| 39 |
+
if not isEscaped:
|
| 40 |
+
# pipe separating cells, '|'
|
| 41 |
+
result.append(current + string[lastPos:pos])
|
| 42 |
+
current = ""
|
| 43 |
+
lastPos = pos + 1
|
| 44 |
+
else:
|
| 45 |
+
# escaped pipe, '\|'
|
| 46 |
+
current += string[lastPos : pos - 1]
|
| 47 |
+
lastPos = pos
|
| 48 |
+
|
| 49 |
+
isEscaped = ch == "\\"
|
| 50 |
+
pos += 1
|
| 51 |
+
|
| 52 |
+
ch = charStrAt(string, pos)
|
| 53 |
+
|
| 54 |
+
result.append(current + string[lastPos:])
|
| 55 |
+
|
| 56 |
+
return result
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def table(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 60 |
+
tbodyLines = None
|
| 61 |
+
|
| 62 |
+
# should have at least two lines
|
| 63 |
+
if startLine + 2 > endLine:
|
| 64 |
+
return False
|
| 65 |
+
|
| 66 |
+
nextLine = startLine + 1
|
| 67 |
+
|
| 68 |
+
if state.sCount[nextLine] < state.blkIndent:
|
| 69 |
+
return False
|
| 70 |
+
|
| 71 |
+
if state.is_code_block(nextLine):
|
| 72 |
+
return False
|
| 73 |
+
|
| 74 |
+
# first character of the second line should be '|', '-', ':',
|
| 75 |
+
# and no other characters are allowed but spaces;
|
| 76 |
+
# basically, this is the equivalent of /^[-:|][-:|\s]*$/ regexp
|
| 77 |
+
|
| 78 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 79 |
+
if pos >= state.eMarks[nextLine]:
|
| 80 |
+
return False
|
| 81 |
+
first_ch = state.src[pos]
|
| 82 |
+
pos += 1
|
| 83 |
+
if first_ch not in ("|", "-", ":"):
|
| 84 |
+
return False
|
| 85 |
+
|
| 86 |
+
if pos >= state.eMarks[nextLine]:
|
| 87 |
+
return False
|
| 88 |
+
second_ch = state.src[pos]
|
| 89 |
+
pos += 1
|
| 90 |
+
if second_ch not in ("|", "-", ":") and not isStrSpace(second_ch):
|
| 91 |
+
return False
|
| 92 |
+
|
| 93 |
+
# if first character is '-', then second character must not be a space
|
| 94 |
+
# (due to parsing ambiguity with list)
|
| 95 |
+
if first_ch == "-" and isStrSpace(second_ch):
|
| 96 |
+
return False
|
| 97 |
+
|
| 98 |
+
while pos < state.eMarks[nextLine]:
|
| 99 |
+
ch = state.src[pos]
|
| 100 |
+
|
| 101 |
+
if ch not in ("|", "-", ":") and not isStrSpace(ch):
|
| 102 |
+
return False
|
| 103 |
+
|
| 104 |
+
pos += 1
|
| 105 |
+
|
| 106 |
+
lineText = getLine(state, startLine + 1)
|
| 107 |
+
|
| 108 |
+
columns = lineText.split("|")
|
| 109 |
+
aligns = []
|
| 110 |
+
for i in range(len(columns)):
|
| 111 |
+
t = columns[i].strip()
|
| 112 |
+
if not t:
|
| 113 |
+
# allow empty columns before and after table, but not in between columns;
|
| 114 |
+
# e.g. allow ` |---| `, disallow ` ---||--- `
|
| 115 |
+
if i == 0 or i == len(columns) - 1:
|
| 116 |
+
continue
|
| 117 |
+
else:
|
| 118 |
+
return False
|
| 119 |
+
|
| 120 |
+
if not headerLineRe.search(t):
|
| 121 |
+
return False
|
| 122 |
+
if charStrAt(t, len(t) - 1) == ":":
|
| 123 |
+
aligns.append("center" if charStrAt(t, 0) == ":" else "right")
|
| 124 |
+
elif charStrAt(t, 0) == ":":
|
| 125 |
+
aligns.append("left")
|
| 126 |
+
else:
|
| 127 |
+
aligns.append("")
|
| 128 |
+
|
| 129 |
+
lineText = getLine(state, startLine).strip()
|
| 130 |
+
if "|" not in lineText:
|
| 131 |
+
return False
|
| 132 |
+
if state.is_code_block(startLine):
|
| 133 |
+
return False
|
| 134 |
+
columns = escapedSplit(lineText)
|
| 135 |
+
if columns and columns[0] == "":
|
| 136 |
+
columns.pop(0)
|
| 137 |
+
if columns and columns[-1] == "":
|
| 138 |
+
columns.pop()
|
| 139 |
+
|
| 140 |
+
# header row will define an amount of columns in the entire table,
|
| 141 |
+
# and align row should be exactly the same (the rest of the rows can differ)
|
| 142 |
+
columnCount = len(columns)
|
| 143 |
+
if columnCount == 0 or columnCount != len(aligns):
|
| 144 |
+
return False
|
| 145 |
+
|
| 146 |
+
if silent:
|
| 147 |
+
return True
|
| 148 |
+
|
| 149 |
+
oldParentType = state.parentType
|
| 150 |
+
state.parentType = "table"
|
| 151 |
+
|
| 152 |
+
# use 'blockquote' lists for termination because it's
|
| 153 |
+
# the most similar to tables
|
| 154 |
+
terminatorRules = state.md.block.ruler.getRules("blockquote")
|
| 155 |
+
|
| 156 |
+
token = state.push("table_open", "table", 1)
|
| 157 |
+
token.map = tableLines = [startLine, 0]
|
| 158 |
+
|
| 159 |
+
token = state.push("thead_open", "thead", 1)
|
| 160 |
+
token.map = [startLine, startLine + 1]
|
| 161 |
+
|
| 162 |
+
token = state.push("tr_open", "tr", 1)
|
| 163 |
+
token.map = [startLine, startLine + 1]
|
| 164 |
+
|
| 165 |
+
for i in range(len(columns)):
|
| 166 |
+
token = state.push("th_open", "th", 1)
|
| 167 |
+
if aligns[i]:
|
| 168 |
+
token.attrs = {"style": "text-align:" + aligns[i]}
|
| 169 |
+
|
| 170 |
+
token = state.push("inline", "", 0)
|
| 171 |
+
# note in markdown-it this map was removed in v12.0.0 however, we keep it,
|
| 172 |
+
# since it is helpful to propagate to children tokens
|
| 173 |
+
token.map = [startLine, startLine + 1]
|
| 174 |
+
token.content = columns[i].strip()
|
| 175 |
+
token.children = []
|
| 176 |
+
|
| 177 |
+
token = state.push("th_close", "th", -1)
|
| 178 |
+
|
| 179 |
+
token = state.push("tr_close", "tr", -1)
|
| 180 |
+
token = state.push("thead_close", "thead", -1)
|
| 181 |
+
|
| 182 |
+
autocompleted_cells = 0
|
| 183 |
+
nextLine = startLine + 2
|
| 184 |
+
while nextLine < endLine:
|
| 185 |
+
if state.sCount[nextLine] < state.blkIndent:
|
| 186 |
+
break
|
| 187 |
+
|
| 188 |
+
terminate = False
|
| 189 |
+
for i in range(len(terminatorRules)):
|
| 190 |
+
if terminatorRules[i](state, nextLine, endLine, True):
|
| 191 |
+
terminate = True
|
| 192 |
+
break
|
| 193 |
+
|
| 194 |
+
if terminate:
|
| 195 |
+
break
|
| 196 |
+
lineText = getLine(state, nextLine).strip()
|
| 197 |
+
if not lineText:
|
| 198 |
+
break
|
| 199 |
+
if state.is_code_block(nextLine):
|
| 200 |
+
break
|
| 201 |
+
columns = escapedSplit(lineText)
|
| 202 |
+
if columns and columns[0] == "":
|
| 203 |
+
columns.pop(0)
|
| 204 |
+
if columns and columns[-1] == "":
|
| 205 |
+
columns.pop()
|
| 206 |
+
|
| 207 |
+
# note: autocomplete count can be negative if user specifies more columns than header,
|
| 208 |
+
# but that does not affect intended use (which is limiting expansion)
|
| 209 |
+
autocompleted_cells += columnCount - len(columns)
|
| 210 |
+
if autocompleted_cells > MAX_AUTOCOMPLETED_CELLS:
|
| 211 |
+
break
|
| 212 |
+
|
| 213 |
+
if nextLine == startLine + 2:
|
| 214 |
+
token = state.push("tbody_open", "tbody", 1)
|
| 215 |
+
token.map = tbodyLines = [startLine + 2, 0]
|
| 216 |
+
|
| 217 |
+
token = state.push("tr_open", "tr", 1)
|
| 218 |
+
token.map = [nextLine, nextLine + 1]
|
| 219 |
+
|
| 220 |
+
for i in range(columnCount):
|
| 221 |
+
token = state.push("td_open", "td", 1)
|
| 222 |
+
if aligns[i]:
|
| 223 |
+
token.attrs = {"style": "text-align:" + aligns[i]}
|
| 224 |
+
|
| 225 |
+
token = state.push("inline", "", 0)
|
| 226 |
+
# note in markdown-it this map was removed in v12.0.0 however, we keep it,
|
| 227 |
+
# since it is helpful to propagate to children tokens
|
| 228 |
+
token.map = [nextLine, nextLine + 1]
|
| 229 |
+
try:
|
| 230 |
+
token.content = columns[i].strip() if columns[i] else ""
|
| 231 |
+
except IndexError:
|
| 232 |
+
token.content = ""
|
| 233 |
+
token.children = []
|
| 234 |
+
|
| 235 |
+
token = state.push("td_close", "td", -1)
|
| 236 |
+
|
| 237 |
+
token = state.push("tr_close", "tr", -1)
|
| 238 |
+
|
| 239 |
+
nextLine += 1
|
| 240 |
+
|
| 241 |
+
if tbodyLines:
|
| 242 |
+
token = state.push("tbody_close", "tbody", -1)
|
| 243 |
+
tbodyLines[1] = nextLine
|
| 244 |
+
|
| 245 |
+
token = state.push("table_close", "table", -1)
|
| 246 |
+
|
| 247 |
+
tableLines[1] = nextLine
|
| 248 |
+
state.parentType = oldParentType
|
| 249 |
+
state.line = nextLine
|
| 250 |
+
return True
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = (
|
| 2 |
+
"StateCore",
|
| 3 |
+
"block",
|
| 4 |
+
"inline",
|
| 5 |
+
"linkify",
|
| 6 |
+
"normalize",
|
| 7 |
+
"replace",
|
| 8 |
+
"smartquotes",
|
| 9 |
+
"text_join",
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
from .block import block
|
| 13 |
+
from .inline import inline
|
| 14 |
+
from .linkify import linkify
|
| 15 |
+
from .normalize import normalize
|
| 16 |
+
from .replacements import replace
|
| 17 |
+
from .smartquotes import smartquotes
|
| 18 |
+
from .state_core import StateCore
|
| 19 |
+
from .text_join import text_join
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/block.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..token import Token
|
| 2 |
+
from .state_core import StateCore
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def block(state: StateCore) -> None:
|
| 6 |
+
if state.inlineMode:
|
| 7 |
+
token = Token("inline", "", 0)
|
| 8 |
+
token.content = state.src
|
| 9 |
+
token.map = [0, 1]
|
| 10 |
+
token.children = []
|
| 11 |
+
state.tokens.append(token)
|
| 12 |
+
else:
|
| 13 |
+
state.md.block.parse(state.src, state.md, state.env, state.tokens)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/inline.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .state_core import StateCore
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def inline(state: StateCore) -> None:
|
| 5 |
+
"""Parse inlines"""
|
| 6 |
+
for token in state.tokens:
|
| 7 |
+
if token.type == "inline":
|
| 8 |
+
if token.children is None:
|
| 9 |
+
token.children = []
|
| 10 |
+
state.md.inline.parse(token.content, state.md, state.env, token.children)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/linkify.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
from typing import Protocol
|
| 5 |
+
|
| 6 |
+
from ..common.utils import arrayReplaceAt, isLinkClose, isLinkOpen
|
| 7 |
+
from ..token import Token
|
| 8 |
+
from .state_core import StateCore
|
| 9 |
+
|
| 10 |
+
HTTP_RE = re.compile(r"^http://")
|
| 11 |
+
MAILTO_RE = re.compile(r"^mailto:")
|
| 12 |
+
TEST_MAILTO_RE = re.compile(r"^mailto:", flags=re.IGNORECASE)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def linkify(state: StateCore) -> None:
|
| 16 |
+
"""Rule for identifying plain-text links."""
|
| 17 |
+
if not state.md.options.linkify:
|
| 18 |
+
return
|
| 19 |
+
|
| 20 |
+
if not state.md.linkify:
|
| 21 |
+
raise ModuleNotFoundError("Linkify enabled but not installed.")
|
| 22 |
+
|
| 23 |
+
for inline_token in state.tokens:
|
| 24 |
+
if inline_token.type != "inline" or not state.md.linkify.pretest(
|
| 25 |
+
inline_token.content
|
| 26 |
+
):
|
| 27 |
+
continue
|
| 28 |
+
|
| 29 |
+
tokens = inline_token.children
|
| 30 |
+
|
| 31 |
+
htmlLinkLevel = 0
|
| 32 |
+
|
| 33 |
+
# We scan from the end, to keep position when new tags added.
|
| 34 |
+
# Use reversed logic in links start/end match
|
| 35 |
+
assert tokens is not None
|
| 36 |
+
i = len(tokens)
|
| 37 |
+
while i >= 1:
|
| 38 |
+
i -= 1
|
| 39 |
+
assert isinstance(tokens, list)
|
| 40 |
+
currentToken = tokens[i]
|
| 41 |
+
|
| 42 |
+
# Skip content of markdown links
|
| 43 |
+
if currentToken.type == "link_close":
|
| 44 |
+
i -= 1
|
| 45 |
+
while (
|
| 46 |
+
tokens[i].level != currentToken.level
|
| 47 |
+
and tokens[i].type != "link_open"
|
| 48 |
+
):
|
| 49 |
+
i -= 1
|
| 50 |
+
continue
|
| 51 |
+
|
| 52 |
+
# Skip content of html tag links
|
| 53 |
+
if currentToken.type == "html_inline":
|
| 54 |
+
if isLinkOpen(currentToken.content) and htmlLinkLevel > 0:
|
| 55 |
+
htmlLinkLevel -= 1
|
| 56 |
+
if isLinkClose(currentToken.content):
|
| 57 |
+
htmlLinkLevel += 1
|
| 58 |
+
if htmlLinkLevel > 0:
|
| 59 |
+
continue
|
| 60 |
+
|
| 61 |
+
if currentToken.type == "text" and state.md.linkify.test(
|
| 62 |
+
currentToken.content
|
| 63 |
+
):
|
| 64 |
+
text = currentToken.content
|
| 65 |
+
links: list[_LinkType] = state.md.linkify.match(text) or []
|
| 66 |
+
|
| 67 |
+
# Now split string to nodes
|
| 68 |
+
nodes = []
|
| 69 |
+
level = currentToken.level
|
| 70 |
+
lastPos = 0
|
| 71 |
+
|
| 72 |
+
# forbid escape sequence at the start of the string,
|
| 73 |
+
# this avoids http\://example.com/ from being linkified as
|
| 74 |
+
# http:<a href="//example.com/">//example.com/</a>
|
| 75 |
+
if (
|
| 76 |
+
links
|
| 77 |
+
and links[0].index == 0
|
| 78 |
+
and i > 0
|
| 79 |
+
and tokens[i - 1].type == "text_special"
|
| 80 |
+
):
|
| 81 |
+
links = links[1:]
|
| 82 |
+
|
| 83 |
+
for link in links:
|
| 84 |
+
url = link.url
|
| 85 |
+
fullUrl = state.md.normalizeLink(url)
|
| 86 |
+
if not state.md.validateLink(fullUrl):
|
| 87 |
+
continue
|
| 88 |
+
|
| 89 |
+
urlText = link.text
|
| 90 |
+
|
| 91 |
+
# Linkifier might send raw hostnames like "example.com", where url
|
| 92 |
+
# starts with domain name. So we prepend http:// in those cases,
|
| 93 |
+
# and remove it afterwards.
|
| 94 |
+
if not link.schema:
|
| 95 |
+
urlText = HTTP_RE.sub(
|
| 96 |
+
"", state.md.normalizeLinkText("http://" + urlText)
|
| 97 |
+
)
|
| 98 |
+
elif link.schema == "mailto:" and TEST_MAILTO_RE.search(urlText):
|
| 99 |
+
urlText = MAILTO_RE.sub(
|
| 100 |
+
"", state.md.normalizeLinkText("mailto:" + urlText)
|
| 101 |
+
)
|
| 102 |
+
else:
|
| 103 |
+
urlText = state.md.normalizeLinkText(urlText)
|
| 104 |
+
|
| 105 |
+
pos = link.index
|
| 106 |
+
|
| 107 |
+
if pos > lastPos:
|
| 108 |
+
token = Token("text", "", 0)
|
| 109 |
+
token.content = text[lastPos:pos]
|
| 110 |
+
token.level = level
|
| 111 |
+
nodes.append(token)
|
| 112 |
+
|
| 113 |
+
token = Token("link_open", "a", 1)
|
| 114 |
+
token.attrs = {"href": fullUrl}
|
| 115 |
+
token.level = level
|
| 116 |
+
level += 1
|
| 117 |
+
token.markup = "linkify"
|
| 118 |
+
token.info = "auto"
|
| 119 |
+
nodes.append(token)
|
| 120 |
+
|
| 121 |
+
token = Token("text", "", 0)
|
| 122 |
+
token.content = urlText
|
| 123 |
+
token.level = level
|
| 124 |
+
nodes.append(token)
|
| 125 |
+
|
| 126 |
+
token = Token("link_close", "a", -1)
|
| 127 |
+
level -= 1
|
| 128 |
+
token.level = level
|
| 129 |
+
token.markup = "linkify"
|
| 130 |
+
token.info = "auto"
|
| 131 |
+
nodes.append(token)
|
| 132 |
+
|
| 133 |
+
lastPos = link.last_index
|
| 134 |
+
|
| 135 |
+
if lastPos < len(text):
|
| 136 |
+
token = Token("text", "", 0)
|
| 137 |
+
token.content = text[lastPos:]
|
| 138 |
+
token.level = level
|
| 139 |
+
nodes.append(token)
|
| 140 |
+
|
| 141 |
+
inline_token.children = tokens = arrayReplaceAt(tokens, i, nodes)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class _LinkType(Protocol):
|
| 145 |
+
url: str
|
| 146 |
+
text: str
|
| 147 |
+
index: int
|
| 148 |
+
last_index: int
|
| 149 |
+
schema: str | None
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/normalize.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Normalize input string."""
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
from .state_core import StateCore
|
| 6 |
+
|
| 7 |
+
# https://spec.commonmark.org/0.29/#line-ending
|
| 8 |
+
NEWLINES_RE = re.compile(r"\r\n?|\n")
|
| 9 |
+
NULL_RE = re.compile(r"\0")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def normalize(state: StateCore) -> None:
|
| 13 |
+
# Normalize newlines
|
| 14 |
+
string = NEWLINES_RE.sub("\n", state.src)
|
| 15 |
+
|
| 16 |
+
# Replace NULL characters
|
| 17 |
+
string = NULL_RE.sub("\ufffd", string)
|
| 18 |
+
|
| 19 |
+
state.src = string
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/replacements.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Simple typographic replacements
|
| 2 |
+
|
| 3 |
+
* ``(c)``, ``(C)`` → ©
|
| 4 |
+
* ``(tm)``, ``(TM)`` → ™
|
| 5 |
+
* ``(r)``, ``(R)`` → ®
|
| 6 |
+
* ``+-`` → ±
|
| 7 |
+
* ``...`` → …
|
| 8 |
+
* ``?....`` → ?..
|
| 9 |
+
* ``!....`` → !..
|
| 10 |
+
* ``????????`` → ???
|
| 11 |
+
* ``!!!!!`` → !!!
|
| 12 |
+
* ``,,,`` → ,
|
| 13 |
+
* ``--`` → &ndash
|
| 14 |
+
* ``---`` → &mdash
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
from __future__ import annotations
|
| 18 |
+
|
| 19 |
+
import logging
|
| 20 |
+
import re
|
| 21 |
+
|
| 22 |
+
from ..token import Token
|
| 23 |
+
from .state_core import StateCore
|
| 24 |
+
|
| 25 |
+
LOGGER = logging.getLogger(__name__)
|
| 26 |
+
|
| 27 |
+
# TODO:
|
| 28 |
+
# - fractionals 1/2, 1/4, 3/4 -> ½, ¼, ¾
|
| 29 |
+
# - multiplication 2 x 4 -> 2 × 4
|
| 30 |
+
|
| 31 |
+
RARE_RE = re.compile(r"\+-|\.\.|\?\?\?\?|!!!!|,,|--")
|
| 32 |
+
|
| 33 |
+
# Workaround for phantomjs - need regex without /g flag,
|
| 34 |
+
# or root check will fail every second time
|
| 35 |
+
# SCOPED_ABBR_TEST_RE = r"\((c|tm|r)\)"
|
| 36 |
+
|
| 37 |
+
SCOPED_ABBR_RE = re.compile(r"\((c|tm|r)\)", flags=re.IGNORECASE)
|
| 38 |
+
|
| 39 |
+
PLUS_MINUS_RE = re.compile(r"\+-")
|
| 40 |
+
|
| 41 |
+
ELLIPSIS_RE = re.compile(r"\.{2,}")
|
| 42 |
+
|
| 43 |
+
ELLIPSIS_QUESTION_EXCLAMATION_RE = re.compile(r"([?!])…")
|
| 44 |
+
|
| 45 |
+
QUESTION_EXCLAMATION_RE = re.compile(r"([?!]){4,}")
|
| 46 |
+
|
| 47 |
+
COMMA_RE = re.compile(r",{2,}")
|
| 48 |
+
|
| 49 |
+
EM_DASH_RE = re.compile(r"(^|[^-])---(?=[^-]|$)", flags=re.MULTILINE)
|
| 50 |
+
|
| 51 |
+
EN_DASH_RE = re.compile(r"(^|\s)--(?=\s|$)", flags=re.MULTILINE)
|
| 52 |
+
|
| 53 |
+
EN_DASH_INDENT_RE = re.compile(r"(^|[^-\s])--(?=[^-\s]|$)", flags=re.MULTILINE)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
SCOPED_ABBR = {"c": "©", "r": "®", "tm": "™"}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def replaceFn(match: re.Match[str]) -> str:
|
| 60 |
+
return SCOPED_ABBR[match.group(1).lower()]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def replace_scoped(inlineTokens: list[Token]) -> None:
|
| 64 |
+
inside_autolink = 0
|
| 65 |
+
|
| 66 |
+
for token in inlineTokens:
|
| 67 |
+
if token.type == "text" and not inside_autolink:
|
| 68 |
+
token.content = SCOPED_ABBR_RE.sub(replaceFn, token.content)
|
| 69 |
+
|
| 70 |
+
if token.type == "link_open" and token.info == "auto":
|
| 71 |
+
inside_autolink -= 1
|
| 72 |
+
|
| 73 |
+
if token.type == "link_close" and token.info == "auto":
|
| 74 |
+
inside_autolink += 1
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def replace_rare(inlineTokens: list[Token]) -> None:
|
| 78 |
+
inside_autolink = 0
|
| 79 |
+
|
| 80 |
+
for token in inlineTokens:
|
| 81 |
+
if (
|
| 82 |
+
token.type == "text"
|
| 83 |
+
and (not inside_autolink)
|
| 84 |
+
and RARE_RE.search(token.content)
|
| 85 |
+
):
|
| 86 |
+
# +- -> ±
|
| 87 |
+
token.content = PLUS_MINUS_RE.sub("±", token.content)
|
| 88 |
+
|
| 89 |
+
# .., ..., ....... -> …
|
| 90 |
+
token.content = ELLIPSIS_RE.sub("…", token.content)
|
| 91 |
+
|
| 92 |
+
# but ?..... & !..... -> ?.. & !..
|
| 93 |
+
token.content = ELLIPSIS_QUESTION_EXCLAMATION_RE.sub("\\1..", token.content)
|
| 94 |
+
token.content = QUESTION_EXCLAMATION_RE.sub("\\1\\1\\1", token.content)
|
| 95 |
+
|
| 96 |
+
# ,, ,,, ,,,, -> ,
|
| 97 |
+
token.content = COMMA_RE.sub(",", token.content)
|
| 98 |
+
|
| 99 |
+
# em-dash
|
| 100 |
+
token.content = EM_DASH_RE.sub("\\1\u2014", token.content)
|
| 101 |
+
|
| 102 |
+
# en-dash
|
| 103 |
+
token.content = EN_DASH_RE.sub("\\1\u2013", token.content)
|
| 104 |
+
token.content = EN_DASH_INDENT_RE.sub("\\1\u2013", token.content)
|
| 105 |
+
|
| 106 |
+
if token.type == "link_open" and token.info == "auto":
|
| 107 |
+
inside_autolink -= 1
|
| 108 |
+
|
| 109 |
+
if token.type == "link_close" and token.info == "auto":
|
| 110 |
+
inside_autolink += 1
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def replace(state: StateCore) -> None:
|
| 114 |
+
if not state.md.options.typographer:
|
| 115 |
+
return
|
| 116 |
+
|
| 117 |
+
for token in state.tokens:
|
| 118 |
+
if token.type != "inline":
|
| 119 |
+
continue
|
| 120 |
+
if token.children is None:
|
| 121 |
+
continue
|
| 122 |
+
|
| 123 |
+
if SCOPED_ABBR_RE.search(token.content):
|
| 124 |
+
replace_scoped(token.children)
|
| 125 |
+
|
| 126 |
+
if RARE_RE.search(token.content):
|
| 127 |
+
replace_rare(token.children)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/smartquotes.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Convert straight quotation marks to typographic ones"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
from typing import Any
|
| 7 |
+
|
| 8 |
+
from ..common.utils import charCodeAt, isMdAsciiPunct, isPunctChar, isWhiteSpace
|
| 9 |
+
from ..token import Token
|
| 10 |
+
from .state_core import StateCore
|
| 11 |
+
|
| 12 |
+
QUOTE_TEST_RE = re.compile(r"['\"]")
|
| 13 |
+
QUOTE_RE = re.compile(r"['\"]")
|
| 14 |
+
APOSTROPHE = "\u2019" # ’
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def replaceAt(string: str, index: int, ch: str) -> str:
|
| 18 |
+
# When the index is negative, the behavior is different from the js version.
|
| 19 |
+
# But basically, the index will not be negative.
|
| 20 |
+
assert index >= 0
|
| 21 |
+
return string[:index] + ch + string[index + 1 :]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def process_inlines(tokens: list[Token], state: StateCore) -> None:
|
| 25 |
+
stack: list[dict[str, Any]] = []
|
| 26 |
+
|
| 27 |
+
for i, token in enumerate(tokens):
|
| 28 |
+
thisLevel = token.level
|
| 29 |
+
|
| 30 |
+
j = 0
|
| 31 |
+
for j in range(len(stack))[::-1]:
|
| 32 |
+
if stack[j]["level"] <= thisLevel:
|
| 33 |
+
break
|
| 34 |
+
else:
|
| 35 |
+
# When the loop is terminated without a "break".
|
| 36 |
+
# Subtract 1 to get the same index as the js version.
|
| 37 |
+
j -= 1
|
| 38 |
+
|
| 39 |
+
stack = stack[: j + 1]
|
| 40 |
+
|
| 41 |
+
if token.type != "text":
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
text = token.content
|
| 45 |
+
pos = 0
|
| 46 |
+
maximum = len(text)
|
| 47 |
+
|
| 48 |
+
while pos < maximum:
|
| 49 |
+
goto_outer = False
|
| 50 |
+
lastIndex = pos
|
| 51 |
+
t = QUOTE_RE.search(text[lastIndex:])
|
| 52 |
+
if not t:
|
| 53 |
+
break
|
| 54 |
+
|
| 55 |
+
canOpen = canClose = True
|
| 56 |
+
pos = t.start(0) + lastIndex + 1
|
| 57 |
+
isSingle = t.group(0) == "'"
|
| 58 |
+
|
| 59 |
+
# Find previous character,
|
| 60 |
+
# default to space if it's the beginning of the line
|
| 61 |
+
lastChar: None | int = 0x20
|
| 62 |
+
|
| 63 |
+
if t.start(0) + lastIndex - 1 >= 0:
|
| 64 |
+
lastChar = charCodeAt(text, t.start(0) + lastIndex - 1)
|
| 65 |
+
else:
|
| 66 |
+
for j in range(i)[::-1]:
|
| 67 |
+
if tokens[j].type == "softbreak" or tokens[j].type == "hardbreak":
|
| 68 |
+
break
|
| 69 |
+
# should skip all tokens except 'text', 'html_inline' or 'code_inline'
|
| 70 |
+
if not tokens[j].content:
|
| 71 |
+
continue
|
| 72 |
+
|
| 73 |
+
lastChar = charCodeAt(tokens[j].content, len(tokens[j].content) - 1)
|
| 74 |
+
break
|
| 75 |
+
|
| 76 |
+
# Find next character,
|
| 77 |
+
# default to space if it's the end of the line
|
| 78 |
+
nextChar: None | int = 0x20
|
| 79 |
+
|
| 80 |
+
if pos < maximum:
|
| 81 |
+
nextChar = charCodeAt(text, pos)
|
| 82 |
+
else:
|
| 83 |
+
for j in range(i + 1, len(tokens)):
|
| 84 |
+
# nextChar defaults to 0x20
|
| 85 |
+
if tokens[j].type == "softbreak" or tokens[j].type == "hardbreak":
|
| 86 |
+
break
|
| 87 |
+
# should skip all tokens except 'text', 'html_inline' or 'code_inline'
|
| 88 |
+
if not tokens[j].content:
|
| 89 |
+
continue
|
| 90 |
+
|
| 91 |
+
nextChar = charCodeAt(tokens[j].content, 0)
|
| 92 |
+
break
|
| 93 |
+
|
| 94 |
+
isLastPunctChar = lastChar is not None and (
|
| 95 |
+
isMdAsciiPunct(lastChar) or isPunctChar(chr(lastChar))
|
| 96 |
+
)
|
| 97 |
+
isNextPunctChar = nextChar is not None and (
|
| 98 |
+
isMdAsciiPunct(nextChar) or isPunctChar(chr(nextChar))
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
isLastWhiteSpace = lastChar is not None and isWhiteSpace(lastChar)
|
| 102 |
+
isNextWhiteSpace = nextChar is not None and isWhiteSpace(nextChar)
|
| 103 |
+
|
| 104 |
+
if isNextWhiteSpace: # noqa: SIM114
|
| 105 |
+
canOpen = False
|
| 106 |
+
elif isNextPunctChar and not (isLastWhiteSpace or isLastPunctChar):
|
| 107 |
+
canOpen = False
|
| 108 |
+
|
| 109 |
+
if isLastWhiteSpace: # noqa: SIM114
|
| 110 |
+
canClose = False
|
| 111 |
+
elif isLastPunctChar and not (isNextWhiteSpace or isNextPunctChar):
|
| 112 |
+
canClose = False
|
| 113 |
+
|
| 114 |
+
if nextChar == 0x22 and t.group(0) == '"': # 0x22: " # noqa: SIM102
|
| 115 |
+
if (
|
| 116 |
+
lastChar is not None and lastChar >= 0x30 and lastChar <= 0x39
|
| 117 |
+
): # 0x30: 0, 0x39: 9
|
| 118 |
+
# special case: 1"" - count first quote as an inch
|
| 119 |
+
canClose = canOpen = False
|
| 120 |
+
|
| 121 |
+
if canOpen and canClose:
|
| 122 |
+
# Replace quotes in the middle of punctuation sequence, but not
|
| 123 |
+
# in the middle of the words, i.e.:
|
| 124 |
+
#
|
| 125 |
+
# 1. foo " bar " baz - not replaced
|
| 126 |
+
# 2. foo-"-bar-"-baz - replaced
|
| 127 |
+
# 3. foo"bar"baz - not replaced
|
| 128 |
+
canOpen = isLastPunctChar
|
| 129 |
+
canClose = isNextPunctChar
|
| 130 |
+
|
| 131 |
+
if not canOpen and not canClose:
|
| 132 |
+
# middle of word
|
| 133 |
+
if isSingle:
|
| 134 |
+
token.content = replaceAt(
|
| 135 |
+
token.content, t.start(0) + lastIndex, APOSTROPHE
|
| 136 |
+
)
|
| 137 |
+
continue
|
| 138 |
+
|
| 139 |
+
if canClose:
|
| 140 |
+
# this could be a closing quote, rewind the stack to get a match
|
| 141 |
+
for j in range(len(stack))[::-1]:
|
| 142 |
+
item = stack[j]
|
| 143 |
+
if stack[j]["level"] < thisLevel:
|
| 144 |
+
break
|
| 145 |
+
if item["single"] == isSingle and stack[j]["level"] == thisLevel:
|
| 146 |
+
item = stack[j]
|
| 147 |
+
|
| 148 |
+
if isSingle:
|
| 149 |
+
openQuote = state.md.options.quotes[2]
|
| 150 |
+
closeQuote = state.md.options.quotes[3]
|
| 151 |
+
else:
|
| 152 |
+
openQuote = state.md.options.quotes[0]
|
| 153 |
+
closeQuote = state.md.options.quotes[1]
|
| 154 |
+
|
| 155 |
+
# replace token.content *before* tokens[item.token].content,
|
| 156 |
+
# because, if they are pointing at the same token, replaceAt
|
| 157 |
+
# could mess up indices when quote length != 1
|
| 158 |
+
token.content = replaceAt(
|
| 159 |
+
token.content, t.start(0) + lastIndex, closeQuote
|
| 160 |
+
)
|
| 161 |
+
tokens[item["token"]].content = replaceAt(
|
| 162 |
+
tokens[item["token"]].content, item["pos"], openQuote
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
pos += len(closeQuote) - 1
|
| 166 |
+
if item["token"] == i:
|
| 167 |
+
pos += len(openQuote) - 1
|
| 168 |
+
|
| 169 |
+
text = token.content
|
| 170 |
+
maximum = len(text)
|
| 171 |
+
|
| 172 |
+
stack = stack[:j]
|
| 173 |
+
goto_outer = True
|
| 174 |
+
break
|
| 175 |
+
if goto_outer:
|
| 176 |
+
goto_outer = False
|
| 177 |
+
continue
|
| 178 |
+
|
| 179 |
+
if canOpen:
|
| 180 |
+
stack.append(
|
| 181 |
+
{
|
| 182 |
+
"token": i,
|
| 183 |
+
"pos": t.start(0) + lastIndex,
|
| 184 |
+
"single": isSingle,
|
| 185 |
+
"level": thisLevel,
|
| 186 |
+
}
|
| 187 |
+
)
|
| 188 |
+
elif canClose and isSingle:
|
| 189 |
+
token.content = replaceAt(
|
| 190 |
+
token.content, t.start(0) + lastIndex, APOSTROPHE
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def smartquotes(state: StateCore) -> None:
|
| 195 |
+
if not state.md.options.typographer:
|
| 196 |
+
return
|
| 197 |
+
|
| 198 |
+
for token in state.tokens:
|
| 199 |
+
if token.type != "inline" or not QUOTE_RE.search(token.content):
|
| 200 |
+
continue
|
| 201 |
+
if token.children is not None:
|
| 202 |
+
process_inlines(token.children, state)
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/state_core.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
from ..ruler import StateBase
|
| 6 |
+
from ..token import Token
|
| 7 |
+
from ..utils import EnvType
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
from markdown_it import MarkdownIt
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class StateCore(StateBase):
|
| 14 |
+
def __init__(
|
| 15 |
+
self,
|
| 16 |
+
src: str,
|
| 17 |
+
md: MarkdownIt,
|
| 18 |
+
env: EnvType,
|
| 19 |
+
tokens: list[Token] | None = None,
|
| 20 |
+
) -> None:
|
| 21 |
+
self.src = src
|
| 22 |
+
self.md = md # link to parser instance
|
| 23 |
+
self.env = env
|
| 24 |
+
self.tokens: list[Token] = tokens or []
|
| 25 |
+
self.inlineMode = False
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_core/text_join.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Join raw text tokens with the rest of the text
|
| 2 |
+
|
| 3 |
+
This is set as a separate rule to provide an opportunity for plugins
|
| 4 |
+
to run text replacements after text join, but before escape join.
|
| 5 |
+
|
| 6 |
+
For example, `\\:)` shouldn't be replaced with an emoji.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
from ..token import Token
|
| 12 |
+
from .state_core import StateCore
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def text_join(state: StateCore) -> None:
|
| 16 |
+
"""Join raw text for escape sequences (`text_special`) tokens with the rest of the text"""
|
| 17 |
+
|
| 18 |
+
for inline_token in state.tokens[:]:
|
| 19 |
+
if inline_token.type != "inline":
|
| 20 |
+
continue
|
| 21 |
+
|
| 22 |
+
# convert text_special to text and join all adjacent text nodes
|
| 23 |
+
new_tokens: list[Token] = []
|
| 24 |
+
for child_token in inline_token.children or []:
|
| 25 |
+
if child_token.type == "text_special":
|
| 26 |
+
child_token.type = "text"
|
| 27 |
+
if (
|
| 28 |
+
child_token.type == "text"
|
| 29 |
+
and new_tokens
|
| 30 |
+
and new_tokens[-1].type == "text"
|
| 31 |
+
):
|
| 32 |
+
new_tokens[-1].content += child_token.content
|
| 33 |
+
else:
|
| 34 |
+
new_tokens.append(child_token)
|
| 35 |
+
inline_token.children = new_tokens
|
.cache/uv/archive-v0/8afuC0ufXvZbwZaI0_fpd/markdown_it/rules_inline/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = (
|
| 2 |
+
"StateInline",
|
| 3 |
+
"autolink",
|
| 4 |
+
"backtick",
|
| 5 |
+
"emphasis",
|
| 6 |
+
"entity",
|
| 7 |
+
"escape",
|
| 8 |
+
"fragments_join",
|
| 9 |
+
"html_inline",
|
| 10 |
+
"image",
|
| 11 |
+
"link",
|
| 12 |
+
"link_pairs",
|
| 13 |
+
"linkify",
|
| 14 |
+
"newline",
|
| 15 |
+
"strikethrough",
|
| 16 |
+
"text",
|
| 17 |
+
)
|
| 18 |
+
from . import emphasis, strikethrough
|
| 19 |
+
from .autolink import autolink
|
| 20 |
+
from .backticks import backtick
|
| 21 |
+
from .balance_pairs import link_pairs
|
| 22 |
+
from .entity import entity
|
| 23 |
+
from .escape import escape
|
| 24 |
+
from .fragments_join import fragments_join
|
| 25 |
+
from .html_inline import html_inline
|
| 26 |
+
from .image import image
|
| 27 |
+
from .link import link
|
| 28 |
+
from .linkify import linkify
|
| 29 |
+
from .newline import newline
|
| 30 |
+
from .state_inline import StateInline
|
| 31 |
+
from .text import text
|