Instructions to use godlykmathews/BERT-Sentiment_Classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use godlykmathews/BERT-Sentiment_Classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="godlykmathews/BERT-Sentiment_Classifier")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("godlykmathews/BERT-Sentiment_Classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub (part 5)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/INSTALLER +1 -0
- venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/METADATA +54 -0
- venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/RECORD +33 -0
- venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/WHEEL +4 -0
- venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/licenses/COPYING +19 -0
- venv/lib/python3.14/site-packages/jsonschema_specifications/schemas/draft7/metaschema.json +166 -0
- venv/lib/python3.14/site-packages/jsonschema_specifications/tests/__init__.py +0 -0
- venv/lib/python3.14/site-packages/jsonschema_specifications/tests/test_jsonschema_specifications.py +41 -0
- venv/lib/python3.14/site-packages/markdown_it/__init__.py +6 -0
- venv/lib/python3.14/site-packages/markdown_it/_compat.py +1 -0
- venv/lib/python3.14/site-packages/markdown_it/_punycode.py +67 -0
- venv/lib/python3.14/site-packages/markdown_it/cli/__init__.py +0 -0
- venv/lib/python3.14/site-packages/markdown_it/cli/parse.py +144 -0
- venv/lib/python3.14/site-packages/markdown_it/common/__init__.py +0 -0
- venv/lib/python3.14/site-packages/markdown_it/common/entities.py +5 -0
- venv/lib/python3.14/site-packages/markdown_it/common/html_blocks.py +69 -0
- venv/lib/python3.14/site-packages/markdown_it/common/html_re.py +41 -0
- venv/lib/python3.14/site-packages/markdown_it/common/normalize_url.py +94 -0
- venv/lib/python3.14/site-packages/markdown_it/common/utils.py +338 -0
- venv/lib/python3.14/site-packages/markdown_it/helpers/__init__.py +6 -0
- venv/lib/python3.14/site-packages/markdown_it/helpers/parse_link_destination.py +83 -0
- venv/lib/python3.14/site-packages/markdown_it/helpers/parse_link_label.py +44 -0
- venv/lib/python3.14/site-packages/markdown_it/helpers/parse_link_title.py +75 -0
- venv/lib/python3.14/site-packages/markdown_it/main.py +354 -0
- venv/lib/python3.14/site-packages/markdown_it/parser_block.py +121 -0
- venv/lib/python3.14/site-packages/markdown_it/parser_core.py +46 -0
- venv/lib/python3.14/site-packages/markdown_it/parser_inline.py +220 -0
- venv/lib/python3.14/site-packages/markdown_it/port.yaml +54 -0
- venv/lib/python3.14/site-packages/markdown_it/presets/__init__.py +48 -0
- venv/lib/python3.14/site-packages/markdown_it/presets/commonmark.py +75 -0
- venv/lib/python3.14/site-packages/markdown_it/presets/default.py +36 -0
- venv/lib/python3.14/site-packages/markdown_it/presets/zero.py +44 -0
- venv/lib/python3.14/site-packages/markdown_it/py.typed +1 -0
- venv/lib/python3.14/site-packages/markdown_it/renderer.py +375 -0
- venv/lib/python3.14/site-packages/markdown_it/ruler.py +282 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/__init__.py +28 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/blockquote.py +368 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/code.py +36 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/fence.py +146 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/heading.py +72 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/hr.py +56 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/html_block.py +106 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/lheading.py +87 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/list.py +413 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/paragraph.py +67 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/reference.py +235 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/state_block.py +265 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_block/table.py +250 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_core/__init__.py +19 -0
- venv/lib/python3.14/site-packages/markdown_it/rules_core/block.py +13 -0
venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/METADATA
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: jsonschema-specifications
|
| 3 |
+
Version: 2025.9.1
|
| 4 |
+
Summary: The JSON Schema meta-schemas and vocabularies, exposed as a Registry
|
| 5 |
+
Project-URL: Documentation, https://jsonschema-specifications.readthedocs.io/
|
| 6 |
+
Project-URL: Homepage, https://github.com/python-jsonschema/jsonschema-specifications
|
| 7 |
+
Project-URL: Issues, https://github.com/python-jsonschema/jsonschema-specifications/issues/
|
| 8 |
+
Project-URL: Funding, https://github.com/sponsors/Julian
|
| 9 |
+
Project-URL: Tidelift, https://tidelift.com/subscription/pkg/pypi-jsonschema-specifications?utm_source=pypi-jsonschema-specifications&utm_medium=referral&utm_campaign=pypi-link
|
| 10 |
+
Project-URL: Source, https://github.com/python-jsonschema/jsonschema-specifications
|
| 11 |
+
Author-email: Julian Berman <Julian+jsonschema-specifications@GrayVines.com>
|
| 12 |
+
License-Expression: MIT
|
| 13 |
+
License-File: COPYING
|
| 14 |
+
Keywords: data validation,json,json schema,jsonschema,validation
|
| 15 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 16 |
+
Classifier: Intended Audience :: Developers
|
| 17 |
+
Classifier: Operating System :: OS Independent
|
| 18 |
+
Classifier: Programming Language :: Python
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 24 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 25 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 26 |
+
Classifier: Topic :: File Formats :: JSON
|
| 27 |
+
Classifier: Topic :: File Formats :: JSON :: JSON Schema
|
| 28 |
+
Requires-Python: >=3.9
|
| 29 |
+
Requires-Dist: referencing>=0.31.0
|
| 30 |
+
Description-Content-Type: text/x-rst
|
| 31 |
+
|
| 32 |
+
=============================
|
| 33 |
+
``jsonschema-specifications``
|
| 34 |
+
=============================
|
| 35 |
+
|
| 36 |
+
|PyPI| |Pythons| |CI| |ReadTheDocs|
|
| 37 |
+
|
| 38 |
+
JSON support files from the `JSON Schema Specifications <https://json-schema.org/specification.html>`_ (metaschemas, vocabularies, etc.), packaged for runtime access from Python as a `referencing-based Schema Registry <https://referencing.readthedocs.io/en/stable/api/#referencing.Registry>`_.
|
| 39 |
+
|
| 40 |
+
.. |PyPI| image:: https://img.shields.io/pypi/v/jsonschema-specifications.svg
|
| 41 |
+
:alt: PyPI version
|
| 42 |
+
:target: https://pypi.org/project/jsonschema-specifications/
|
| 43 |
+
|
| 44 |
+
.. |Pythons| image:: https://img.shields.io/pypi/pyversions/jsonschema-specifications.svg
|
| 45 |
+
:alt: Supported Python versions
|
| 46 |
+
:target: https://pypi.org/project/jsonschema-specifications/
|
| 47 |
+
|
| 48 |
+
.. |CI| image:: https://github.com/python-jsonschema/jsonschema-specifications/workflows/CI/badge.svg
|
| 49 |
+
:alt: Build status
|
| 50 |
+
:target: https://github.com/python-jsonschema/jsonschema-specifications/actions?query=workflow%3ACI
|
| 51 |
+
|
| 52 |
+
.. |ReadTheDocs| image:: https://readthedocs.org/projects/jsonschema-specifications/badge/?version=stable&style=flat
|
| 53 |
+
:alt: ReadTheDocs status
|
| 54 |
+
:target: https://jsonschema-specifications.readthedocs.io/en/stable/
|
venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/RECORD
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
jsonschema_specifications-2025.9.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
jsonschema_specifications-2025.9.1.dist-info/METADATA,sha256=NavUF1fzK06iR1aSDe1HtwFz13y8BSpabTq1g7Lo2J0,2907
|
| 3 |
+
jsonschema_specifications-2025.9.1.dist-info/RECORD,,
|
| 4 |
+
jsonschema_specifications-2025.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
| 5 |
+
jsonschema_specifications-2025.9.1.dist-info/licenses/COPYING,sha256=QtzWNJX4e063x3V6-jebtVpT-Ur9el9lfZrfVyNuUVw,1057
|
| 6 |
+
jsonschema_specifications/__init__.py,sha256=qoTB2DKY7qvNrGhMPH6gtmAJRLilmVQ-fFZwT6ryqw0,386
|
| 7 |
+
jsonschema_specifications/__pycache__/__init__.cpython-314.pyc,,
|
| 8 |
+
jsonschema_specifications/__pycache__/_core.cpython-314.pyc,,
|
| 9 |
+
jsonschema_specifications/_core.py,sha256=tFhc1CMleJ3AJOK_bjxOpFQTdrsUClFGfFxPBU_CebM,1140
|
| 10 |
+
jsonschema_specifications/schemas/draft201909/metaschema.json,sha256=e3YbPhIfCgyh6ioLjizIVrz4AWBLgmjXG6yqICvAwTs,1785
|
| 11 |
+
jsonschema_specifications/schemas/draft201909/vocabularies/applicator,sha256=aJUQDplyb7sQcFhRK77D7P1LJOj9L6zuPlBe5ysNTDE,1860
|
| 12 |
+
jsonschema_specifications/schemas/draft201909/vocabularies/content,sha256=m31PVaTi_bAsQwBo_f-rxzKt3OI42j8d8mkCScM1MnQ,517
|
| 13 |
+
jsonschema_specifications/schemas/draft201909/vocabularies/core,sha256=taLElX9kldClCB8ECevooU5BOayyA_x0hHH47eKvWyw,1531
|
| 14 |
+
jsonschema_specifications/schemas/draft201909/vocabularies/format,sha256=UOu_55BhGoSbjMQAoJwdDg-2q1wNQ6DyIgH9NiUFa_Q,403
|
| 15 |
+
jsonschema_specifications/schemas/draft201909/vocabularies/meta-data,sha256=1H4kRd1qgicaKY2DzGxsuNSuHhXg3Fa-zTehY-zwEoY,892
|
| 16 |
+
jsonschema_specifications/schemas/draft201909/vocabularies/validation,sha256=HlJsHTNac0gF_ILPV5jBK5YK19olF8Zs2lobCTWcPBw,2834
|
| 17 |
+
jsonschema_specifications/schemas/draft202012/metaschema.json,sha256=Qdp29a-3zgYtJI92JGOpL3ykfk4PkFsiS6av7vkd7Q8,2452
|
| 18 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/applicator,sha256=xKbkFHuR_vf-ptwFjLG_k0AvdBS3ZXiosWqvHa1qrO8,1659
|
| 19 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/content,sha256=CDQ3R3ZOSlgUJieTz01lIFenkThjxZUNQyl-jh_axbY,519
|
| 20 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/core,sha256=wtEqjk3RHTNt_IOj9mOqTGnwtJs76wlP_rJbUxb0gD0,1564
|
| 21 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/format-annotation,sha256=q8d1rf79idIjWBcNm_k_Tr0jSVY7u-3WDwK-98gSvMA,448
|
| 22 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/format-assertion,sha256=xSJCuaG7eGsmw-gset1CjDH5yW5XXc6Z5W6l_qptogw,445
|
| 23 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/meta-data,sha256=j3bW4U9Bubku-TO3CM3FFEyLUmhlGtEZGEhfsXVPHHY,892
|
| 24 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/unevaluated,sha256=Lb-8tzmUtnCwl2SSre4f_7RsIWgnhNL1pMpWH54tDLQ,506
|
| 25 |
+
jsonschema_specifications/schemas/draft202012/vocabularies/validation,sha256=cBCjHlQfMtK-ch4t40jfdcmzaHaj7TBId_wKvaHTelg,2834
|
| 26 |
+
jsonschema_specifications/schemas/draft3/metaschema.json,sha256=LPdfZENvtb43Si6qJ6uLfh_WUcm0ba6mxnsC_WTiRYs,2600
|
| 27 |
+
jsonschema_specifications/schemas/draft4/metaschema.json,sha256=4UidC0dV8CeTMCWR0_y48Htok6gqlPJIlfjk7fEbguI,4357
|
| 28 |
+
jsonschema_specifications/schemas/draft6/metaschema.json,sha256=wp386fVINcOgbAOzxdXsDtp3cGVo-cTffPvHVmpRAG0,4437
|
| 29 |
+
jsonschema_specifications/schemas/draft7/metaschema.json,sha256=PVOSCIJhYGxVm2A_OFMpyfGrRbXWZ-uZBodFOwVdQF4,4819
|
| 30 |
+
jsonschema_specifications/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 31 |
+
jsonschema_specifications/tests/__pycache__/__init__.cpython-314.pyc,,
|
| 32 |
+
jsonschema_specifications/tests/__pycache__/test_jsonschema_specifications.cpython-314.pyc,,
|
| 33 |
+
jsonschema_specifications/tests/test_jsonschema_specifications.py,sha256=WkbYRW6A6FoZ0rivShfqVLSCsAiHJ2x8TxqECJTXPTY,1106
|
venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: hatchling 1.27.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
venv/lib/python3.14/site-packages/jsonschema_specifications-2025.9.1.dist-info/licenses/COPYING
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2022 Julian Berman
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 5 |
+
in the Software without restriction, including without limitation the rights
|
| 6 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in
|
| 11 |
+
all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 19 |
+
THE SOFTWARE.
|
venv/lib/python3.14/site-packages/jsonschema_specifications/schemas/draft7/metaschema.json
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 3 |
+
"$id": "http://json-schema.org/draft-07/schema#",
|
| 4 |
+
"title": "Core schema meta-schema",
|
| 5 |
+
"definitions": {
|
| 6 |
+
"schemaArray": {
|
| 7 |
+
"type": "array",
|
| 8 |
+
"minItems": 1,
|
| 9 |
+
"items": { "$ref": "#" }
|
| 10 |
+
},
|
| 11 |
+
"nonNegativeInteger": {
|
| 12 |
+
"type": "integer",
|
| 13 |
+
"minimum": 0
|
| 14 |
+
},
|
| 15 |
+
"nonNegativeIntegerDefault0": {
|
| 16 |
+
"allOf": [
|
| 17 |
+
{ "$ref": "#/definitions/nonNegativeInteger" },
|
| 18 |
+
{ "default": 0 }
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
"simpleTypes": {
|
| 22 |
+
"enum": [
|
| 23 |
+
"array",
|
| 24 |
+
"boolean",
|
| 25 |
+
"integer",
|
| 26 |
+
"null",
|
| 27 |
+
"number",
|
| 28 |
+
"object",
|
| 29 |
+
"string"
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
"stringArray": {
|
| 33 |
+
"type": "array",
|
| 34 |
+
"items": { "type": "string" },
|
| 35 |
+
"uniqueItems": true,
|
| 36 |
+
"default": []
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"type": ["object", "boolean"],
|
| 40 |
+
"properties": {
|
| 41 |
+
"$id": {
|
| 42 |
+
"type": "string",
|
| 43 |
+
"format": "uri-reference"
|
| 44 |
+
},
|
| 45 |
+
"$schema": {
|
| 46 |
+
"type": "string",
|
| 47 |
+
"format": "uri"
|
| 48 |
+
},
|
| 49 |
+
"$ref": {
|
| 50 |
+
"type": "string",
|
| 51 |
+
"format": "uri-reference"
|
| 52 |
+
},
|
| 53 |
+
"$comment": {
|
| 54 |
+
"type": "string"
|
| 55 |
+
},
|
| 56 |
+
"title": {
|
| 57 |
+
"type": "string"
|
| 58 |
+
},
|
| 59 |
+
"description": {
|
| 60 |
+
"type": "string"
|
| 61 |
+
},
|
| 62 |
+
"default": true,
|
| 63 |
+
"readOnly": {
|
| 64 |
+
"type": "boolean",
|
| 65 |
+
"default": false
|
| 66 |
+
},
|
| 67 |
+
"examples": {
|
| 68 |
+
"type": "array",
|
| 69 |
+
"items": true
|
| 70 |
+
},
|
| 71 |
+
"multipleOf": {
|
| 72 |
+
"type": "number",
|
| 73 |
+
"exclusiveMinimum": 0
|
| 74 |
+
},
|
| 75 |
+
"maximum": {
|
| 76 |
+
"type": "number"
|
| 77 |
+
},
|
| 78 |
+
"exclusiveMaximum": {
|
| 79 |
+
"type": "number"
|
| 80 |
+
},
|
| 81 |
+
"minimum": {
|
| 82 |
+
"type": "number"
|
| 83 |
+
},
|
| 84 |
+
"exclusiveMinimum": {
|
| 85 |
+
"type": "number"
|
| 86 |
+
},
|
| 87 |
+
"maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
|
| 88 |
+
"minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
| 89 |
+
"pattern": {
|
| 90 |
+
"type": "string",
|
| 91 |
+
"format": "regex"
|
| 92 |
+
},
|
| 93 |
+
"additionalItems": { "$ref": "#" },
|
| 94 |
+
"items": {
|
| 95 |
+
"anyOf": [
|
| 96 |
+
{ "$ref": "#" },
|
| 97 |
+
{ "$ref": "#/definitions/schemaArray" }
|
| 98 |
+
],
|
| 99 |
+
"default": true
|
| 100 |
+
},
|
| 101 |
+
"maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
|
| 102 |
+
"minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
| 103 |
+
"uniqueItems": {
|
| 104 |
+
"type": "boolean",
|
| 105 |
+
"default": false
|
| 106 |
+
},
|
| 107 |
+
"contains": { "$ref": "#" },
|
| 108 |
+
"maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
|
| 109 |
+
"minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
|
| 110 |
+
"required": { "$ref": "#/definitions/stringArray" },
|
| 111 |
+
"additionalProperties": { "$ref": "#" },
|
| 112 |
+
"definitions": {
|
| 113 |
+
"type": "object",
|
| 114 |
+
"additionalProperties": { "$ref": "#" },
|
| 115 |
+
"default": {}
|
| 116 |
+
},
|
| 117 |
+
"properties": {
|
| 118 |
+
"type": "object",
|
| 119 |
+
"additionalProperties": { "$ref": "#" },
|
| 120 |
+
"default": {}
|
| 121 |
+
},
|
| 122 |
+
"patternProperties": {
|
| 123 |
+
"type": "object",
|
| 124 |
+
"additionalProperties": { "$ref": "#" },
|
| 125 |
+
"propertyNames": { "format": "regex" },
|
| 126 |
+
"default": {}
|
| 127 |
+
},
|
| 128 |
+
"dependencies": {
|
| 129 |
+
"type": "object",
|
| 130 |
+
"additionalProperties": {
|
| 131 |
+
"anyOf": [
|
| 132 |
+
{ "$ref": "#" },
|
| 133 |
+
{ "$ref": "#/definitions/stringArray" }
|
| 134 |
+
]
|
| 135 |
+
}
|
| 136 |
+
},
|
| 137 |
+
"propertyNames": { "$ref": "#" },
|
| 138 |
+
"const": true,
|
| 139 |
+
"enum": {
|
| 140 |
+
"type": "array",
|
| 141 |
+
"items": true
|
| 142 |
+
},
|
| 143 |
+
"type": {
|
| 144 |
+
"anyOf": [
|
| 145 |
+
{ "$ref": "#/definitions/simpleTypes" },
|
| 146 |
+
{
|
| 147 |
+
"type": "array",
|
| 148 |
+
"items": { "$ref": "#/definitions/simpleTypes" },
|
| 149 |
+
"minItems": 1,
|
| 150 |
+
"uniqueItems": true
|
| 151 |
+
}
|
| 152 |
+
]
|
| 153 |
+
},
|
| 154 |
+
"format": { "type": "string" },
|
| 155 |
+
"contentMediaType": { "type": "string" },
|
| 156 |
+
"contentEncoding": { "type": "string" },
|
| 157 |
+
"if": {"$ref": "#"},
|
| 158 |
+
"then": {"$ref": "#"},
|
| 159 |
+
"else": {"$ref": "#"},
|
| 160 |
+
"allOf": { "$ref": "#/definitions/schemaArray" },
|
| 161 |
+
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
| 162 |
+
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
| 163 |
+
"not": { "$ref": "#" }
|
| 164 |
+
},
|
| 165 |
+
"default": true
|
| 166 |
+
}
|
venv/lib/python3.14/site-packages/jsonschema_specifications/tests/__init__.py
ADDED
|
File without changes
|
venv/lib/python3.14/site-packages/jsonschema_specifications/tests/test_jsonschema_specifications.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Mapping
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from jsonschema_specifications import REGISTRY
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_it_contains_metaschemas():
|
| 10 |
+
schema = REGISTRY.contents("http://json-schema.org/draft-07/schema#")
|
| 11 |
+
assert isinstance(schema, Mapping)
|
| 12 |
+
assert schema["$id"] == "http://json-schema.org/draft-07/schema#"
|
| 13 |
+
assert schema["title"] == "Core schema meta-schema"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_it_is_crawled():
|
| 17 |
+
assert REGISTRY.crawl() == REGISTRY
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@pytest.mark.parametrize(
|
| 21 |
+
"ignored_relative_path",
|
| 22 |
+
["schemas/.DS_Store", "schemas/draft7/.DS_Store"],
|
| 23 |
+
)
|
| 24 |
+
def test_it_copes_with_dotfiles(ignored_relative_path):
|
| 25 |
+
"""
|
| 26 |
+
Ignore files like .DS_Store if someone has actually caused one to exist.
|
| 27 |
+
|
| 28 |
+
We test here through the private interface as of course the global has
|
| 29 |
+
already loaded our schemas.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
import jsonschema_specifications
|
| 33 |
+
|
| 34 |
+
package = Path(jsonschema_specifications.__file__).parent
|
| 35 |
+
|
| 36 |
+
ignored = package / ignored_relative_path
|
| 37 |
+
ignored.touch()
|
| 38 |
+
try:
|
| 39 |
+
list(jsonschema_specifications._schemas())
|
| 40 |
+
finally:
|
| 41 |
+
ignored.unlink()
|
venv/lib/python3.14/site-packages/markdown_it/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A Python port of Markdown-It"""
|
| 2 |
+
|
| 3 |
+
__all__ = ("MarkdownIt",)
|
| 4 |
+
__version__ = "4.3.0"
|
| 5 |
+
|
| 6 |
+
from .main import MarkdownIt
|
venv/lib/python3.14/site-packages/markdown_it/_compat.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
venv/lib/python3.14/site-packages/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)
|
venv/lib/python3.14/site-packages/markdown_it/cli/__init__.py
ADDED
|
File without changes
|
venv/lib/python3.14/site-packages/markdown_it/cli/parse.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
CLI interface to markdown-it-py
|
| 3 |
+
|
| 4 |
+
Parse one or more markdown files, convert each to HTML, and print to stdout.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
from collections.abc import Iterable, Sequence
|
| 11 |
+
import sys
|
| 12 |
+
|
| 13 |
+
from markdown_it import __version__
|
| 14 |
+
from markdown_it.main import MarkdownIt
|
| 15 |
+
|
| 16 |
+
version_str = f"markdown-it-py [version {__version__}]"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _eof_keys() -> str:
|
| 20 |
+
"""The keys that end interactive input (send EOF) on this platform."""
|
| 21 |
+
return "Ctrl-Z then Enter" if sys.platform == "win32" else "Ctrl-D"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main(args: Sequence[str] | None = None) -> int:
|
| 25 |
+
namespace = parse_args(args)
|
| 26 |
+
md = MarkdownIt()
|
| 27 |
+
if namespace.enable_tables:
|
| 28 |
+
md.enable("table")
|
| 29 |
+
if namespace.filenames:
|
| 30 |
+
convert(namespace.filenames, md)
|
| 31 |
+
elif namespace.stdin:
|
| 32 |
+
convert_stdin(md)
|
| 33 |
+
else:
|
| 34 |
+
interactive(md)
|
| 35 |
+
return 0
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def convert(filenames: Iterable[str], md: MarkdownIt | None = None) -> None:
|
| 39 |
+
for filename in filenames:
|
| 40 |
+
convert_file(filename, md)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def convert_stdin(md: MarkdownIt | None = None) -> None:
|
| 44 |
+
"""
|
| 45 |
+
Parse a Markdown file and dump the output to stdout.
|
| 46 |
+
|
| 47 |
+
Use the supplied parser, creating a default only when it is None.
|
| 48 |
+
"""
|
| 49 |
+
try:
|
| 50 |
+
rendered = (MarkdownIt() if md is None else md).render(sys.stdin.read())
|
| 51 |
+
print(rendered, end="")
|
| 52 |
+
except OSError:
|
| 53 |
+
sys.stderr.write("Cannot parse Markdown from the standard input.\n")
|
| 54 |
+
sys.exit(1)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def convert_file(filename: str, md: MarkdownIt | None = None) -> None:
|
| 58 |
+
"""
|
| 59 |
+
Parse a Markdown file and dump the output to stdout.
|
| 60 |
+
|
| 61 |
+
Use the supplied parser, creating a default only when it is None.
|
| 62 |
+
"""
|
| 63 |
+
try:
|
| 64 |
+
with open(filename, encoding="utf8", errors="ignore") as fin:
|
| 65 |
+
rendered = (MarkdownIt() if md is None else md).render(fin.read())
|
| 66 |
+
print(rendered, end="")
|
| 67 |
+
except OSError:
|
| 68 |
+
sys.stderr.write(f'Cannot open file "{filename}".\n')
|
| 69 |
+
sys.exit(1)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def interactive(md: MarkdownIt | None = None) -> None:
|
| 73 |
+
"""
|
| 74 |
+
Parse user input, dump to stdout, rinse and repeat.
|
| 75 |
+
Python REPL style.
|
| 76 |
+
|
| 77 |
+
Use the supplied parser, creating a default only when it is None.
|
| 78 |
+
"""
|
| 79 |
+
md = MarkdownIt() if md is None else md
|
| 80 |
+
print_heading()
|
| 81 |
+
contents = []
|
| 82 |
+
more = False
|
| 83 |
+
while True:
|
| 84 |
+
try:
|
| 85 |
+
prompt, more = ("... ", True) if more else (">>> ", True)
|
| 86 |
+
contents.append(input(prompt) + "\n")
|
| 87 |
+
except EOFError:
|
| 88 |
+
print("\n" + md.render("".join(contents)), end="")
|
| 89 |
+
more = False
|
| 90 |
+
contents = []
|
| 91 |
+
except KeyboardInterrupt:
|
| 92 |
+
print("\nExiting.")
|
| 93 |
+
break
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def parse_args(args: Sequence[str] | None) -> argparse.Namespace:
|
| 97 |
+
"""Parse input CLI arguments."""
|
| 98 |
+
parser = argparse.ArgumentParser(
|
| 99 |
+
description="Parse one or more markdown files, "
|
| 100 |
+
"convert each to HTML, and print to stdout",
|
| 101 |
+
# NOTE: Remember to update README.md w/ the output of `markdown-it -h`
|
| 102 |
+
epilog=(
|
| 103 |
+
f"""
|
| 104 |
+
Interactive:
|
| 105 |
+
|
| 106 |
+
$ markdown-it
|
| 107 |
+
markdown-it-py [version {__version__}] (interactive)
|
| 108 |
+
Type {_eof_keys()} to complete input, or Ctrl-C to exit.
|
| 109 |
+
>>> # Example
|
| 110 |
+
... > markdown *input*
|
| 111 |
+
...
|
| 112 |
+
<h1>Example</h1>
|
| 113 |
+
<blockquote>
|
| 114 |
+
<p>markdown <em>input</em></p>
|
| 115 |
+
</blockquote>
|
| 116 |
+
|
| 117 |
+
Batch:
|
| 118 |
+
|
| 119 |
+
$ markdown-it README.md README.footer.md > index.html
|
| 120 |
+
"""
|
| 121 |
+
),
|
| 122 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 123 |
+
)
|
| 124 |
+
parser.add_argument("-v", "--version", action="version", version=version_str)
|
| 125 |
+
parser.add_argument(
|
| 126 |
+
"--stdin", action="store_true", help="read Markdown from standard input"
|
| 127 |
+
)
|
| 128 |
+
parser.add_argument(
|
| 129 |
+
"--enable-tables", action="store_true", help="enable table parsing"
|
| 130 |
+
)
|
| 131 |
+
parser.add_argument(
|
| 132 |
+
"filenames", nargs="*", help="specify an optional list of files to convert"
|
| 133 |
+
)
|
| 134 |
+
return parser.parse_args(args)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def print_heading() -> None:
|
| 138 |
+
print(f"{version_str} (interactive)")
|
| 139 |
+
print(f"Type {_eof_keys()} to complete input, or Ctrl-C to exit.")
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
if __name__ == "__main__":
|
| 143 |
+
exit_code = main(sys.argv[1:])
|
| 144 |
+
sys.exit(exit_code)
|
venv/lib/python3.14/site-packages/markdown_it/common/__init__.py
ADDED
|
File without changes
|
venv/lib/python3.14/site-packages/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()}
|
venv/lib/python3.14/site-packages/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 |
+
]
|
venv/lib/python3.14/site-packages/markdown_it/common/html_re.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# No leading `^`: applied via `.match(src, pos)`, which anchors at `pos`
|
| 25 |
+
# without slicing `src[pos:]` (an O(len) copy per call, quadratic over a run).
|
| 26 |
+
"(?:"
|
| 27 |
+
+ open_tag
|
| 28 |
+
+ "|"
|
| 29 |
+
+ close_tag
|
| 30 |
+
+ "|"
|
| 31 |
+
+ comment
|
| 32 |
+
+ "|"
|
| 33 |
+
+ processing
|
| 34 |
+
+ "|"
|
| 35 |
+
+ declaration
|
| 36 |
+
+ "|"
|
| 37 |
+
+ cdata
|
| 38 |
+
+ ")"
|
| 39 |
+
)
|
| 40 |
+
HTML_OPEN_CLOSE_TAG_STR = "^(?:" + open_tag + "|" + close_tag + ")"
|
| 41 |
+
HTML_OPEN_CLOSE_TAG_RE = re.compile(HTML_OPEN_CLOSE_TAG_STR)
|
venv/lib/python3.14/site-packages/markdown_it/common/normalize_url.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
if not parsed.hostname or ":" not in parsed.hostname:
|
| 38 |
+
return mdurl.encode(mdurl.format(parsed))
|
| 39 |
+
|
| 40 |
+
# Encode components before format() adds the IPv6 host brackets.
|
| 41 |
+
return mdurl.format(
|
| 42 |
+
parsed._replace(
|
| 43 |
+
protocol=parsed.protocol and mdurl.encode(parsed.protocol),
|
| 44 |
+
auth=parsed.auth and mdurl.encode(parsed.auth),
|
| 45 |
+
hostname=mdurl.encode(parsed.hostname),
|
| 46 |
+
pathname=parsed.pathname and mdurl.encode(parsed.pathname),
|
| 47 |
+
search=parsed.search and mdurl.encode(parsed.search),
|
| 48 |
+
hash=parsed.hash and mdurl.encode(parsed.hash),
|
| 49 |
+
)
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def normalizeLinkText(url: str) -> str:
|
| 54 |
+
"""Normalize autolink content
|
| 55 |
+
|
| 56 |
+
::
|
| 57 |
+
|
| 58 |
+
<destination>
|
| 59 |
+
~~~~~~~~~~~
|
| 60 |
+
"""
|
| 61 |
+
parsed = mdurl.parse(url, slashes_denote_host=True)
|
| 62 |
+
|
| 63 |
+
# Encode hostnames in urls like:
|
| 64 |
+
# `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
|
| 65 |
+
#
|
| 66 |
+
# We don't encode unknown schemas, because it's likely that we encode
|
| 67 |
+
# something we shouldn't (e.g. `skype:name` treated as `skype:host`)
|
| 68 |
+
#
|
| 69 |
+
if parsed.hostname and (
|
| 70 |
+
not parsed.protocol or parsed.protocol in RECODE_HOSTNAME_FOR
|
| 71 |
+
):
|
| 72 |
+
with suppress(Exception):
|
| 73 |
+
parsed = parsed._replace(hostname=_punycode.to_unicode(parsed.hostname))
|
| 74 |
+
|
| 75 |
+
# add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720
|
| 76 |
+
return mdurl.decode(mdurl.format(parsed), mdurl.DECODE_DEFAULT_CHARS + "%")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
BAD_PROTO_RE = re.compile(r"^(vbscript|javascript|file|data):")
|
| 80 |
+
GOOD_DATA_RE = re.compile(r"^data:image\/(gif|png|jpeg|webp);")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def validateLink(url: str, validator: Callable[[str], bool] | None = None) -> bool:
|
| 84 |
+
"""Validate URL link is allowed in output.
|
| 85 |
+
|
| 86 |
+
This validator can prohibit more than really needed to prevent XSS.
|
| 87 |
+
It's a tradeoff to keep code simple and to be secure by default.
|
| 88 |
+
|
| 89 |
+
Note: url should be normalized at this point, and existing entities decoded.
|
| 90 |
+
"""
|
| 91 |
+
if validator is not None:
|
| 92 |
+
return validator(url)
|
| 93 |
+
url = url.strip().lower()
|
| 94 |
+
return bool(GOOD_DATA_RE.search(url)) if BAD_PROTO_RE.search(url) else True
|
venv/lib/python3.14/site-packages/markdown_it/common/utils.py
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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: int | None = 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 |
+
#: The characters ``String.prototype.trim`` removes in JavaScript, which is
|
| 195 |
+
#: what upstream markdown-it strips, minus U+FEFF.
|
| 196 |
+
#:
|
| 197 |
+
#: ``str.strip()`` without an argument uses :py:meth:`str.isspace`, which also
|
| 198 |
+
#: removes U+001C, U+001D, U+001E, U+001F and U+0085. Those are not whitespace
|
| 199 |
+
#: in CommonMark and are not removed by ``trim``, so relying on it drops them
|
| 200 |
+
#: from the output and makes two different reference labels compare equal.
|
| 201 |
+
#:
|
| 202 |
+
#: U+FEFF is deliberately excluded: ``trim`` does remove it, and that has the
|
| 203 |
+
#: very label folding effect this constant exists to avoid.
|
| 204 |
+
MD_TRIM_CHARS = "".join(
|
| 205 |
+
chr(code)
|
| 206 |
+
for code in sorted(MD_WHITESPACE | set(range(0x2000, 0x200B)) | {0x2028, 0x2029})
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
#: A run of one or more characters from :data:`MD_TRIM_CHARS`.
|
| 211 |
+
MD_TRIM_RE = re.compile("[" + re.escape(MD_TRIM_CHARS) + "]+")
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def mdTrim(string: str) -> str:
|
| 215 |
+
"""Strip leading and trailing whitespace, using the CommonMark set."""
|
| 216 |
+
return string.strip(MD_TRIM_CHARS)
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
# //////////////////////////////////////////////////////////////////////////////
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def isPunctChar(ch: str) -> bool:
|
| 223 |
+
"""Check if character is a punctuation character."""
|
| 224 |
+
return unicodedata.category(ch).startswith(("P", "S"))
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
MD_ASCII_PUNCT = {
|
| 228 |
+
0x21, # /* ! */
|
| 229 |
+
0x22, # /* " */
|
| 230 |
+
0x23, # /* # */
|
| 231 |
+
0x24, # /* $ */
|
| 232 |
+
0x25, # /* % */
|
| 233 |
+
0x26, # /* & */
|
| 234 |
+
0x27, # /* ' */
|
| 235 |
+
0x28, # /* ( */
|
| 236 |
+
0x29, # /* ) */
|
| 237 |
+
0x2A, # /* * */
|
| 238 |
+
0x2B, # /* + */
|
| 239 |
+
0x2C, # /* , */
|
| 240 |
+
0x2D, # /* - */
|
| 241 |
+
0x2E, # /* . */
|
| 242 |
+
0x2F, # /* / */
|
| 243 |
+
0x3A, # /* : */
|
| 244 |
+
0x3B, # /* ; */
|
| 245 |
+
0x3C, # /* < */
|
| 246 |
+
0x3D, # /* = */
|
| 247 |
+
0x3E, # /* > */
|
| 248 |
+
0x3F, # /* ? */
|
| 249 |
+
0x40, # /* @ */
|
| 250 |
+
0x5B, # /* [ */
|
| 251 |
+
0x5C, # /* \ */
|
| 252 |
+
0x5D, # /* ] */
|
| 253 |
+
0x5E, # /* ^ */
|
| 254 |
+
0x5F, # /* _ */
|
| 255 |
+
0x60, # /* ` */
|
| 256 |
+
0x7B, # /* { */
|
| 257 |
+
0x7C, # /* | */
|
| 258 |
+
0x7D, # /* } */
|
| 259 |
+
0x7E, # /* ~ */
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def isMdAsciiPunct(ch: int) -> bool:
|
| 264 |
+
"""Markdown ASCII punctuation characters.
|
| 265 |
+
|
| 266 |
+
::
|
| 267 |
+
|
| 268 |
+
!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \\, ], ^, _, `, {, |, }, or ~
|
| 269 |
+
|
| 270 |
+
See http://spec.commonmark.org/0.15/#ascii-punctuation-character
|
| 271 |
+
|
| 272 |
+
Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
|
| 273 |
+
|
| 274 |
+
"""
|
| 275 |
+
return ch in MD_ASCII_PUNCT
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def normalizeReference(string: str) -> str:
|
| 279 |
+
"""Helper to unify [reference labels]."""
|
| 280 |
+
# Trim and collapse whitespace
|
| 281 |
+
#
|
| 282 |
+
string = MD_TRIM_RE.sub(" ", mdTrim(string))
|
| 283 |
+
|
| 284 |
+
# In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug
|
| 285 |
+
# fixed in v12 (couldn't find any details).
|
| 286 |
+
#
|
| 287 |
+
# So treat this one as a special case
|
| 288 |
+
# (remove this when node v10 is no longer supported).
|
| 289 |
+
#
|
| 290 |
+
# if ('ẞ'.toLowerCase() === 'Ṿ') {
|
| 291 |
+
# str = str.replace(/ẞ/g, 'ß')
|
| 292 |
+
# }
|
| 293 |
+
|
| 294 |
+
# .toLowerCase().toUpperCase() should get rid of all differences
|
| 295 |
+
# between letter variants.
|
| 296 |
+
#
|
| 297 |
+
# Simple .toLowerCase() doesn't normalize 125 code points correctly,
|
| 298 |
+
# and .toUpperCase doesn't normalize 6 of them (list of exceptions:
|
| 299 |
+
# İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently
|
| 300 |
+
# uppercased versions).
|
| 301 |
+
#
|
| 302 |
+
# Here's an example showing how it happens. Lets take greek letter omega:
|
| 303 |
+
# uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ)
|
| 304 |
+
#
|
| 305 |
+
# Unicode entries:
|
| 306 |
+
# 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8
|
| 307 |
+
# 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398
|
| 308 |
+
# 03D1;GREEK THETA SYMBOL;Ll;0;L;<compat> 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398
|
| 309 |
+
# 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L;<compat> 0398;;;;N;;;;03B8
|
| 310 |
+
#
|
| 311 |
+
# Case-insensitive comparison should treat all of them as equivalent.
|
| 312 |
+
#
|
| 313 |
+
# But .toLowerCase() doesn't change ϑ (it's already lowercase),
|
| 314 |
+
# and .toUpperCase() doesn't change ϴ (already uppercase).
|
| 315 |
+
#
|
| 316 |
+
# Applying first lower then upper case normalizes any character:
|
| 317 |
+
# '\u0398\u03f4\u03b8\u03d1'.toLowerCase().toUpperCase() === '\u0398\u0398\u0398\u0398'
|
| 318 |
+
#
|
| 319 |
+
# Note: this is equivalent to unicode case folding; unicode normalization
|
| 320 |
+
# is a different step that is not required here.
|
| 321 |
+
#
|
| 322 |
+
# Final result should be uppercased, because it's later stored in an object
|
| 323 |
+
# (this avoid a conflict with Object.prototype members,
|
| 324 |
+
# most notably, `__proto__`)
|
| 325 |
+
#
|
| 326 |
+
return string.lower().upper()
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
LINK_OPEN_RE = re.compile(r"^<a[>\s]", flags=re.IGNORECASE)
|
| 330 |
+
LINK_CLOSE_RE = re.compile(r"^</a\s*>", flags=re.IGNORECASE)
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
def isLinkOpen(string: str) -> bool:
|
| 334 |
+
return bool(LINK_OPEN_RE.search(string))
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
def isLinkClose(string: str) -> bool:
|
| 338 |
+
return bool(LINK_CLOSE_RE.search(string))
|
venv/lib/python3.14/site-packages/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
|
venv/lib/python3.14/site-packages/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
|
venv/lib/python3.14/site-packages/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
|
venv/lib/python3.14/site-packages/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
|
venv/lib/python3.14/site-packages/markdown_it/main.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"gfm-like2": presets.gfm_like2.make(),
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class MarkdownIt:
|
| 34 |
+
def __init__(
|
| 35 |
+
self,
|
| 36 |
+
config: str | PresetType = "commonmark",
|
| 37 |
+
options_update: Mapping[str, Any] | None = None,
|
| 38 |
+
*,
|
| 39 |
+
renderer_cls: Callable[[MarkdownIt], RendererProtocol] = RendererHTML,
|
| 40 |
+
):
|
| 41 |
+
"""Main parser class
|
| 42 |
+
|
| 43 |
+
:param config: name of configuration to load or a pre-defined dictionary
|
| 44 |
+
:param options_update: dictionary that will be merged into ``config["options"]``
|
| 45 |
+
:param renderer_cls: the class to load as the renderer:
|
| 46 |
+
``self.renderer = renderer_cls(self)
|
| 47 |
+
"""
|
| 48 |
+
# add modules
|
| 49 |
+
self.utils = utils
|
| 50 |
+
self.helpers = helpers
|
| 51 |
+
|
| 52 |
+
# initialise classes
|
| 53 |
+
self.inline = ParserInline()
|
| 54 |
+
self.block = ParserBlock()
|
| 55 |
+
self.core = ParserCore()
|
| 56 |
+
self.renderer = renderer_cls(self)
|
| 57 |
+
self.linkify = linkify_it.LinkifyIt() if linkify_it else None
|
| 58 |
+
|
| 59 |
+
# set the configuration
|
| 60 |
+
if options_update and not isinstance(options_update, Mapping):
|
| 61 |
+
# catch signature change where renderer_cls was not used as a key-word
|
| 62 |
+
raise TypeError(
|
| 63 |
+
f"options_update should be a mapping: {options_update}"
|
| 64 |
+
"\n(Perhaps you intended this to be the renderer_cls?)"
|
| 65 |
+
)
|
| 66 |
+
self.configure(config, options_update=options_update)
|
| 67 |
+
|
| 68 |
+
def __repr__(self) -> str:
|
| 69 |
+
return f"{self.__class__.__module__}.{self.__class__.__name__}()"
|
| 70 |
+
|
| 71 |
+
@overload
|
| 72 |
+
def __getitem__(self, name: Literal["inline"]) -> ParserInline: ...
|
| 73 |
+
|
| 74 |
+
@overload
|
| 75 |
+
def __getitem__(self, name: Literal["block"]) -> ParserBlock: ...
|
| 76 |
+
|
| 77 |
+
@overload
|
| 78 |
+
def __getitem__(self, name: Literal["core"]) -> ParserCore: ...
|
| 79 |
+
|
| 80 |
+
@overload
|
| 81 |
+
def __getitem__(self, name: Literal["renderer"]) -> RendererProtocol: ...
|
| 82 |
+
|
| 83 |
+
@overload
|
| 84 |
+
def __getitem__(self, name: str) -> Any: ...
|
| 85 |
+
|
| 86 |
+
def __getitem__(self, name: str) -> Any:
|
| 87 |
+
return {
|
| 88 |
+
"inline": self.inline,
|
| 89 |
+
"block": self.block,
|
| 90 |
+
"core": self.core,
|
| 91 |
+
"renderer": self.renderer,
|
| 92 |
+
}[name]
|
| 93 |
+
|
| 94 |
+
def set(self, options: OptionsType) -> None:
|
| 95 |
+
"""Set parser options (in the same format as in constructor).
|
| 96 |
+
Probably, you will never need it, but you can change options after constructor call.
|
| 97 |
+
|
| 98 |
+
__Note:__ To achieve the best possible performance, don't modify a
|
| 99 |
+
`markdown-it` instance options on the fly. If you need multiple configurations
|
| 100 |
+
it's best to create multiple instances and initialize each with separate config.
|
| 101 |
+
"""
|
| 102 |
+
self.options = OptionsDict(options)
|
| 103 |
+
|
| 104 |
+
def configure(
|
| 105 |
+
self, presets: str | PresetType, options_update: Mapping[str, Any] | None = None
|
| 106 |
+
) -> MarkdownIt:
|
| 107 |
+
"""Batch load of all options and component settings.
|
| 108 |
+
This is an internal method, and you probably will not need it.
|
| 109 |
+
But if you will - see available presets and data structure
|
| 110 |
+
[here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)
|
| 111 |
+
|
| 112 |
+
We strongly recommend to use presets instead of direct config loads.
|
| 113 |
+
That will give better compatibility with next versions.
|
| 114 |
+
"""
|
| 115 |
+
if isinstance(presets, str):
|
| 116 |
+
if presets not in _PRESETS:
|
| 117 |
+
raise KeyError(f"Wrong `markdown-it` preset '{presets}', check name")
|
| 118 |
+
config = _PRESETS[presets]
|
| 119 |
+
else:
|
| 120 |
+
config = presets
|
| 121 |
+
|
| 122 |
+
if not config:
|
| 123 |
+
raise ValueError("Wrong `markdown-it` config, can't be empty")
|
| 124 |
+
|
| 125 |
+
options = config.get("options", {}) or {}
|
| 126 |
+
if options_update:
|
| 127 |
+
options = {**options, **options_update} # type: ignore
|
| 128 |
+
|
| 129 |
+
self.set(options)
|
| 130 |
+
|
| 131 |
+
if "components" in config:
|
| 132 |
+
for name, component in config["components"].items():
|
| 133 |
+
rules = component.get("rules", None)
|
| 134 |
+
if rules:
|
| 135 |
+
self[name].ruler.enableOnly(rules)
|
| 136 |
+
rules2 = component.get("rules2", None)
|
| 137 |
+
if rules2:
|
| 138 |
+
self[name].ruler2.enableOnly(rules2)
|
| 139 |
+
|
| 140 |
+
return self
|
| 141 |
+
|
| 142 |
+
def get_all_rules(self) -> dict[str, list[str]]:
|
| 143 |
+
"""Return the names of all active rules."""
|
| 144 |
+
rules = {
|
| 145 |
+
chain: self[chain].ruler.get_all_rules()
|
| 146 |
+
for chain in ["core", "block", "inline"]
|
| 147 |
+
}
|
| 148 |
+
rules["inline2"] = self.inline.ruler2.get_all_rules()
|
| 149 |
+
return rules
|
| 150 |
+
|
| 151 |
+
def get_active_rules(self) -> dict[str, list[str]]:
|
| 152 |
+
"""Return the names of all active rules."""
|
| 153 |
+
rules = {
|
| 154 |
+
chain: self[chain].ruler.get_active_rules()
|
| 155 |
+
for chain in ["core", "block", "inline"]
|
| 156 |
+
}
|
| 157 |
+
rules["inline2"] = self.inline.ruler2.get_active_rules()
|
| 158 |
+
return rules
|
| 159 |
+
|
| 160 |
+
def enable(
|
| 161 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 162 |
+
) -> MarkdownIt:
|
| 163 |
+
"""Enable list of rules. (chainable)
|
| 164 |
+
|
| 165 |
+
:param names: rule name or iterable of rule names to enable.
|
| 166 |
+
:param ignoreInvalid: set `true` to ignore errors when rule not found.
|
| 167 |
+
|
| 168 |
+
It will automatically find appropriate components,
|
| 169 |
+
containing rules with given names. If rule not found, and `ignoreInvalid`
|
| 170 |
+
not set - throws exception.
|
| 171 |
+
|
| 172 |
+
Example::
|
| 173 |
+
|
| 174 |
+
md = MarkdownIt().enable(['sub', 'sup']).disable('smartquotes')
|
| 175 |
+
|
| 176 |
+
"""
|
| 177 |
+
result = []
|
| 178 |
+
|
| 179 |
+
names = [names] if isinstance(names, str) else list(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 iterable of rule names to disable.
|
| 197 |
+
:param ignoreInvalid: set `true` to ignore errors when rule not found.
|
| 198 |
+
|
| 199 |
+
"""
|
| 200 |
+
result = []
|
| 201 |
+
|
| 202 |
+
names = [names] if isinstance(names, str) else list(names)
|
| 203 |
+
|
| 204 |
+
for chain in ["core", "block", "inline"]:
|
| 205 |
+
result.extend(self[chain].ruler.disable(names, True))
|
| 206 |
+
result.extend(self.inline.ruler2.disable(names, True))
|
| 207 |
+
|
| 208 |
+
missed = [name for name in names if name not in result]
|
| 209 |
+
if missed and not ignoreInvalid:
|
| 210 |
+
raise ValueError(f"MarkdownIt. Failed to disable unknown rule(s): {missed}")
|
| 211 |
+
return self
|
| 212 |
+
|
| 213 |
+
@contextmanager
|
| 214 |
+
def reset_rules(self) -> Generator[None, None, None]:
|
| 215 |
+
"""A context manager, that will reset the current enabled rules on exit."""
|
| 216 |
+
chain_rules = self.get_active_rules()
|
| 217 |
+
yield
|
| 218 |
+
for chain, rules in chain_rules.items():
|
| 219 |
+
if chain != "inline2":
|
| 220 |
+
self[chain].ruler.enableOnly(rules)
|
| 221 |
+
self.inline.ruler2.enableOnly(chain_rules["inline2"])
|
| 222 |
+
|
| 223 |
+
def add_render_rule(
|
| 224 |
+
self, name: str, function: Callable[..., Any], fmt: str = "html"
|
| 225 |
+
) -> None:
|
| 226 |
+
"""Add a rule for rendering a particular Token type.
|
| 227 |
+
|
| 228 |
+
Only applied when ``renderer.__output__ == fmt``
|
| 229 |
+
|
| 230 |
+
:param name: must equal the ``type`` of the token(s) this should render
|
| 231 |
+
(e.g. ``"heading_open"``, ``"fence"``); it is not an arbitrary label.
|
| 232 |
+
If it does not match any token type actually produced by the active
|
| 233 |
+
rules, ``function`` will silently never be called.
|
| 234 |
+
"""
|
| 235 |
+
if self.renderer.__output__ == fmt:
|
| 236 |
+
self.renderer.rules[name] = function.__get__(self.renderer) # type: ignore
|
| 237 |
+
|
| 238 |
+
def use(
|
| 239 |
+
self, plugin: Callable[..., None], *params: Any, **options: Any
|
| 240 |
+
) -> MarkdownIt:
|
| 241 |
+
"""Load specified plugin with given params into current parser instance. (chainable)
|
| 242 |
+
|
| 243 |
+
It's just a sugar to call `plugin(md, params)` with curring.
|
| 244 |
+
|
| 245 |
+
Example::
|
| 246 |
+
|
| 247 |
+
def func(tokens, idx):
|
| 248 |
+
tokens[idx].content = tokens[idx].content.replace('foo', 'bar')
|
| 249 |
+
md = MarkdownIt().use(plugin, 'foo_replace', 'text', func)
|
| 250 |
+
|
| 251 |
+
"""
|
| 252 |
+
plugin(self, *params, **options)
|
| 253 |
+
return self
|
| 254 |
+
|
| 255 |
+
def parse(self, src: str, env: EnvType | None = None) -> list[Token]:
|
| 256 |
+
"""Parse the source string to a token stream
|
| 257 |
+
|
| 258 |
+
:param src: source string
|
| 259 |
+
:param env: environment sandbox
|
| 260 |
+
|
| 261 |
+
Parse input string and return list of block tokens (special token type
|
| 262 |
+
"inline" will contain list of inline tokens).
|
| 263 |
+
|
| 264 |
+
`env` is used to pass data between "distributed" rules and return additional
|
| 265 |
+
metadata like reference info, needed for the renderer. It also can be used to
|
| 266 |
+
inject data in specific cases. Usually, you will be ok to pass `{}`,
|
| 267 |
+
and then pass updated object to renderer.
|
| 268 |
+
"""
|
| 269 |
+
env = {} if env is None else env
|
| 270 |
+
if not isinstance(env, MutableMapping):
|
| 271 |
+
raise TypeError(f"Input data should be a MutableMapping, not {type(env)}")
|
| 272 |
+
if not isinstance(src, str):
|
| 273 |
+
raise TypeError(f"Input data should be a string, not {type(src)}")
|
| 274 |
+
state = StateCore(src, self, env)
|
| 275 |
+
self.core.process(state)
|
| 276 |
+
return state.tokens
|
| 277 |
+
|
| 278 |
+
def render(self, src: str, env: EnvType | None = None) -> Any:
|
| 279 |
+
"""Render markdown string into html. It does all magic for you :).
|
| 280 |
+
|
| 281 |
+
:param src: source string
|
| 282 |
+
:param env: environment sandbox
|
| 283 |
+
:returns: The output of the loaded renderer
|
| 284 |
+
|
| 285 |
+
`env` can be used to inject additional metadata (`{}` by default).
|
| 286 |
+
But you will not need it with high probability. See also comment
|
| 287 |
+
in [[MarkdownIt.parse]].
|
| 288 |
+
"""
|
| 289 |
+
env = {} if env is None else env
|
| 290 |
+
return self.renderer.render(self.parse(src, env), self.options, env)
|
| 291 |
+
|
| 292 |
+
def parseInline(self, src: str, env: EnvType | None = None) -> list[Token]:
|
| 293 |
+
"""The same as [[MarkdownIt.parse]] but skip all block rules.
|
| 294 |
+
|
| 295 |
+
:param src: source string
|
| 296 |
+
:param env: environment sandbox
|
| 297 |
+
|
| 298 |
+
It returns the
|
| 299 |
+
block tokens list with the single `inline` element, containing parsed inline
|
| 300 |
+
tokens in `children` property. Also updates `env` object.
|
| 301 |
+
"""
|
| 302 |
+
env = {} if env is None else env
|
| 303 |
+
if not isinstance(env, MutableMapping):
|
| 304 |
+
raise TypeError(f"Input data should be an MutableMapping, not {type(env)}")
|
| 305 |
+
if not isinstance(src, str):
|
| 306 |
+
raise TypeError(f"Input data should be a string, not {type(src)}")
|
| 307 |
+
state = StateCore(src, self, env)
|
| 308 |
+
state.inlineMode = True
|
| 309 |
+
self.core.process(state)
|
| 310 |
+
return state.tokens
|
| 311 |
+
|
| 312 |
+
def renderInline(self, src: str, env: EnvType | None = None) -> Any:
|
| 313 |
+
"""Similar to [[MarkdownIt.render]] but for single paragraph content.
|
| 314 |
+
|
| 315 |
+
:param src: source string
|
| 316 |
+
:param env: environment sandbox
|
| 317 |
+
|
| 318 |
+
Similar to [[MarkdownIt.render]] but for single paragraph content. Result
|
| 319 |
+
will NOT be wrapped into `<p>` tags.
|
| 320 |
+
"""
|
| 321 |
+
env = {} if env is None else env
|
| 322 |
+
return self.renderer.render(self.parseInline(src, env), self.options, env)
|
| 323 |
+
|
| 324 |
+
# link methods
|
| 325 |
+
|
| 326 |
+
def validateLink(self, url: str) -> bool:
|
| 327 |
+
"""Validate if the URL link is allowed in output.
|
| 328 |
+
|
| 329 |
+
This validator can prohibit more than really needed to prevent XSS.
|
| 330 |
+
It's a tradeoff to keep code simple and to be secure by default.
|
| 331 |
+
|
| 332 |
+
Note: the url should be normalized at this point, and existing entities decoded.
|
| 333 |
+
"""
|
| 334 |
+
return normalize_url.validateLink(url)
|
| 335 |
+
|
| 336 |
+
def normalizeLink(self, url: str) -> str:
|
| 337 |
+
"""Normalize destination URLs in links
|
| 338 |
+
|
| 339 |
+
::
|
| 340 |
+
|
| 341 |
+
[label]: destination 'title'
|
| 342 |
+
^^^^^^^^^^^
|
| 343 |
+
"""
|
| 344 |
+
return normalize_url.normalizeLink(url)
|
| 345 |
+
|
| 346 |
+
def normalizeLinkText(self, link: str) -> str:
|
| 347 |
+
"""Normalize autolink content
|
| 348 |
+
|
| 349 |
+
::
|
| 350 |
+
|
| 351 |
+
<destination>
|
| 352 |
+
~~~~~~~~~~~
|
| 353 |
+
"""
|
| 354 |
+
return normalize_url.normalizeLinkText(link)
|
venv/lib/python3.14/site-packages/markdown_it/parser_block.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
ok = False
|
| 87 |
+
for rule in rules:
|
| 88 |
+
ok = rule(state, line, endLine, False)
|
| 89 |
+
if ok:
|
| 90 |
+
if state.line <= line:
|
| 91 |
+
raise RuntimeError("block rule didn't increment state.line")
|
| 92 |
+
break
|
| 93 |
+
|
| 94 |
+
# this can only happen if user disables paragraph rule
|
| 95 |
+
if not ok:
|
| 96 |
+
raise RuntimeError("none of the block rules matched")
|
| 97 |
+
|
| 98 |
+
# set state.tight if we had an empty line before current tag
|
| 99 |
+
# i.e. latest empty line should not count
|
| 100 |
+
state.tight = not hasEmptyLines
|
| 101 |
+
|
| 102 |
+
line = state.line
|
| 103 |
+
|
| 104 |
+
# paragraph might "eat" one newline after it in nested lists
|
| 105 |
+
if (line - 1) < endLine and state.isEmpty(line - 1):
|
| 106 |
+
hasEmptyLines = True
|
| 107 |
+
|
| 108 |
+
if line < endLine and state.isEmpty(line):
|
| 109 |
+
hasEmptyLines = True
|
| 110 |
+
line += 1
|
| 111 |
+
state.line = line
|
| 112 |
+
|
| 113 |
+
def parse(
|
| 114 |
+
self, src: str, md: MarkdownIt, env: EnvType, outTokens: list[Token]
|
| 115 |
+
) -> list[Token] | None:
|
| 116 |
+
"""Process input string and push block tokens into `outTokens`."""
|
| 117 |
+
if not src:
|
| 118 |
+
return None
|
| 119 |
+
state = StateBlock(src, md, env, outTokens)
|
| 120 |
+
self.tokenize(state, state.line, state.lineMax)
|
| 121 |
+
return state.tokens
|
venv/lib/python3.14/site-packages/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)
|
venv/lib/python3.14/site-packages/markdown_it/parser_inline.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tokenizes paragraph content."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from collections.abc import Callable
|
| 6 |
+
import functools
|
| 7 |
+
import re
|
| 8 |
+
from typing import TYPE_CHECKING
|
| 9 |
+
|
| 10 |
+
from . import rules_inline
|
| 11 |
+
from .ruler import Ruler
|
| 12 |
+
from .rules_inline.state_inline import StateInline
|
| 13 |
+
from .token import Token
|
| 14 |
+
from .utils import EnvType
|
| 15 |
+
|
| 16 |
+
if TYPE_CHECKING:
|
| 17 |
+
from markdown_it import MarkdownIt
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Default set of characters that terminate a text token and allow inline rules to fire.
|
| 21 |
+
# '{}$%@~+=:' reserved for extensions.
|
| 22 |
+
# Note: Don't confuse with "Markdown ASCII Punctuation" chars.
|
| 23 |
+
# http://spec.commonmark.org/0.15/#ascii-punctuation-character
|
| 24 |
+
_DEFAULT_TERMINATORS: frozenset[str] = frozenset(
|
| 25 |
+
{
|
| 26 |
+
"\n",
|
| 27 |
+
"!",
|
| 28 |
+
"#",
|
| 29 |
+
"$",
|
| 30 |
+
"%",
|
| 31 |
+
"&",
|
| 32 |
+
"*",
|
| 33 |
+
"+",
|
| 34 |
+
"-",
|
| 35 |
+
":",
|
| 36 |
+
"<",
|
| 37 |
+
"=",
|
| 38 |
+
">",
|
| 39 |
+
"@",
|
| 40 |
+
"[",
|
| 41 |
+
"\\",
|
| 42 |
+
"]",
|
| 43 |
+
"^",
|
| 44 |
+
"_",
|
| 45 |
+
"`",
|
| 46 |
+
"{",
|
| 47 |
+
"}",
|
| 48 |
+
"~",
|
| 49 |
+
}
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# Lazily compiled regex for the default terminator set. The @cache ensures it is
|
| 54 |
+
# compiled at most once (on first ParserInline instantiation) and shared across all
|
| 55 |
+
# instances that have not added extra chars, keeping __init__ cost near zero.
|
| 56 |
+
@functools.cache
|
| 57 |
+
def _default_terminator_re() -> re.Pattern[str]:
|
| 58 |
+
return re.compile("[" + re.escape("".join(_DEFAULT_TERMINATORS)) + "]")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# Parser rules
|
| 62 |
+
RuleFuncInlineType = Callable[[StateInline, bool], bool]
|
| 63 |
+
"""(state: StateInline, silent: bool) -> matched: bool)
|
| 64 |
+
|
| 65 |
+
`silent` disables token generation, useful for lookahead.
|
| 66 |
+
"""
|
| 67 |
+
_rules: list[tuple[str, RuleFuncInlineType]] = [
|
| 68 |
+
("text", rules_inline.text),
|
| 69 |
+
("linkify", rules_inline.linkify),
|
| 70 |
+
("newline", rules_inline.newline),
|
| 71 |
+
("escape", rules_inline.escape),
|
| 72 |
+
("backticks", rules_inline.backtick),
|
| 73 |
+
("strikethrough", rules_inline.strikethrough.tokenize),
|
| 74 |
+
("emphasis", rules_inline.emphasis.tokenize),
|
| 75 |
+
("link", rules_inline.link),
|
| 76 |
+
("image", rules_inline.image),
|
| 77 |
+
("autolink", rules_inline.autolink),
|
| 78 |
+
("html_inline", rules_inline.html_inline),
|
| 79 |
+
("entity", rules_inline.entity),
|
| 80 |
+
]
|
| 81 |
+
|
| 82 |
+
# Note `rule2` ruleset was created specifically for emphasis/strikethrough
|
| 83 |
+
# post-processing and may be changed in the future.
|
| 84 |
+
#
|
| 85 |
+
# Don't use this for anything except pairs (plugins working with `balance_pairs`).
|
| 86 |
+
#
|
| 87 |
+
RuleFuncInline2Type = Callable[[StateInline], None]
|
| 88 |
+
_rules2: list[tuple[str, RuleFuncInline2Type]] = [
|
| 89 |
+
("balance_pairs", rules_inline.link_pairs),
|
| 90 |
+
("strikethrough", rules_inline.strikethrough.postProcess),
|
| 91 |
+
("emphasis", rules_inline.emphasis.postProcess),
|
| 92 |
+
# rules for pairs separate '**' into its own text tokens, which may be left unused,
|
| 93 |
+
# rule below merges unused segments back with the rest of the text
|
| 94 |
+
("fragments_join", rules_inline.fragments_join),
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class ParserInline:
|
| 99 |
+
def __init__(self) -> None:
|
| 100 |
+
self.ruler = Ruler[RuleFuncInlineType]()
|
| 101 |
+
for name, rule in _rules:
|
| 102 |
+
self.ruler.push(name, rule)
|
| 103 |
+
# Second ruler used for post-processing (e.g. in emphasis-like rules)
|
| 104 |
+
self.ruler2 = Ruler[RuleFuncInline2Type]()
|
| 105 |
+
for name, rule2 in _rules2:
|
| 106 |
+
self.ruler2.push(name, rule2)
|
| 107 |
+
# Characters that stop the text rule, allowing other inline rules to fire.
|
| 108 |
+
# _extra_terminator_chars is only allocated when add_terminator_char() is called
|
| 109 |
+
# with a char outside the defaults, keeping __init__ allocation-free.
|
| 110 |
+
self._extra_terminator_chars: set[str] = set()
|
| 111 |
+
# Pre-compiled regex shared with all default instances (no copy in the common path).
|
| 112 |
+
self.terminator_re: re.Pattern[str] = _default_terminator_re()
|
| 113 |
+
|
| 114 |
+
def add_terminator_char(self, ch: str) -> None:
|
| 115 |
+
"""Register a character that stops the ``text`` rule, allowing inline rules to fire.
|
| 116 |
+
|
| 117 |
+
This lets plugins declare which characters their inline rules react to,
|
| 118 |
+
mirroring the ``MARKER`` mechanism in the Rust markdown-it implementation.
|
| 119 |
+
|
| 120 |
+
:param ch: A single character to add to the terminator set.
|
| 121 |
+
"""
|
| 122 |
+
if ch not in _DEFAULT_TERMINATORS and ch not in self._extra_terminator_chars:
|
| 123 |
+
self._extra_terminator_chars.add(ch)
|
| 124 |
+
self.terminator_re = re.compile(
|
| 125 |
+
"["
|
| 126 |
+
+ re.escape(
|
| 127 |
+
"".join(_DEFAULT_TERMINATORS | self._extra_terminator_chars)
|
| 128 |
+
)
|
| 129 |
+
+ "]"
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
def skipToken(self, state: StateInline) -> None:
|
| 133 |
+
"""Skip single token by running all rules in validation mode;
|
| 134 |
+
returns `True` if any rule reported success
|
| 135 |
+
"""
|
| 136 |
+
ok = False
|
| 137 |
+
pos = state.pos
|
| 138 |
+
rules = self.ruler.getRules("")
|
| 139 |
+
maxNesting = state.md.options["maxNesting"]
|
| 140 |
+
cache = state.cache
|
| 141 |
+
|
| 142 |
+
if pos in cache:
|
| 143 |
+
state.pos = cache[pos]
|
| 144 |
+
return
|
| 145 |
+
|
| 146 |
+
if state.level < maxNesting:
|
| 147 |
+
for rule in rules:
|
| 148 |
+
# Increment state.level and decrement it later to limit recursion.
|
| 149 |
+
# It's harmless to do here, because no tokens are created.
|
| 150 |
+
# But ideally, we'd need a separate private state variable for this purpose.
|
| 151 |
+
state.level += 1
|
| 152 |
+
ok = rule(state, True)
|
| 153 |
+
state.level -= 1
|
| 154 |
+
if ok:
|
| 155 |
+
if state.pos <= pos:
|
| 156 |
+
raise RuntimeError("inline rule didn't increment state.pos")
|
| 157 |
+
break
|
| 158 |
+
else:
|
| 159 |
+
# Too much nesting, just skip until the end of the paragraph.
|
| 160 |
+
#
|
| 161 |
+
# NOTE: this will cause links to behave incorrectly in the following case,
|
| 162 |
+
# when an amount of `[` is exactly equal to `maxNesting + 1`:
|
| 163 |
+
#
|
| 164 |
+
# [[[[[[[[[[[[[[[[[[[[[foo]()
|
| 165 |
+
#
|
| 166 |
+
# TODO: remove this workaround when CM standard will allow nested links
|
| 167 |
+
# (we can replace it by preventing links from being parsed in
|
| 168 |
+
# validation mode)
|
| 169 |
+
#
|
| 170 |
+
state.pos = state.posMax
|
| 171 |
+
|
| 172 |
+
if not ok:
|
| 173 |
+
state.pos += 1
|
| 174 |
+
cache[pos] = state.pos
|
| 175 |
+
|
| 176 |
+
def tokenize(self, state: StateInline) -> None:
|
| 177 |
+
"""Generate tokens for input range."""
|
| 178 |
+
rules = self.ruler.getRules("")
|
| 179 |
+
end = state.posMax
|
| 180 |
+
maxNesting = state.md.options["maxNesting"]
|
| 181 |
+
|
| 182 |
+
while state.pos < end:
|
| 183 |
+
pos = state.pos
|
| 184 |
+
ok = False
|
| 185 |
+
# Try all possible rules.
|
| 186 |
+
# On success, rule should:
|
| 187 |
+
#
|
| 188 |
+
# - update `state.pos`
|
| 189 |
+
# - update `state.tokens`
|
| 190 |
+
# - return true
|
| 191 |
+
|
| 192 |
+
if state.level < maxNesting:
|
| 193 |
+
for rule in rules:
|
| 194 |
+
ok = rule(state, False)
|
| 195 |
+
if ok:
|
| 196 |
+
if state.pos <= pos:
|
| 197 |
+
raise RuntimeError("inline rule didn't increment state.pos")
|
| 198 |
+
break
|
| 199 |
+
|
| 200 |
+
if ok:
|
| 201 |
+
if state.pos >= end:
|
| 202 |
+
break
|
| 203 |
+
continue
|
| 204 |
+
|
| 205 |
+
state.append_pending(state.src[state.pos])
|
| 206 |
+
state.pos += 1
|
| 207 |
+
|
| 208 |
+
if state.pending:
|
| 209 |
+
state.pushPending()
|
| 210 |
+
|
| 211 |
+
def parse(
|
| 212 |
+
self, src: str, md: MarkdownIt, env: EnvType, tokens: list[Token]
|
| 213 |
+
) -> list[Token]:
|
| 214 |
+
"""Process input string and push inline tokens into `tokens`"""
|
| 215 |
+
state = StateInline(src, md, env, tokens)
|
| 216 |
+
self.tokenize(state)
|
| 217 |
+
rules2 = self.ruler2.getRules("")
|
| 218 |
+
for rule in rules2:
|
| 219 |
+
rule(state)
|
| 220 |
+
return state.tokens
|
venv/lib/python3.14/site-packages/markdown_it/port.yaml
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
`MarkdownIt` constructs its renderer with `renderer_cls(self)`, passing the
|
| 40 |
+
parser instance as a positional argument; JavaScript constructs its renderer
|
| 41 |
+
with no arguments. Custom renderer constructors must accept this argument.
|
| 42 |
+
`RendererHTML` accepts an optional `parser=None` argument but does not use it,
|
| 43 |
+
so it can also be instantiated directly without a parser.
|
| 44 |
+
- |
|
| 45 |
+
change render method signatures
|
| 46 |
+
`func(tokens, idx, options, env, slf)` to
|
| 47 |
+
`func(self, tokens, idx, options, env)`
|
| 48 |
+
- |
|
| 49 |
+
Extensions add render methods by format
|
| 50 |
+
`MarkdownIt.add_render_rule(name, function, fmt="html")`,
|
| 51 |
+
rather than `MarkdownIt.renderer.rules[name] = function`
|
| 52 |
+
and renderers should declare a class property `__output__ = "html"`.
|
| 53 |
+
This allows for extensibility to more than just HTML renderers
|
| 54 |
+
- inline tokens in tables are assigned a map (this is helpful for propagation to children)
|
venv/lib/python3.14/site-packages/markdown_it/presets/__init__.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ("commonmark", "default", "gfm_like", "gfm_like2", "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
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class gfm_like2: # noqa: N801
|
| 32 |
+
"""GitHub Flavoured Markdown (GFM) like, extended.
|
| 33 |
+
|
| 34 |
+
Builds on ``gfm-like`` and additionally enables:
|
| 35 |
+
|
| 36 |
+
- Task lists (``- [x] done``)
|
| 37 |
+
- Alerts (``> [!NOTE]``)
|
| 38 |
+
- Single-tilde strikethrough (``~text~`` in addition to ``~~text~~``)
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
@staticmethod
|
| 42 |
+
def make() -> PresetType:
|
| 43 |
+
config = gfm_like.make()
|
| 44 |
+
config["options"]["tasklists"] = True
|
| 45 |
+
config["options"]["tasklists_editable"] = False
|
| 46 |
+
config["options"]["alerts"] = True
|
| 47 |
+
config["options"]["strikethrough_single_tilde"] = True
|
| 48 |
+
return config
|
venv/lib/python3.14/site-packages/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 |
+
}
|
venv/lib/python3.14/site-packages/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 |
+
}
|
venv/lib/python3.14/site-packages/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 |
+
}
|
venv/lib/python3.14/site-packages/markdown_it/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Marker file for PEP 561
|
venv/lib/python3.14/site-packages/markdown_it/renderer.py
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 MD_TRIM_RE, escapeHtml, mdTrim, unescapeAll
|
| 16 |
+
from .token import Token
|
| 17 |
+
from .utils import EnvType, OptionsDict
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class RendererProtocol(Protocol):
|
| 21 |
+
"""The interface a renderer passed to ``MarkdownIt(renderer_cls=...)`` must have.
|
| 22 |
+
|
| 23 |
+
``MarkdownIt`` creates the renderer as ``renderer_cls(md)``, and its
|
| 24 |
+
``render`` and ``renderInline`` methods call only :meth:`render`.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
__output__: ClassVar[str]
|
| 28 |
+
"""The name of the output format, e.g. ``"html"``.
|
| 29 |
+
|
| 30 |
+
``MarkdownIt.add_render_rule`` only applies rules whose ``fmt`` matches it.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
def render(
|
| 34 |
+
self, tokens: Sequence[Token], options: OptionsDict, env: EnvType
|
| 35 |
+
) -> Any:
|
| 36 |
+
"""Render a token stream to the output format."""
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class RendererHTML(RendererProtocol):
|
| 40 |
+
"""Contains render rules for tokens. Can be updated and extended.
|
| 41 |
+
|
| 42 |
+
Example:
|
| 43 |
+
|
| 44 |
+
Each rule is called as independent static function with fixed signature:
|
| 45 |
+
|
| 46 |
+
::
|
| 47 |
+
|
| 48 |
+
class Renderer:
|
| 49 |
+
def token_type_name(self, tokens, idx, options, env) {
|
| 50 |
+
# ...
|
| 51 |
+
return renderedHTML
|
| 52 |
+
|
| 53 |
+
::
|
| 54 |
+
|
| 55 |
+
class CustomRenderer(RendererHTML):
|
| 56 |
+
def strong_open(self, tokens, idx, options, env):
|
| 57 |
+
return '<b>'
|
| 58 |
+
def strong_close(self, tokens, idx, options, env):
|
| 59 |
+
return '</b>'
|
| 60 |
+
|
| 61 |
+
md = MarkdownIt(renderer_cls=CustomRenderer)
|
| 62 |
+
|
| 63 |
+
result = md.render(...)
|
| 64 |
+
|
| 65 |
+
See https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js
|
| 66 |
+
for more details and examples.
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
__output__ = "html"
|
| 70 |
+
|
| 71 |
+
def __init__(self, parser: Any = None):
|
| 72 |
+
self.rules = {
|
| 73 |
+
k: v
|
| 74 |
+
for k, v in inspect.getmembers(self, predicate=inspect.ismethod)
|
| 75 |
+
if not k.startswith(("render", "_"))
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
def render(
|
| 79 |
+
self, tokens: Sequence[Token], options: OptionsDict, env: EnvType
|
| 80 |
+
) -> str:
|
| 81 |
+
"""Takes token stream and generates HTML.
|
| 82 |
+
|
| 83 |
+
:param tokens: list on block tokens to render
|
| 84 |
+
:param options: params of parser instance
|
| 85 |
+
:param env: additional data from parsed input
|
| 86 |
+
|
| 87 |
+
"""
|
| 88 |
+
# Collect the fragments and join them once: repeated ``str +=`` is only
|
| 89 |
+
# linear on interpreters that can extend a string in place (the default
|
| 90 |
+
# CPython build), and quadratic in the output size elsewhere (e.g. PyPy,
|
| 91 |
+
# GraalPy and free-threaded CPython 3.13).
|
| 92 |
+
out: list[str] = []
|
| 93 |
+
|
| 94 |
+
for i, token in enumerate(tokens):
|
| 95 |
+
if token.type == "inline":
|
| 96 |
+
if token.children:
|
| 97 |
+
out.append(self.renderInline(token.children, options, env))
|
| 98 |
+
elif token.type in self.rules:
|
| 99 |
+
out.append(self.rules[token.type](tokens, i, options, env))
|
| 100 |
+
else:
|
| 101 |
+
out.append(self.renderToken(tokens, i, options, env))
|
| 102 |
+
|
| 103 |
+
return "".join(out)
|
| 104 |
+
|
| 105 |
+
def renderInline(
|
| 106 |
+
self, tokens: Sequence[Token], options: OptionsDict, env: EnvType
|
| 107 |
+
) -> str:
|
| 108 |
+
"""The same as ``render``, but for single token of `inline` type.
|
| 109 |
+
|
| 110 |
+
:param tokens: list on block tokens to render
|
| 111 |
+
:param options: params of parser instance
|
| 112 |
+
:param env: additional data from parsed input (references, for example)
|
| 113 |
+
"""
|
| 114 |
+
out: list[str] = []
|
| 115 |
+
|
| 116 |
+
for i, token in enumerate(tokens):
|
| 117 |
+
if token.type in self.rules:
|
| 118 |
+
out.append(self.rules[token.type](tokens, i, options, env))
|
| 119 |
+
else:
|
| 120 |
+
out.append(self.renderToken(tokens, i, options, env))
|
| 121 |
+
|
| 122 |
+
return "".join(out)
|
| 123 |
+
|
| 124 |
+
def renderToken(
|
| 125 |
+
self,
|
| 126 |
+
tokens: Sequence[Token],
|
| 127 |
+
idx: int,
|
| 128 |
+
options: OptionsDict,
|
| 129 |
+
env: EnvType,
|
| 130 |
+
) -> str:
|
| 131 |
+
"""Default token renderer.
|
| 132 |
+
|
| 133 |
+
Can be overridden by custom function
|
| 134 |
+
|
| 135 |
+
:param idx: token index to render
|
| 136 |
+
:param options: params of parser instance
|
| 137 |
+
"""
|
| 138 |
+
result = ""
|
| 139 |
+
needLf = False
|
| 140 |
+
token = tokens[idx]
|
| 141 |
+
|
| 142 |
+
# Tight list paragraphs
|
| 143 |
+
if token.hidden:
|
| 144 |
+
return ""
|
| 145 |
+
|
| 146 |
+
# Insert a newline between hidden paragraph and subsequent opening
|
| 147 |
+
# block-level tag.
|
| 148 |
+
#
|
| 149 |
+
# For example, here we should insert a newline before blockquote:
|
| 150 |
+
# - a
|
| 151 |
+
# >
|
| 152 |
+
#
|
| 153 |
+
if token.block and token.nesting != -1 and idx and tokens[idx - 1].hidden:
|
| 154 |
+
result += "\n"
|
| 155 |
+
|
| 156 |
+
# Add token name, e.g. `<img`
|
| 157 |
+
result += ("</" if token.nesting == -1 else "<") + token.tag
|
| 158 |
+
|
| 159 |
+
# Encode attributes, e.g. `<img src="foo"`
|
| 160 |
+
result += self.renderAttrs(token)
|
| 161 |
+
|
| 162 |
+
# Add a slash for self-closing tags, e.g. `<img src="foo" /`
|
| 163 |
+
if token.nesting == 0 and options["xhtmlOut"]:
|
| 164 |
+
result += " /"
|
| 165 |
+
|
| 166 |
+
# Check if we need to add a newline after this tag
|
| 167 |
+
if token.block:
|
| 168 |
+
needLf = True
|
| 169 |
+
|
| 170 |
+
if token.nesting == 1 and (idx + 1 < len(tokens)):
|
| 171 |
+
nextToken = tokens[idx + 1]
|
| 172 |
+
|
| 173 |
+
if nextToken.type == "inline" or nextToken.hidden:
|
| 174 |
+
# Block-level tag containing an inline tag.
|
| 175 |
+
#
|
| 176 |
+
needLf = False
|
| 177 |
+
|
| 178 |
+
elif nextToken.nesting == -1 and nextToken.tag == token.tag:
|
| 179 |
+
# Opening tag + closing tag of the same type. E.g. `<li></li>`.
|
| 180 |
+
#
|
| 181 |
+
needLf = False
|
| 182 |
+
|
| 183 |
+
result += ">\n" if needLf else ">"
|
| 184 |
+
|
| 185 |
+
return result
|
| 186 |
+
|
| 187 |
+
@staticmethod
|
| 188 |
+
def renderAttrs(token: Token) -> str:
|
| 189 |
+
"""Render token attributes to string."""
|
| 190 |
+
result = ""
|
| 191 |
+
|
| 192 |
+
for key, value in token.attrItems():
|
| 193 |
+
result += " " + escapeHtml(key) + '="' + escapeHtml(str(value)) + '"'
|
| 194 |
+
|
| 195 |
+
return result
|
| 196 |
+
|
| 197 |
+
def renderInlineAsText(
|
| 198 |
+
self,
|
| 199 |
+
tokens: Sequence[Token] | None,
|
| 200 |
+
options: OptionsDict,
|
| 201 |
+
env: EnvType,
|
| 202 |
+
) -> str:
|
| 203 |
+
"""Special kludge for image `alt` attributes to conform CommonMark spec.
|
| 204 |
+
|
| 205 |
+
Don't try to use it! Spec requires to show `alt` content with stripped markup,
|
| 206 |
+
instead of simple escaping.
|
| 207 |
+
|
| 208 |
+
:param tokens: list on block tokens to render
|
| 209 |
+
:param options: params of parser instance
|
| 210 |
+
:param env: additional data from parsed input
|
| 211 |
+
"""
|
| 212 |
+
out: list[str] = []
|
| 213 |
+
|
| 214 |
+
for token in tokens or []:
|
| 215 |
+
if token.type in ("text", "code_inline"):
|
| 216 |
+
out.append(token.content)
|
| 217 |
+
elif token.type == "image":
|
| 218 |
+
if token.children:
|
| 219 |
+
out.append(self.renderInlineAsText(token.children, options, env))
|
| 220 |
+
elif token.type in ("html_inline", "html_block"):
|
| 221 |
+
out.append(token.content)
|
| 222 |
+
elif token.type in ("softbreak", "hardbreak"):
|
| 223 |
+
out.append("\n")
|
| 224 |
+
|
| 225 |
+
return "".join(out)
|
| 226 |
+
|
| 227 |
+
###################################################
|
| 228 |
+
|
| 229 |
+
def list_item_open(
|
| 230 |
+
self,
|
| 231 |
+
tokens: Sequence[Token],
|
| 232 |
+
idx: int,
|
| 233 |
+
options: OptionsDict,
|
| 234 |
+
env: EnvType,
|
| 235 |
+
) -> str:
|
| 236 |
+
token = tokens[idx]
|
| 237 |
+
result = self.renderToken(tokens, idx, options, env)
|
| 238 |
+
if token.meta and "checked" in token.meta:
|
| 239 |
+
checked_attr = ' checked=""' if token.meta["checked"] else ""
|
| 240 |
+
disabled_attr = (
|
| 241 |
+
"" if options.get("tasklists_editable", False) else ' disabled=""'
|
| 242 |
+
)
|
| 243 |
+
result += (
|
| 244 |
+
'<input class="task-list-item-checkbox"'
|
| 245 |
+
f'{disabled_attr} type="checkbox"{checked_attr}> '
|
| 246 |
+
)
|
| 247 |
+
return result
|
| 248 |
+
|
| 249 |
+
def code_inline(
|
| 250 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 251 |
+
) -> str:
|
| 252 |
+
token = tokens[idx]
|
| 253 |
+
return (
|
| 254 |
+
"<code"
|
| 255 |
+
+ self.renderAttrs(token)
|
| 256 |
+
+ ">"
|
| 257 |
+
+ escapeHtml(tokens[idx].content)
|
| 258 |
+
+ "</code>"
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
def code_block(
|
| 262 |
+
self,
|
| 263 |
+
tokens: Sequence[Token],
|
| 264 |
+
idx: int,
|
| 265 |
+
options: OptionsDict,
|
| 266 |
+
env: EnvType,
|
| 267 |
+
) -> str:
|
| 268 |
+
token = tokens[idx]
|
| 269 |
+
|
| 270 |
+
return (
|
| 271 |
+
"<pre"
|
| 272 |
+
+ self.renderAttrs(token)
|
| 273 |
+
+ "><code>"
|
| 274 |
+
+ escapeHtml(tokens[idx].content)
|
| 275 |
+
+ "</code></pre>\n"
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
def fence(
|
| 279 |
+
self,
|
| 280 |
+
tokens: Sequence[Token],
|
| 281 |
+
idx: int,
|
| 282 |
+
options: OptionsDict,
|
| 283 |
+
env: EnvType,
|
| 284 |
+
) -> str:
|
| 285 |
+
token = tokens[idx]
|
| 286 |
+
info = mdTrim(unescapeAll(token.info)) if token.info else ""
|
| 287 |
+
langName = ""
|
| 288 |
+
langAttrs = ""
|
| 289 |
+
|
| 290 |
+
if info:
|
| 291 |
+
# Not ``str.split()``: it splits on the Python whitespace set,
|
| 292 |
+
# which is wider than the one upstream uses here.
|
| 293 |
+
arr = MD_TRIM_RE.split(info, maxsplit=1)
|
| 294 |
+
langName = arr[0]
|
| 295 |
+
if len(arr) == 2:
|
| 296 |
+
langAttrs = arr[1]
|
| 297 |
+
|
| 298 |
+
if options.highlight:
|
| 299 |
+
highlighted = options.highlight(
|
| 300 |
+
token.content, langName, langAttrs
|
| 301 |
+
) or escapeHtml(token.content)
|
| 302 |
+
else:
|
| 303 |
+
highlighted = escapeHtml(token.content)
|
| 304 |
+
|
| 305 |
+
if highlighted.startswith("<pre"):
|
| 306 |
+
return highlighted + "\n"
|
| 307 |
+
|
| 308 |
+
# If language exists, inject class gently, without modifying original token.
|
| 309 |
+
# May be, one day we will add .deepClone() for token and simplify this part, but
|
| 310 |
+
# now we prefer to keep things local.
|
| 311 |
+
if info:
|
| 312 |
+
# Fake token just to render attributes
|
| 313 |
+
tmpToken = Token(type="", tag="", nesting=0, attrs=token.attrs.copy())
|
| 314 |
+
tmpToken.attrJoin("class", options.langPrefix + langName)
|
| 315 |
+
|
| 316 |
+
return (
|
| 317 |
+
"<pre><code"
|
| 318 |
+
+ self.renderAttrs(tmpToken)
|
| 319 |
+
+ ">"
|
| 320 |
+
+ highlighted
|
| 321 |
+
+ "</code></pre>\n"
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
+
return (
|
| 325 |
+
"<pre><code"
|
| 326 |
+
+ self.renderAttrs(token)
|
| 327 |
+
+ ">"
|
| 328 |
+
+ highlighted
|
| 329 |
+
+ "</code></pre>\n"
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
def image(
|
| 333 |
+
self,
|
| 334 |
+
tokens: Sequence[Token],
|
| 335 |
+
idx: int,
|
| 336 |
+
options: OptionsDict,
|
| 337 |
+
env: EnvType,
|
| 338 |
+
) -> str:
|
| 339 |
+
token = tokens[idx]
|
| 340 |
+
|
| 341 |
+
# "alt" attr MUST be set, even if empty. Because it's mandatory and
|
| 342 |
+
# should be placed on proper position for tests.
|
| 343 |
+
if token.children:
|
| 344 |
+
token.attrSet("alt", self.renderInlineAsText(token.children, options, env))
|
| 345 |
+
else:
|
| 346 |
+
token.attrSet("alt", "")
|
| 347 |
+
|
| 348 |
+
return self.renderToken(tokens, idx, options, env)
|
| 349 |
+
|
| 350 |
+
def hardbreak(
|
| 351 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 352 |
+
) -> str:
|
| 353 |
+
return "<br />\n" if options.xhtmlOut else "<br>\n"
|
| 354 |
+
|
| 355 |
+
def softbreak(
|
| 356 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 357 |
+
) -> str:
|
| 358 |
+
return (
|
| 359 |
+
("<br />\n" if options.xhtmlOut else "<br>\n") if options.breaks else "\n"
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
+
def text(
|
| 363 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 364 |
+
) -> str:
|
| 365 |
+
return escapeHtml(tokens[idx].content)
|
| 366 |
+
|
| 367 |
+
def html_block(
|
| 368 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 369 |
+
) -> str:
|
| 370 |
+
return tokens[idx].content
|
| 371 |
+
|
| 372 |
+
def html_inline(
|
| 373 |
+
self, tokens: Sequence[Token], idx: int, options: OptionsDict, env: EnvType
|
| 374 |
+
) -> str:
|
| 375 |
+
return tokens[idx].content
|
venv/lib/python3.14/site-packages/markdown_it/ruler.py
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# `src` is a plain attribute, not a property: rules read it on almost
|
| 34 |
+
# every step, and a property call there costs ~5% of total parse time.
|
| 35 |
+
src: str
|
| 36 |
+
|
| 37 |
+
# Cache for the deprecated `srcCharCode`, as `(src, char_codes)`.
|
| 38 |
+
# This is a class-level default, since subclasses do not call `__init__`.
|
| 39 |
+
_src_char_code: tuple[str, tuple[int, ...]] | None = None
|
| 40 |
+
|
| 41 |
+
def __init__(self, src: str, md: MarkdownIt, env: EnvType):
|
| 42 |
+
self.src = src
|
| 43 |
+
self.env = env
|
| 44 |
+
self.md = md
|
| 45 |
+
|
| 46 |
+
@property
|
| 47 |
+
def srcCharCode(self) -> tuple[int, ...]:
|
| 48 |
+
warnings.warn(
|
| 49 |
+
"StateBase.srcCharCode is deprecated. Use StateBase.src instead.",
|
| 50 |
+
DeprecationWarning,
|
| 51 |
+
stacklevel=2,
|
| 52 |
+
)
|
| 53 |
+
# rebuild the cache if `src` has been reassigned since it was built
|
| 54 |
+
if self._src_char_code is None or self._src_char_code[0] is not self.src:
|
| 55 |
+
self._src_char_code = (self.src, tuple(ord(c) for c in self.src))
|
| 56 |
+
return self._src_char_code[1]
|
| 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 |
+
(the rules named before it are still enabled)
|
| 200 |
+
:return: list of found rule names
|
| 201 |
+
"""
|
| 202 |
+
if isinstance(names, str):
|
| 203 |
+
names = [names]
|
| 204 |
+
result: list[str] = []
|
| 205 |
+
try:
|
| 206 |
+
for name in names:
|
| 207 |
+
idx = self.__find__(name)
|
| 208 |
+
if (idx < 0) and ignoreInvalid:
|
| 209 |
+
continue
|
| 210 |
+
if (idx < 0) and not ignoreInvalid:
|
| 211 |
+
raise KeyError(f"Rules manager: invalid rule name {name}")
|
| 212 |
+
self.__rules__[idx].enabled = True
|
| 213 |
+
result.append(name)
|
| 214 |
+
finally:
|
| 215 |
+
self.__cache__ = None
|
| 216 |
+
return result
|
| 217 |
+
|
| 218 |
+
def enableOnly(
|
| 219 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 220 |
+
) -> list[str]:
|
| 221 |
+
"""Enable rules with given names, and disable everything else.
|
| 222 |
+
|
| 223 |
+
:param names: name or list of rule names to enable.
|
| 224 |
+
:param ignoreInvalid: ignore errors when rule not found
|
| 225 |
+
:raises: KeyError if name not found and not ignoreInvalid
|
| 226 |
+
(all rules are still disabled, and the rules named before it enabled)
|
| 227 |
+
:return: list of found rule names
|
| 228 |
+
"""
|
| 229 |
+
if isinstance(names, str):
|
| 230 |
+
names = [names]
|
| 231 |
+
for rule in self.__rules__:
|
| 232 |
+
rule.enabled = False
|
| 233 |
+
return self.enable(names, ignoreInvalid)
|
| 234 |
+
|
| 235 |
+
def disable(
|
| 236 |
+
self, names: str | Iterable[str], ignoreInvalid: bool = False
|
| 237 |
+
) -> list[str]:
|
| 238 |
+
"""Disable rules with given names.
|
| 239 |
+
|
| 240 |
+
:param names: name or list of rule names to enable.
|
| 241 |
+
:param ignoreInvalid: ignore errors when rule not found
|
| 242 |
+
:raises: KeyError if name not found and not ignoreInvalid
|
| 243 |
+
(the rules named before it are still disabled)
|
| 244 |
+
:return: list of found rule names
|
| 245 |
+
"""
|
| 246 |
+
if isinstance(names, str):
|
| 247 |
+
names = [names]
|
| 248 |
+
result = []
|
| 249 |
+
try:
|
| 250 |
+
for name in names:
|
| 251 |
+
idx = self.__find__(name)
|
| 252 |
+
if (idx < 0) and ignoreInvalid:
|
| 253 |
+
continue
|
| 254 |
+
if (idx < 0) and not ignoreInvalid:
|
| 255 |
+
raise KeyError(f"Rules manager: invalid rule name {name}")
|
| 256 |
+
self.__rules__[idx].enabled = False
|
| 257 |
+
result.append(name)
|
| 258 |
+
finally:
|
| 259 |
+
self.__cache__ = None
|
| 260 |
+
return result
|
| 261 |
+
|
| 262 |
+
def getRules(self, chainName: str = "") -> list[RuleFuncTv]:
|
| 263 |
+
"""Return array of active functions (rules) for given chain name.
|
| 264 |
+
It analyzes rules configuration, compiles caches if not exists and returns result.
|
| 265 |
+
|
| 266 |
+
Default chain name is `''` (empty string). It can't be skipped.
|
| 267 |
+
That's done intentionally, to keep signature monomorphic for high speed.
|
| 268 |
+
|
| 269 |
+
"""
|
| 270 |
+
if self.__cache__ is None:
|
| 271 |
+
self.__compile__()
|
| 272 |
+
assert self.__cache__ is not None
|
| 273 |
+
# Chain can be empty, if rules disabled. But we still have to return Array.
|
| 274 |
+
return self.__cache__.get(chainName, []) or []
|
| 275 |
+
|
| 276 |
+
def get_all_rules(self) -> list[str]:
|
| 277 |
+
"""Return all available rule names."""
|
| 278 |
+
return [r.name for r in self.__rules__]
|
| 279 |
+
|
| 280 |
+
def get_active_rules(self) -> list[str]:
|
| 281 |
+
"""Return the active rule names."""
|
| 282 |
+
return [r.name for r in self.__rules__ if r.enabled]
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = (
|
| 2 |
+
"StateBlock",
|
| 3 |
+
"blockquote",
|
| 4 |
+
"code",
|
| 5 |
+
"fence",
|
| 6 |
+
"heading",
|
| 7 |
+
"hr",
|
| 8 |
+
"html_block",
|
| 9 |
+
"lheading",
|
| 10 |
+
"list_block",
|
| 11 |
+
"make_fence_rule",
|
| 12 |
+
"paragraph",
|
| 13 |
+
"reference",
|
| 14 |
+
"table",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
from .blockquote import blockquote
|
| 18 |
+
from .code import code
|
| 19 |
+
from .fence import fence, make_fence_rule
|
| 20 |
+
from .heading import heading
|
| 21 |
+
from .hr import hr
|
| 22 |
+
from .html_block import html_block
|
| 23 |
+
from .lheading import lheading
|
| 24 |
+
from .list import list_block
|
| 25 |
+
from .paragraph import paragraph
|
| 26 |
+
from .reference import reference
|
| 27 |
+
from .state_block import StateBlock
|
| 28 |
+
from .table import table
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/blockquote.py
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Detect GitHub-style alert marker on the first content line.
|
| 277 |
+
# Note: `startLine` here refers to the first content line of the
|
| 278 |
+
# blockquote, after the `>` prefix has already been stripped by the
|
| 279 |
+
# blockquote parser above (bMarks/tShift adjusted to skip `> `).
|
| 280 |
+
alert_kind = None
|
| 281 |
+
if state.md.options.get("alerts", False) and nextLine > startLine:
|
| 282 |
+
alert_kind = _detect_alert(state, startLine)
|
| 283 |
+
|
| 284 |
+
lines = [startLine, 0]
|
| 285 |
+
|
| 286 |
+
if alert_kind is not None:
|
| 287 |
+
# Emit alert tokens instead of blockquote tokens
|
| 288 |
+
alert_lower = alert_kind.lower()
|
| 289 |
+
token = state.push("alert_open", "div", 1)
|
| 290 |
+
token.markup = ">"
|
| 291 |
+
token.attrSet("class", f"markdown-alert markdown-alert-{alert_lower}")
|
| 292 |
+
token.map = lines
|
| 293 |
+
token.info = alert_kind
|
| 294 |
+
token.meta = {"kind": alert_kind}
|
| 295 |
+
|
| 296 |
+
# Emit a title paragraph: <p class="markdown-alert-title">Kind</p>
|
| 297 |
+
token = state.push("alert_title_open", "p", 1)
|
| 298 |
+
token.attrSet("class", "markdown-alert-title")
|
| 299 |
+
title_token = state.push("inline", "", 0)
|
| 300 |
+
title_token.content = alert_kind.capitalize()
|
| 301 |
+
title_token.children = []
|
| 302 |
+
token = state.push("alert_title_close", "p", -1)
|
| 303 |
+
|
| 304 |
+
# Skip the marker line (startLine) and tokenize from startLine + 1.
|
| 305 |
+
contentStart = startLine + 1
|
| 306 |
+
if contentStart < nextLine:
|
| 307 |
+
# tokenize() updates state.line to nextLine as part of its
|
| 308 |
+
# contract, consistent with the blockquote code path below.
|
| 309 |
+
state.md.block.tokenize(state, contentStart, nextLine)
|
| 310 |
+
else:
|
| 311 |
+
state.line = nextLine
|
| 312 |
+
|
| 313 |
+
token = state.push("alert_close", "div", -1)
|
| 314 |
+
token.markup = ">"
|
| 315 |
+
else:
|
| 316 |
+
token = state.push("blockquote_open", "blockquote", 1)
|
| 317 |
+
token.markup = ">"
|
| 318 |
+
token.map = lines
|
| 319 |
+
|
| 320 |
+
state.md.block.tokenize(state, startLine, nextLine)
|
| 321 |
+
|
| 322 |
+
token = state.push("blockquote_close", "blockquote", -1)
|
| 323 |
+
token.markup = ">"
|
| 324 |
+
|
| 325 |
+
state.lineMax = oldLineMax
|
| 326 |
+
state.parentType = oldParentType
|
| 327 |
+
# Update the opening token map for both alert and blockquote containers.
|
| 328 |
+
lines[1] = state.line
|
| 329 |
+
|
| 330 |
+
# Restore original tShift; this might not be necessary since the parser
|
| 331 |
+
# has already been here, but just to make sure we can do that.
|
| 332 |
+
for i, item in enumerate(oldTShift):
|
| 333 |
+
state.bMarks[i + startLine] = oldBMarks[i]
|
| 334 |
+
state.tShift[i + startLine] = item
|
| 335 |
+
state.sCount[i + startLine] = oldSCount[i]
|
| 336 |
+
state.bsCount[i + startLine] = oldBSCount[i]
|
| 337 |
+
|
| 338 |
+
state.blkIndent = oldIndent
|
| 339 |
+
|
| 340 |
+
return True
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
_ALERT_TYPES = {"NOTE", "TIP", "IMPORTANT", "WARNING", "CAUTION"}
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def _detect_alert(state: StateBlock, startLine: int) -> str | None:
|
| 347 |
+
"""Detect ``[!TYPE]`` on *startLine* (after ``>`` prefix has been stripped).
|
| 348 |
+
|
| 349 |
+
Returns the alert type string (e.g. ``"NOTE"``) or ``None``.
|
| 350 |
+
"""
|
| 351 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 352 |
+
maximum = state.eMarks[startLine]
|
| 353 |
+
src = state.src
|
| 354 |
+
|
| 355 |
+
# Trim trailing whitespace
|
| 356 |
+
while maximum > pos and src[maximum - 1] in (" ", "\t"):
|
| 357 |
+
maximum -= 1
|
| 358 |
+
|
| 359 |
+
if maximum - pos < 4:
|
| 360 |
+
return None
|
| 361 |
+
if src[pos] != "[" or src[pos + 1] != "!":
|
| 362 |
+
return None
|
| 363 |
+
if src[maximum - 1] != "]":
|
| 364 |
+
return None
|
| 365 |
+
type_str = src[pos + 2 : maximum - 1].upper()
|
| 366 |
+
if type_str not in _ALERT_TYPES:
|
| 367 |
+
return None
|
| 368 |
+
return type_str
|
venv/lib/python3.14/site-packages/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
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/fence.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# fences (``` lang, ~~~ lang)
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from collections.abc import Callable
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
from .state_block import StateBlock
|
| 8 |
+
|
| 9 |
+
LOGGER = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def make_fence_rule(
|
| 13 |
+
*,
|
| 14 |
+
markers: tuple[str, ...] = ("~", "`"),
|
| 15 |
+
token_type: str = "fence",
|
| 16 |
+
exact_match: bool = False,
|
| 17 |
+
disallow_marker_in_info: tuple[str, ...] = ("`",),
|
| 18 |
+
min_markers: int = 3,
|
| 19 |
+
) -> Callable[[StateBlock, int, int, bool], bool]:
|
| 20 |
+
"""Create a fence parsing rule with configurable options.
|
| 21 |
+
|
| 22 |
+
:param markers: Tuple of single characters that can be used as fence markers.
|
| 23 |
+
:param token_type: The token type name to emit (e.g. "fence", "colon_fence").
|
| 24 |
+
:param exact_match: If True, the closing fence must have exactly the same
|
| 25 |
+
number of marker characters as the opening fence (not "at least as many").
|
| 26 |
+
This enables nesting of fences with different marker counts.
|
| 27 |
+
:param disallow_marker_in_info: Tuple of marker characters that are not allowed
|
| 28 |
+
to appear in the info string. The check only applies when the actual opening
|
| 29 |
+
marker is in this tuple (e.g. a tilde fence is unaffected by ``"`"`` being
|
| 30 |
+
listed). Per CommonMark, backtick fences cannot have backticks in the info
|
| 31 |
+
string. Use ``()`` to disable this restriction.
|
| 32 |
+
:param min_markers: Minimum number of marker characters to form a fence.
|
| 33 |
+
:return: A block rule function with signature
|
| 34 |
+
``(state, startLine, endLine, silent) -> bool``.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
closing_matcher: Callable[[int, int], bool]
|
| 38 |
+
if exact_match:
|
| 39 |
+
# closing code fence must have exactly the same number of markers as the opening one
|
| 40 |
+
closing_matcher = lambda opening_len, closing_len: closing_len == opening_len
|
| 41 |
+
else:
|
| 42 |
+
# closing code fence must be at least as long as the opening one
|
| 43 |
+
closing_matcher = lambda opening_len, closing_len: closing_len >= opening_len
|
| 44 |
+
|
| 45 |
+
def _fence_rule(
|
| 46 |
+
state: StateBlock, startLine: int, endLine: int, silent: bool
|
| 47 |
+
) -> bool:
|
| 48 |
+
LOGGER.debug(
|
| 49 |
+
"entering fence: %s, %s, %s, %s", state, startLine, endLine, silent
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
haveEndMarker = False
|
| 53 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 54 |
+
maximum = state.eMarks[startLine]
|
| 55 |
+
|
| 56 |
+
if state.is_code_block(startLine):
|
| 57 |
+
return False
|
| 58 |
+
|
| 59 |
+
if pos + min_markers > maximum:
|
| 60 |
+
return False
|
| 61 |
+
|
| 62 |
+
marker = state.src[pos]
|
| 63 |
+
|
| 64 |
+
if marker not in markers:
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
# scan marker length
|
| 68 |
+
mem = pos
|
| 69 |
+
pos = state.skipCharsStr(pos, marker)
|
| 70 |
+
|
| 71 |
+
length = pos - mem
|
| 72 |
+
|
| 73 |
+
if length < min_markers:
|
| 74 |
+
return False
|
| 75 |
+
|
| 76 |
+
markup = state.src[mem:pos]
|
| 77 |
+
params = state.src[pos:maximum]
|
| 78 |
+
|
| 79 |
+
if marker in disallow_marker_in_info and marker in params:
|
| 80 |
+
return False
|
| 81 |
+
|
| 82 |
+
# Since start is found, we can report success here in validation mode
|
| 83 |
+
if silent:
|
| 84 |
+
return True
|
| 85 |
+
|
| 86 |
+
# search end of block
|
| 87 |
+
nextLine = startLine
|
| 88 |
+
|
| 89 |
+
while True:
|
| 90 |
+
nextLine += 1
|
| 91 |
+
if nextLine >= endLine:
|
| 92 |
+
# unclosed block should be autoclosed by end of document.
|
| 93 |
+
# also block seems to be autoclosed by end of parent
|
| 94 |
+
break
|
| 95 |
+
|
| 96 |
+
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 97 |
+
maximum = state.eMarks[nextLine]
|
| 98 |
+
|
| 99 |
+
if pos < maximum and state.sCount[nextLine] < state.blkIndent:
|
| 100 |
+
# non-empty line with negative indent should stop the list:
|
| 101 |
+
# - ```
|
| 102 |
+
# test
|
| 103 |
+
break
|
| 104 |
+
|
| 105 |
+
try:
|
| 106 |
+
if state.src[pos] != marker:
|
| 107 |
+
continue
|
| 108 |
+
except IndexError:
|
| 109 |
+
break
|
| 110 |
+
|
| 111 |
+
if state.is_code_block(nextLine):
|
| 112 |
+
continue
|
| 113 |
+
|
| 114 |
+
pos = state.skipCharsStr(pos, marker)
|
| 115 |
+
|
| 116 |
+
if not closing_matcher(length, pos - mem):
|
| 117 |
+
continue
|
| 118 |
+
|
| 119 |
+
# make sure tail has spaces only
|
| 120 |
+
pos = state.skipSpaces(pos)
|
| 121 |
+
|
| 122 |
+
if pos < maximum:
|
| 123 |
+
continue
|
| 124 |
+
|
| 125 |
+
haveEndMarker = True
|
| 126 |
+
# found!
|
| 127 |
+
break
|
| 128 |
+
|
| 129 |
+
# If a fence has heading spaces, they should be removed from its inner block
|
| 130 |
+
length = state.sCount[startLine]
|
| 131 |
+
|
| 132 |
+
state.line = nextLine + (1 if haveEndMarker else 0)
|
| 133 |
+
|
| 134 |
+
token = state.push(token_type, "code", 0)
|
| 135 |
+
token.info = params
|
| 136 |
+
token.content = state.getLines(startLine + 1, nextLine, length, True)
|
| 137 |
+
token.markup = markup
|
| 138 |
+
token.map = [startLine, state.line]
|
| 139 |
+
|
| 140 |
+
return True
|
| 141 |
+
|
| 142 |
+
return _fence_rule
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
#: The default fence rule (backtick and tilde markers, CommonMark compliant).
|
| 146 |
+
fence = make_fence_rule()
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/heading.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Atex heading (#, ##, ...)"""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
from ..common.utils import isStrSpace, mdTrim
|
| 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 |
+
try:
|
| 23 |
+
ch: str | None = state.src[pos]
|
| 24 |
+
except IndexError:
|
| 25 |
+
return False
|
| 26 |
+
|
| 27 |
+
if ch != "#" or pos >= maximum:
|
| 28 |
+
return False
|
| 29 |
+
|
| 30 |
+
# count heading level
|
| 31 |
+
level = 1
|
| 32 |
+
pos += 1
|
| 33 |
+
try:
|
| 34 |
+
ch = state.src[pos]
|
| 35 |
+
except IndexError:
|
| 36 |
+
ch = None
|
| 37 |
+
while ch == "#" and pos < maximum and level <= 6:
|
| 38 |
+
level += 1
|
| 39 |
+
pos += 1
|
| 40 |
+
try:
|
| 41 |
+
ch = state.src[pos]
|
| 42 |
+
except IndexError:
|
| 43 |
+
ch = None
|
| 44 |
+
|
| 45 |
+
if level > 6 or (pos < maximum and not isStrSpace(ch)):
|
| 46 |
+
return False
|
| 47 |
+
|
| 48 |
+
if silent:
|
| 49 |
+
return True
|
| 50 |
+
|
| 51 |
+
# Let's cut tails like ' ### ' from the end of string
|
| 52 |
+
|
| 53 |
+
maximum = state.skipSpacesBack(maximum, pos)
|
| 54 |
+
tmp = state.skipCharsStrBack(maximum, "#", pos)
|
| 55 |
+
if tmp > pos and isStrSpace(state.src[tmp - 1]):
|
| 56 |
+
maximum = tmp
|
| 57 |
+
|
| 58 |
+
state.line = startLine + 1
|
| 59 |
+
|
| 60 |
+
token = state.push("heading_open", "h" + str(level), 1)
|
| 61 |
+
token.markup = "########"[:level]
|
| 62 |
+
token.map = [startLine, state.line]
|
| 63 |
+
|
| 64 |
+
token = state.push("inline", "", 0)
|
| 65 |
+
token.content = mdTrim(state.src[pos:maximum])
|
| 66 |
+
token.map = [startLine, state.line]
|
| 67 |
+
token.children = []
|
| 68 |
+
|
| 69 |
+
token = state.push("heading_close", "h" + str(level), -1)
|
| 70 |
+
token.markup = "########"[:level]
|
| 71 |
+
|
| 72 |
+
return True
|
venv/lib/python3.14/site-packages/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
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/html_block.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"^<(?a:(script|pre|style|textarea))(?=(\s|>|$))", re.IGNORECASE),
|
| 18 |
+
re.compile(r"<\/(?a:(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-Za-z]"), re.compile(r">"), True),
|
| 24 |
+
(re.compile(r"^<!\[CDATA\["), re.compile(r"\]\]>"), True),
|
| 25 |
+
(
|
| 26 |
+
re.compile(
|
| 27 |
+
"^</?(?a:(" + "|".join(block_names) + "))(?=(\\s|/?>|$))", re.IGNORECASE
|
| 28 |
+
),
|
| 29 |
+
re.compile(r"^$"),
|
| 30 |
+
True,
|
| 31 |
+
),
|
| 32 |
+
(re.compile(HTML_OPEN_CLOSE_TAG_STR + "\\s*$"), re.compile(r"^$"), False),
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def html_block(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 37 |
+
LOGGER.debug(
|
| 38 |
+
"entering html_block: %s, %s, %s, %s", state, startLine, endLine, silent
|
| 39 |
+
)
|
| 40 |
+
pos = state.bMarks[startLine] + state.tShift[startLine]
|
| 41 |
+
maximum = state.eMarks[startLine]
|
| 42 |
+
|
| 43 |
+
if state.is_code_block(startLine):
|
| 44 |
+
return False
|
| 45 |
+
|
| 46 |
+
if not state.md.options.get("html", None):
|
| 47 |
+
return False
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
if state.src[pos] != "<":
|
| 51 |
+
return False
|
| 52 |
+
except IndexError:
|
| 53 |
+
return False
|
| 54 |
+
|
| 55 |
+
lineText = state.src[pos:maximum]
|
| 56 |
+
|
| 57 |
+
html_seq = None
|
| 58 |
+
for HTML_SEQUENCE in HTML_SEQUENCES:
|
| 59 |
+
if HTML_SEQUENCE[0].search(lineText):
|
| 60 |
+
html_seq = HTML_SEQUENCE
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
if not html_seq:
|
| 64 |
+
return False
|
| 65 |
+
|
| 66 |
+
if silent:
|
| 67 |
+
# true if this sequence can be a terminator, false otherwise
|
| 68 |
+
return html_seq[2]
|
| 69 |
+
|
| 70 |
+
nextLine = startLine + 1
|
| 71 |
+
|
| 72 |
+
# Block types 6 and 7 (the only ones whose end condition is a blank line)
|
| 73 |
+
# have `^$` as their closing regexp. For all other types (1-5, e.g.
|
| 74 |
+
# `<!--` comments), a blank line is regular content and must not terminate
|
| 75 |
+
# the block - it ends only when its closing sequence is found.
|
| 76 |
+
endsOnBlankLine = bool(html_seq[1].search(""))
|
| 77 |
+
|
| 78 |
+
# If we are here - we detected HTML block.
|
| 79 |
+
# Let's roll down till block end.
|
| 80 |
+
if not html_seq[1].search(lineText):
|
| 81 |
+
while nextLine < endLine:
|
| 82 |
+
# An outdented blank line shouldn't end a block that doesn't end on a
|
| 83 |
+
# blank line (e.g. a `<!--` comment inside a list item). Such blocks
|
| 84 |
+
# must continue until their closing sequence regardless of indent.
|
| 85 |
+
if state.sCount[nextLine] < state.blkIndent and (
|
| 86 |
+
endsOnBlankLine or not state.isEmpty(nextLine)
|
| 87 |
+
):
|
| 88 |
+
break
|
| 89 |
+
|
| 90 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 91 |
+
maximum = state.eMarks[nextLine]
|
| 92 |
+
lineText = state.src[pos:maximum]
|
| 93 |
+
|
| 94 |
+
if html_seq[1].search(lineText):
|
| 95 |
+
if len(lineText) != 0:
|
| 96 |
+
nextLine += 1
|
| 97 |
+
break
|
| 98 |
+
nextLine += 1
|
| 99 |
+
|
| 100 |
+
state.line = nextLine
|
| 101 |
+
|
| 102 |
+
token = state.push("html_block", "", 0)
|
| 103 |
+
token.map = [startLine, nextLine]
|
| 104 |
+
token.content = state.getLines(startLine, nextLine, state.blkIndent, True)
|
| 105 |
+
|
| 106 |
+
return True
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/lheading.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# lheading (---, ==)
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
from ..common.utils import mdTrim
|
| 5 |
+
from .state_block import StateBlock
|
| 6 |
+
|
| 7 |
+
LOGGER = logging.getLogger(__name__)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def lheading(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 11 |
+
LOGGER.debug("entering lheading: %s, %s, %s, %s", state, startLine, endLine, silent)
|
| 12 |
+
|
| 13 |
+
level = None
|
| 14 |
+
nextLine = startLine + 1
|
| 15 |
+
ruler = state.md.block.ruler
|
| 16 |
+
terminatorRules = ruler.getRules("paragraph")
|
| 17 |
+
|
| 18 |
+
if state.is_code_block(startLine):
|
| 19 |
+
return False
|
| 20 |
+
|
| 21 |
+
oldParentType = state.parentType
|
| 22 |
+
state.parentType = "paragraph" # use paragraph to match terminatorRules
|
| 23 |
+
|
| 24 |
+
# jump line-by-line until empty one or EOF
|
| 25 |
+
while nextLine < endLine and not state.isEmpty(nextLine):
|
| 26 |
+
# this would be a code block normally, but after paragraph
|
| 27 |
+
# it's considered a lazy continuation regardless of what's there
|
| 28 |
+
if state.sCount[nextLine] - state.blkIndent > 3:
|
| 29 |
+
nextLine += 1
|
| 30 |
+
continue
|
| 31 |
+
|
| 32 |
+
# Check for underline in setext header
|
| 33 |
+
if state.sCount[nextLine] >= state.blkIndent:
|
| 34 |
+
pos = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 35 |
+
maximum = state.eMarks[nextLine]
|
| 36 |
+
|
| 37 |
+
if pos < maximum:
|
| 38 |
+
marker = state.src[pos]
|
| 39 |
+
|
| 40 |
+
if marker in ("-", "="):
|
| 41 |
+
pos = state.skipCharsStr(pos, marker)
|
| 42 |
+
pos = state.skipSpaces(pos)
|
| 43 |
+
|
| 44 |
+
# /* = */
|
| 45 |
+
if pos >= maximum:
|
| 46 |
+
level = 1 if marker == "=" else 2
|
| 47 |
+
break
|
| 48 |
+
|
| 49 |
+
# quirk for blockquotes, this line should already be checked by that rule
|
| 50 |
+
if state.sCount[nextLine] < 0:
|
| 51 |
+
nextLine += 1
|
| 52 |
+
continue
|
| 53 |
+
|
| 54 |
+
# Some tags can terminate paragraph without empty line.
|
| 55 |
+
terminate = False
|
| 56 |
+
for terminatorRule in terminatorRules:
|
| 57 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 58 |
+
terminate = True
|
| 59 |
+
break
|
| 60 |
+
if terminate:
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
nextLine += 1
|
| 64 |
+
|
| 65 |
+
if not level:
|
| 66 |
+
# Didn't find valid underline
|
| 67 |
+
return False
|
| 68 |
+
|
| 69 |
+
content = mdTrim(state.getLines(startLine, nextLine, state.blkIndent, False))
|
| 70 |
+
|
| 71 |
+
state.line = nextLine + 1
|
| 72 |
+
|
| 73 |
+
token = state.push("heading_open", "h" + str(level), 1)
|
| 74 |
+
token.markup = marker
|
| 75 |
+
token.map = [startLine, state.line]
|
| 76 |
+
|
| 77 |
+
token = state.push("inline", "", 0)
|
| 78 |
+
token.content = content
|
| 79 |
+
token.map = [startLine, state.line - 1]
|
| 80 |
+
token.children = []
|
| 81 |
+
|
| 82 |
+
token = state.push("heading_close", "h" + str(level), -1)
|
| 83 |
+
token.markup = marker
|
| 84 |
+
|
| 85 |
+
state.parentType = oldParentType
|
| 86 |
+
|
| 87 |
+
return True
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/list.py
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
oldBMark = state.bMarks[startLine]
|
| 241 |
+
oldTShift = state.tShift[startLine]
|
| 242 |
+
oldSCount = state.sCount[startLine]
|
| 243 |
+
|
| 244 |
+
# - example list
|
| 245 |
+
# ^ listIndent position will be here
|
| 246 |
+
# ^ blkIndent position will be here
|
| 247 |
+
#
|
| 248 |
+
oldListIndent = state.listIndent
|
| 249 |
+
state.listIndent = state.blkIndent
|
| 250 |
+
state.blkIndent = indent
|
| 251 |
+
|
| 252 |
+
state.tight = True
|
| 253 |
+
state.tShift[startLine] = contentStart - state.bMarks[startLine]
|
| 254 |
+
state.sCount[startLine] = offset
|
| 255 |
+
|
| 256 |
+
# Detect GFM task checkboxes only after setting the item's indentation,
|
| 257 |
+
# so literal markers in indented code blocks are left untouched.
|
| 258 |
+
checkboxLen = 0
|
| 259 |
+
if (
|
| 260 |
+
state.md.options.get("tasklists", False)
|
| 261 |
+
and contentStart < maximum
|
| 262 |
+
and not state.is_code_block(startLine)
|
| 263 |
+
):
|
| 264 |
+
checked = _detect_task_checkbox(state.src, contentStart, maximum)
|
| 265 |
+
if checked is not None:
|
| 266 |
+
token.meta = {"checked": checked}
|
| 267 |
+
# Advance content past the checkbox: `[x]` (3 chars) + whitespace.
|
| 268 |
+
# `_detect_task_checkbox` already guarantees a whitespace char at
|
| 269 |
+
# pos+3, so we always consume 4 characters.
|
| 270 |
+
checkboxLen = 4
|
| 271 |
+
|
| 272 |
+
# If we detected a checkbox, advance bMarks past it so that
|
| 273 |
+
# getLines() doesn't include the checkbox text in the content.
|
| 274 |
+
if checkboxLen:
|
| 275 |
+
state.bMarks[startLine] = contentStart + checkboxLen
|
| 276 |
+
state.tShift[startLine] = 0
|
| 277 |
+
|
| 278 |
+
if contentStart >= maximum and state.isEmpty(startLine + 1):
|
| 279 |
+
# workaround for this case
|
| 280 |
+
# (list item is empty, list terminates before "foo"):
|
| 281 |
+
# ~~~~~~~~
|
| 282 |
+
# -
|
| 283 |
+
#
|
| 284 |
+
# foo
|
| 285 |
+
# ~~~~~~~~
|
| 286 |
+
state.line = min(state.line + 2, endLine)
|
| 287 |
+
else:
|
| 288 |
+
# NOTE in list.js this was:
|
| 289 |
+
# state.md.block.tokenize(state, startLine, endLine, True)
|
| 290 |
+
# but tokeniz does not take the final parameter
|
| 291 |
+
state.md.block.tokenize(state, startLine, endLine)
|
| 292 |
+
|
| 293 |
+
# If any of list item is tight, mark list as tight
|
| 294 |
+
if (not state.tight) or prevEmptyEnd:
|
| 295 |
+
tight = False
|
| 296 |
+
|
| 297 |
+
# Item become loose if finish with empty line,
|
| 298 |
+
# but we should filter last element, because it means list finish
|
| 299 |
+
prevEmptyEnd = (state.line - startLine) > 1 and state.isEmpty(state.line - 1)
|
| 300 |
+
|
| 301 |
+
state.blkIndent = state.listIndent
|
| 302 |
+
state.listIndent = oldListIndent
|
| 303 |
+
if checkboxLen:
|
| 304 |
+
state.bMarks[startLine] = oldBMark
|
| 305 |
+
state.tShift[startLine] = oldTShift
|
| 306 |
+
state.sCount[startLine] = oldSCount
|
| 307 |
+
state.tight = oldTight
|
| 308 |
+
|
| 309 |
+
token = state.push("list_item_close", "li", -1)
|
| 310 |
+
token.markup = markerChar
|
| 311 |
+
|
| 312 |
+
nextLine = startLine = state.line
|
| 313 |
+
itemLines[1] = nextLine
|
| 314 |
+
|
| 315 |
+
if nextLine >= endLine:
|
| 316 |
+
break
|
| 317 |
+
|
| 318 |
+
contentStart = state.bMarks[startLine]
|
| 319 |
+
|
| 320 |
+
#
|
| 321 |
+
# Try to check if list is terminated or continued.
|
| 322 |
+
#
|
| 323 |
+
if state.sCount[nextLine] < state.blkIndent:
|
| 324 |
+
break
|
| 325 |
+
|
| 326 |
+
if state.is_code_block(startLine):
|
| 327 |
+
break
|
| 328 |
+
|
| 329 |
+
# fail if terminating block found
|
| 330 |
+
terminate = False
|
| 331 |
+
for terminatorRule in terminatorRules:
|
| 332 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 333 |
+
terminate = True
|
| 334 |
+
break
|
| 335 |
+
|
| 336 |
+
if terminate:
|
| 337 |
+
break
|
| 338 |
+
|
| 339 |
+
# fail if list has another type
|
| 340 |
+
if isOrdered:
|
| 341 |
+
posAfterMarker = skipOrderedListMarker(state, nextLine)
|
| 342 |
+
if posAfterMarker < 0:
|
| 343 |
+
break
|
| 344 |
+
start = state.bMarks[nextLine] + state.tShift[nextLine]
|
| 345 |
+
else:
|
| 346 |
+
posAfterMarker = skipBulletListMarker(state, nextLine)
|
| 347 |
+
if posAfterMarker < 0:
|
| 348 |
+
break
|
| 349 |
+
|
| 350 |
+
if markerChar != state.src[posAfterMarker - 1]:
|
| 351 |
+
break
|
| 352 |
+
|
| 353 |
+
# Finalize list
|
| 354 |
+
|
| 355 |
+
# If any direct list item has a task checkbox, add class to the list
|
| 356 |
+
if state.md.options.get("tasklists", False):
|
| 357 |
+
containsTask = False
|
| 358 |
+
level = state.tokens[listTokIdx].level
|
| 359 |
+
for j in range(listTokIdx + 1, len(state.tokens)):
|
| 360 |
+
tok = state.tokens[j]
|
| 361 |
+
if (
|
| 362 |
+
tok.level == level + 1
|
| 363 |
+
and tok.type == "list_item_open"
|
| 364 |
+
and tok.meta
|
| 365 |
+
and "checked" in tok.meta
|
| 366 |
+
):
|
| 367 |
+
tok.attrJoin("class", "task-list-item")
|
| 368 |
+
containsTask = True
|
| 369 |
+
if containsTask:
|
| 370 |
+
state.tokens[listTokIdx].attrJoin("class", "contains-task-list")
|
| 371 |
+
|
| 372 |
+
if isOrdered:
|
| 373 |
+
token = state.push("ordered_list_close", "ol", -1)
|
| 374 |
+
else:
|
| 375 |
+
token = state.push("bullet_list_close", "ul", -1)
|
| 376 |
+
|
| 377 |
+
token.markup = markerChar
|
| 378 |
+
|
| 379 |
+
listLines[1] = nextLine
|
| 380 |
+
state.line = nextLine
|
| 381 |
+
|
| 382 |
+
state.parentType = oldParentType
|
| 383 |
+
|
| 384 |
+
# mark paragraphs tight if needed
|
| 385 |
+
if tight:
|
| 386 |
+
markTightParagraphs(state, listTokIdx)
|
| 387 |
+
|
| 388 |
+
return True
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
def _detect_task_checkbox(src: str, pos: int, maximum: int) -> bool | None:
|
| 392 |
+
"""Detect ``[ ]``, ``[x]``, or ``[X]`` at *pos*, followed by whitespace.
|
| 393 |
+
|
| 394 |
+
Returns ``True`` (checked), ``False`` (unchecked), or ``None`` (no match).
|
| 395 |
+
"""
|
| 396 |
+
# Need at least 4 chars: `[`, char, `]`, whitespace
|
| 397 |
+
if pos + 4 > maximum:
|
| 398 |
+
return None
|
| 399 |
+
if src[pos] != "[":
|
| 400 |
+
return None
|
| 401 |
+
inner = src[pos + 1]
|
| 402 |
+
if src[pos + 2] != "]":
|
| 403 |
+
return None
|
| 404 |
+
if inner == " ":
|
| 405 |
+
checked = False
|
| 406 |
+
elif inner in ("x", "X"):
|
| 407 |
+
checked = True
|
| 408 |
+
else:
|
| 409 |
+
return None
|
| 410 |
+
# After `]`, must have whitespace
|
| 411 |
+
if src[pos + 3] not in (" ", "\t"):
|
| 412 |
+
return None
|
| 413 |
+
return checked
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/paragraph.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Paragraph."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
from ..common.utils import mdTrim
|
| 6 |
+
from .state_block import StateBlock
|
| 7 |
+
|
| 8 |
+
LOGGER = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def paragraph(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
|
| 12 |
+
LOGGER.debug(
|
| 13 |
+
"entering paragraph: %s, %s, %s, %s", state, startLine, endLine, silent
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
nextLine = startLine + 1
|
| 17 |
+
ruler = state.md.block.ruler
|
| 18 |
+
terminatorRules = ruler.getRules("paragraph")
|
| 19 |
+
endLine = state.lineMax
|
| 20 |
+
|
| 21 |
+
oldParentType = state.parentType
|
| 22 |
+
state.parentType = "paragraph"
|
| 23 |
+
|
| 24 |
+
# jump line-by-line until empty one or EOF
|
| 25 |
+
while nextLine < endLine:
|
| 26 |
+
if state.isEmpty(nextLine):
|
| 27 |
+
break
|
| 28 |
+
# this would be a code block normally, but after paragraph
|
| 29 |
+
# it's considered a lazy continuation regardless of what's there
|
| 30 |
+
if state.sCount[nextLine] - state.blkIndent > 3:
|
| 31 |
+
nextLine += 1
|
| 32 |
+
continue
|
| 33 |
+
|
| 34 |
+
# quirk for blockquotes, this line should already be checked by that rule
|
| 35 |
+
if state.sCount[nextLine] < 0:
|
| 36 |
+
nextLine += 1
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
# Some tags can terminate paragraph without empty line.
|
| 40 |
+
terminate = False
|
| 41 |
+
for terminatorRule in terminatorRules:
|
| 42 |
+
if terminatorRule(state, nextLine, endLine, True):
|
| 43 |
+
terminate = True
|
| 44 |
+
break
|
| 45 |
+
|
| 46 |
+
if terminate:
|
| 47 |
+
break
|
| 48 |
+
|
| 49 |
+
nextLine += 1
|
| 50 |
+
|
| 51 |
+
content = mdTrim(state.getLines(startLine, nextLine, state.blkIndent, False))
|
| 52 |
+
|
| 53 |
+
state.line = nextLine
|
| 54 |
+
|
| 55 |
+
token = state.push("paragraph_open", "p", 1)
|
| 56 |
+
token.map = [startLine, state.line]
|
| 57 |
+
|
| 58 |
+
token = state.push("inline", "", 0)
|
| 59 |
+
token.content = content
|
| 60 |
+
token.map = [startLine, state.line]
|
| 61 |
+
token.children = []
|
| 62 |
+
|
| 63 |
+
token = state.push("paragraph_close", "p", -1)
|
| 64 |
+
|
| 65 |
+
state.parentType = oldParentType
|
| 66 |
+
|
| 67 |
+
return True
|
venv/lib/python3.14/site-packages/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) -> str | None:
|
| 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]
|
venv/lib/python3.14/site-packages/markdown_it/rules_block/state_block.py
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# NOTE: this loop runs once per line, not once per character:
|
| 70 |
+
# `str.find` locates each line break at C speed and only leading
|
| 71 |
+
# whitespace is scanned (usually zero iterations), instead of
|
| 72 |
+
# dispatching every character through `isStrSpace`. The recorded
|
| 73 |
+
# markers are identical to the previous per-character scan.
|
| 74 |
+
start = 0
|
| 75 |
+
length = len(self.src)
|
| 76 |
+
find = self.src.find
|
| 77 |
+
|
| 78 |
+
while start < length:
|
| 79 |
+
end = find("\n", start)
|
| 80 |
+
if end < 0:
|
| 81 |
+
end = length
|
| 82 |
+
indent = offset = 0
|
| 83 |
+
pos = start
|
| 84 |
+
while pos < end:
|
| 85 |
+
character = self.src[pos]
|
| 86 |
+
if not isStrSpace(character):
|
| 87 |
+
break
|
| 88 |
+
indent += 1
|
| 89 |
+
if character == "\t":
|
| 90 |
+
offset += 4 - offset % 4
|
| 91 |
+
else:
|
| 92 |
+
offset += 1
|
| 93 |
+
pos += 1
|
| 94 |
+
if pos == end == length:
|
| 95 |
+
# A final line of only spaces/tabs with no "\n" gets no marker,
|
| 96 |
+
# matching upstream markdown-it's per-character scan.
|
| 97 |
+
break
|
| 98 |
+
self.bMarks.append(start)
|
| 99 |
+
self.eMarks.append(end)
|
| 100 |
+
self.tShift.append(indent)
|
| 101 |
+
self.sCount.append(offset)
|
| 102 |
+
self.bsCount.append(0)
|
| 103 |
+
start = end + 1 if end < length else length
|
| 104 |
+
|
| 105 |
+
# Push fake entry to simplify cache bounds checks
|
| 106 |
+
self.bMarks.append(length)
|
| 107 |
+
self.eMarks.append(length)
|
| 108 |
+
self.tShift.append(0)
|
| 109 |
+
self.sCount.append(0)
|
| 110 |
+
self.bsCount.append(0)
|
| 111 |
+
|
| 112 |
+
self.lineMax = len(self.bMarks) - 1 # don't count last fake line
|
| 113 |
+
|
| 114 |
+
# pre-check if code blocks are enabled, to speed up is_code_block method
|
| 115 |
+
self._code_enabled = "code" in self.md["block"].ruler.get_active_rules()
|
| 116 |
+
|
| 117 |
+
def __repr__(self) -> str:
|
| 118 |
+
return (
|
| 119 |
+
f"{self.__class__.__name__}"
|
| 120 |
+
f"(line={self.line},level={self.level},tokens={len(self.tokens)})"
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
def push(self, ttype: str, tag: str, nesting: Literal[-1, 0, 1]) -> Token:
|
| 124 |
+
"""Push new token to "stream"."""
|
| 125 |
+
token = Token(ttype, tag, nesting)
|
| 126 |
+
token.block = True
|
| 127 |
+
if nesting < 0:
|
| 128 |
+
self.level -= 1 # closing tag
|
| 129 |
+
token.level = self.level
|
| 130 |
+
if nesting > 0:
|
| 131 |
+
self.level += 1 # opening tag
|
| 132 |
+
self.tokens.append(token)
|
| 133 |
+
return token
|
| 134 |
+
|
| 135 |
+
def isEmpty(self, line: int) -> bool:
|
| 136 |
+
"""."""
|
| 137 |
+
return (self.bMarks[line] + self.tShift[line]) >= self.eMarks[line]
|
| 138 |
+
|
| 139 |
+
def skipEmptyLines(self, from_pos: int) -> int:
|
| 140 |
+
"""."""
|
| 141 |
+
while from_pos < self.lineMax:
|
| 142 |
+
try:
|
| 143 |
+
if (self.bMarks[from_pos] + self.tShift[from_pos]) < self.eMarks[
|
| 144 |
+
from_pos
|
| 145 |
+
]:
|
| 146 |
+
break
|
| 147 |
+
except IndexError:
|
| 148 |
+
pass
|
| 149 |
+
from_pos += 1
|
| 150 |
+
return from_pos
|
| 151 |
+
|
| 152 |
+
def skipSpaces(self, pos: int) -> int:
|
| 153 |
+
"""Skip spaces from given position."""
|
| 154 |
+
while True:
|
| 155 |
+
try:
|
| 156 |
+
current = self.src[pos]
|
| 157 |
+
except IndexError:
|
| 158 |
+
break
|
| 159 |
+
if not isStrSpace(current):
|
| 160 |
+
break
|
| 161 |
+
pos += 1
|
| 162 |
+
return pos
|
| 163 |
+
|
| 164 |
+
def skipSpacesBack(self, pos: int, minimum: int) -> int:
|
| 165 |
+
"""Skip spaces from given position in reverse."""
|
| 166 |
+
if pos <= minimum:
|
| 167 |
+
return pos
|
| 168 |
+
while pos > minimum:
|
| 169 |
+
pos -= 1
|
| 170 |
+
if not isStrSpace(self.src[pos]):
|
| 171 |
+
return pos + 1
|
| 172 |
+
return pos
|
| 173 |
+
|
| 174 |
+
def skipChars(self, pos: int, code: int) -> int:
|
| 175 |
+
"""Skip character code from given position."""
|
| 176 |
+
while True:
|
| 177 |
+
try:
|
| 178 |
+
current = self.srcCharCode[pos]
|
| 179 |
+
except IndexError:
|
| 180 |
+
break
|
| 181 |
+
if current != code:
|
| 182 |
+
break
|
| 183 |
+
pos += 1
|
| 184 |
+
return pos
|
| 185 |
+
|
| 186 |
+
def skipCharsStr(self, pos: int, ch: str) -> int:
|
| 187 |
+
"""Skip character string from given position."""
|
| 188 |
+
while True:
|
| 189 |
+
try:
|
| 190 |
+
current = self.src[pos]
|
| 191 |
+
except IndexError:
|
| 192 |
+
break
|
| 193 |
+
if current != ch:
|
| 194 |
+
break
|
| 195 |
+
pos += 1
|
| 196 |
+
return pos
|
| 197 |
+
|
| 198 |
+
def skipCharsBack(self, pos: int, code: int, minimum: int) -> int:
|
| 199 |
+
"""Skip character code reverse from given position - 1."""
|
| 200 |
+
if pos <= minimum:
|
| 201 |
+
return pos
|
| 202 |
+
while pos > minimum:
|
| 203 |
+
pos -= 1
|
| 204 |
+
if code != self.srcCharCode[pos]:
|
| 205 |
+
return pos + 1
|
| 206 |
+
return pos
|
| 207 |
+
|
| 208 |
+
def skipCharsStrBack(self, pos: int, ch: str, minimum: int) -> int:
|
| 209 |
+
"""Skip character string reverse from given position - 1."""
|
| 210 |
+
if pos <= minimum:
|
| 211 |
+
return pos
|
| 212 |
+
while pos > minimum:
|
| 213 |
+
pos -= 1
|
| 214 |
+
if ch != self.src[pos]:
|
| 215 |
+
return pos + 1
|
| 216 |
+
return pos
|
| 217 |
+
|
| 218 |
+
def getLines(self, begin: int, end: int, indent: int, keepLastLF: bool) -> str:
|
| 219 |
+
"""Cut lines range from source."""
|
| 220 |
+
line = begin
|
| 221 |
+
if begin >= end:
|
| 222 |
+
return ""
|
| 223 |
+
|
| 224 |
+
queue = [""] * (end - begin)
|
| 225 |
+
|
| 226 |
+
i = 1
|
| 227 |
+
while line < end:
|
| 228 |
+
lineIndent = 0
|
| 229 |
+
lineStart = first = self.bMarks[line]
|
| 230 |
+
last = (
|
| 231 |
+
self.eMarks[line] + 1
|
| 232 |
+
if line + 1 < end or keepLastLF
|
| 233 |
+
else self.eMarks[line]
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
while (first < last) and (lineIndent < indent):
|
| 237 |
+
ch = self.src[first]
|
| 238 |
+
if isStrSpace(ch):
|
| 239 |
+
if ch == "\t":
|
| 240 |
+
lineIndent += 4 - (lineIndent + self.bsCount[line]) % 4
|
| 241 |
+
else:
|
| 242 |
+
lineIndent += 1
|
| 243 |
+
elif first - lineStart < self.tShift[line]:
|
| 244 |
+
lineIndent += 1
|
| 245 |
+
else:
|
| 246 |
+
break
|
| 247 |
+
first += 1
|
| 248 |
+
|
| 249 |
+
if lineIndent > indent:
|
| 250 |
+
# partially expanding tabs in code blocks, e.g '\t\tfoobar'
|
| 251 |
+
# with indent=2 becomes ' \tfoobar'
|
| 252 |
+
queue[i - 1] = (" " * (lineIndent - indent)) + self.src[first:last]
|
| 253 |
+
else:
|
| 254 |
+
queue[i - 1] = self.src[first:last]
|
| 255 |
+
|
| 256 |
+
line += 1
|
| 257 |
+
i += 1
|
| 258 |
+
|
| 259 |
+
return "".join(queue)
|
| 260 |
+
|
| 261 |
+
def is_code_block(self, line: int) -> bool:
|
| 262 |
+
"""Check if line is a code block,
|
| 263 |
+
i.e. the code block rule is enabled and text is indented by more than 3 spaces.
|
| 264 |
+
"""
|
| 265 |
+
return self._code_enabled and (self.sCount[line] - self.blkIndent) >= 4
|
venv/lib/python3.14/site-packages/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, mdTrim
|
| 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 = mdTrim(columns[i])
|
| 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 = mdTrim(getLine(state, startLine))
|
| 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 = mdTrim(columns[i])
|
| 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 = mdTrim(getLine(state, nextLine))
|
| 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 = mdTrim(columns[i]) 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
|
venv/lib/python3.14/site-packages/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
|
venv/lib/python3.14/site-packages/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)
|