pax_global_header 0000666 0000000 0000000 00000000064 14152347745 0014526 g ustar 00root root 0000000 0000000 52 comment=aba72e6347e0c7ae8df9111a7d69cf0ab4bbf961
mdit-py-plugins-0.3.0/ 0000775 0000000 0000000 00000000000 14152347745 0014570 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/.github/ 0000775 0000000 0000000 00000000000 14152347745 0016130 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14152347745 0020165 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/.github/workflows/tests.yml 0000664 0000000 0000000 00000003570 14152347745 0022057 0 ustar 00root root 0000000 0000000 # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: continuous-integration
on:
push:
branches: [master]
tags:
- 'v*'
pull_request:
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: pre-commit/action@v2.0.0
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [pypy3, 3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[testing]
- name: Run pytest
run: |
pytest --cov=mdit_py_plugins --cov-report=xml --cov-report=term-missing
- name: Upload to Codecov
uses: codecov/codecov-action@v1
with:
name: mdit-py-plugins-pytests
flags: pytests
file: ./coverage.xml
fail_ci_if_error: true
publish:
name: Publish to PyPi
needs: [pre-commit, tests]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Build package
run: |
pip install build
python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@v1.1.0
with:
user: __token__
password: ${{ secrets.PYPI_KEY }}
mdit-py-plugins-0.3.0/.gitignore 0000664 0000000 0000000 00000003612 14152347745 0016562 0 ustar 00root root 0000000 0000000 # Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
benchmark/extra/
node_modules/
coverage/
demo/
apidoc/
*.log
__pycache__/
.ropeproject/
*.egg-info/
.vscode/
.DS_Store
docs/api/
mdit-py-plugins-0.3.0/.pre-commit-config.yaml 0000664 0000000 0000000 00000002333 14152347745 0021052 0 ustar 00root root 0000000 0000000 # Install pre-commit hooks via
# pre-commit install
exclude: >
(?x)^(
\.vscode/settings\.json|
test.*\.md|
test.*\.txt|
test.*\.html|
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/mgedmin/check-manifest
rev: "0.46"
hooks:
- id: check-manifest
args: [--no-build-isolation]
additional_dependencies: [setuptools>=46.4.0]
# this is not used for now,
# since it converts mdit-py-plugins to mdit_py_plugins and removes comments
# - repo: https://github.com/asottile/setup-cfg-fmt
# rev: v1.17.0
# hooks:
# - id: setup-cfg-fmt
- repo: https://github.com/timothycrosley/isort
rev: 5.8.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.1
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==21.3.1]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
hooks:
- id: mypy
additional_dependencies: [markdown-it-py~=1.0]
mdit-py-plugins-0.3.0/.readthedocs.yml 0000664 0000000 0000000 00000000227 14152347745 0017657 0 ustar 00root root 0000000 0000000 version: 2
python:
version: 3
install:
- method: pip
path: .
extra_requirements: [rtd]
sphinx:
builder: html
fail_on_warning: true
mdit-py-plugins-0.3.0/CHANGELOG.md 0000664 0000000 0000000 00000003075 14152347745 0016406 0 ustar 00root root 0000000 0000000 # Change Log
## 0.3.0 - 2021-12-03
- ⬆️ UPGRADE: Compatible with markdown-it-py `v2`.
- ✨ NEW: Add field list plugin, Based on the [restructuredtext syntax](https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#field-lists)
- ♻️ REFACTOR: dollarmath plugin, `math_block_eqno` -> `math_block_label` token
- ♻️ REFACTOR: Remove AttrDict usage from texmath
- 👌 IMPROVE: Default HTML rendering for dollarmath and amsmath plugins
- 👌 IMPROVE: Add render options for dollarmath and amsmath plugins
- 👌 IMPROVE: MyST parsing of target blocks (allow whitespace) and roles (allow for new lines)
## 0.2.8 - 2021-05-03
🐛 FIX: `wordcount` update of minutes
## 0.2.7 - 2021-05-03
- ⬆️ UPDATE: markdown-it-py~=1.0
- ✨ NEW: Add `wordcount_plugin`
- 👌 IMPROVE: `dollarmath`: Allow inline double-dollar
- 👌 IMPROVE: `myst_blocks`: Parse multiline comments
- 👌 IMPROVE: Replace use of `env` as an `AttrDict`
- 🐛 FIX: `front_matter`: don't duplicate content storage in `Token.meta`
## 0.2.6 - 2021-03-17
👌 IMPROVE: Remove direct use of `Token.attrs`
## 0.2.5 - 2021-02-06
🐛 FIX: front-matter: `IndexError` if first line is single dash
## 0.2.2 - 2020-12-16
✨ NEW: Add substitution_plugin
(improvements in 0.2.3 and 0.2.4)
## 0.2.0 - 2020-12-14
Add mypy type-checking, code taken from: https://github.com/executablebooks/markdown-it-py/commit/2eb1fe6b47cc0ad4ebe954cabd91fb8e52a2f03d
## 0.1.0 - 2020-12-14
First release, code taken from: https://github.com/executablebooks/markdown-it-py/commit/3a5bdcc98e67de9df26ebb8bc7cd0221a0d6b51b
mdit-py-plugins-0.3.0/LICENSE 0000664 0000000 0000000 00000002066 14152347745 0015601 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2020 ExecutableBookProject
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
mdit-py-plugins-0.3.0/MANIFEST.in 0000664 0000000 0000000 00000000524 14152347745 0016327 0 ustar 00root root 0000000 0000000 exclude docs
recursive-exclude docs *
exclude tests
recursive-exclude tests *
exclude .pre-commit-config.yaml
exclude .readthedocs.yml
exclude tox.ini
exclude .flake8
exclude codecov.yml
exclude .mypy.ini
include LICENSE
include CHANGELOG.md
include mdit_py_plugins/py.typed
recursive-include mdit_py_plugins port.yaml LICENSE README.md
mdit-py-plugins-0.3.0/README.md 0000664 0000000 0000000 00000002262 14152347745 0016051 0 ustar 00root root 0000000 0000000 # mdit-py-plugins
[![Github-CI][github-ci]][github-link]
[![Coverage Status][codecov-badge]][codecov-link]
[![PyPI][pypi-badge]][pypi-link]
[![Conda][conda-badge]][conda-link]
[![Code style: black][black-badge]][black-link]
Collection of core plugins for [markdown-it-py](https://github.com/executablebooks/markdown-it-py).
[github-ci]: https://github.com/executablebooks/mdit-py-plugins/workflows/continuous-integration/badge.svg
[github-link]: https://github.com/executablebooks/mdit-py-plugins
[pypi-badge]: https://img.shields.io/pypi/v/mdit-py-plugins.svg
[pypi-link]: https://pypi.org/project/mdit-py-plugins
[conda-badge]: https://anaconda.org/conda-forge/mdit-py-plugins/badges/version.svg
[conda-link]: https://anaconda.org/conda-forge/mdit-py-plugins
[codecov-badge]: https://codecov.io/gh/executablebooks/mdit-py-plugins/branch/master/graph/badge.svg
[codecov-link]: https://codecov.io/gh/executablebooks/mdit-py-plugins
[black-badge]: https://img.shields.io/badge/code%20style-black-000000.svg
[black-link]: https://github.com/ambv/black
[install-badge]: https://img.shields.io/pypi/dw/mdit-py-plugins?label=pypi%20installs
[install-link]: https://pypistats.org/packages/mdit-py-plugins
mdit-py-plugins-0.3.0/codecov.yml 0000664 0000000 0000000 00000000242 14152347745 0016733 0 ustar 00root root 0000000 0000000 coverage:
status:
project:
default:
target: 93%
threshold: 0.2%
patch:
default:
target: 80%
threshold: 0.2%
mdit-py-plugins-0.3.0/docs/ 0000775 0000000 0000000 00000000000 14152347745 0015520 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/docs/conf.py 0000664 0000000 0000000 00000001360 14152347745 0017017 0 ustar 00root root 0000000 0000000 project = "mdit-py-plugins"
copyright = "2020, Executable Book Project"
author = "Executable Book Project"
master_doc = "index"
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"myst_parser",
]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
intersphinx_mapping = {
"python": ("https://docs.python.org/3.8", None),
"markdown_it": ("https://markdown-it-py.readthedocs.io/en/latest", None),
}
html_title = "mdit-py-plugins"
html_theme = "sphinx_book_theme"
html_theme_options = {
"single_page": True,
"use_edit_page_button": True,
"repository_url": "https://github.com/executablebooks/mdit-py-plugins",
"repository_branch": "master",
"path_to_docs": "docs",
}
mdit-py-plugins-0.3.0/docs/index.md 0000664 0000000 0000000 00000005711 14152347745 0017155 0 ustar 00root root 0000000 0000000 # Markdown-It-Py Plugin Extensions
## Built-in
The following plugins are embedded within the core package:
- [tables](https://help.github.com/articles/organizing-information-with-tables/) (GFM)
- [strikethrough](https://help.github.com/articles/basic-writing-and-formatting-syntax/#styling-text) (GFM)
These can be enabled individually:
```python
from markdown_it import MarkdownIt
md = MarkdownIt("commonmark").enable('table')
```
or as part of a configuration:
```python
from markdown_it import MarkdownIt
md = MarkdownIt("gfm-like")
```
```{seealso}
See [](markdown_it:using)
```
## mdit-py-plugins package
The [`mdit_py_plugins`](https://github.com/executablebooks/mdit-py-plugins), contains a number of common plugins.
They can be chained and loaded *via*:
```python
from markdown_it import MarkdownIt
from mdit_py_plugins import plugin1, plugin2
md = MarkdownIt().use(plugin1, keyword=value).use(plugin2, keyword=value)
html_string = md.render("some *Markdown*")
```
## Front-Matter
```{eval-rst}
.. autofunction:: mdit_py_plugins.front_matter.front_matter_plugin
```
## Footnotes
```{eval-rst}
.. autofunction:: mdit_py_plugins.footnote.footnote_plugin
```
## Definition Lists
```{eval-rst}
.. autofunction:: mdit_py_plugins.deflist.deflist_plugin
```
## Task lists
```{eval-rst}
.. autofunction:: mdit_py_plugins.tasklists.tasklists_plugin
```
## Field Lists
```{eval-rst}
.. autofunction:: mdit_py_plugins.field_list.fieldlist_plugin
```
## Heading Anchors
```{eval-rst}
.. autofunction:: mdit_py_plugins.anchors.anchors_plugin
```
## Word Count
```{eval-rst}
.. autofunction:: mdit_py_plugins.wordcount.wordcount_plugin
```
## Containers
```{eval-rst}
.. autofunction:: mdit_py_plugins.container.container_plugin
```
## Math
```{eval-rst}
.. autofunction:: mdit_py_plugins.texmath.texmath_plugin
```
```{eval-rst}
.. autofunction:: mdit_py_plugins.dollarmath.dollarmath_plugin
```
```{eval-rst}
.. autofunction:: mdit_py_plugins.amsmath.amsmath_plugin
```
## MyST plugins
`myst_blocks` and `myst_role` plugins are also available, for utilisation by the [MyST renderer](https://myst-parser.readthedocs.io/en/latest/using/syntax.html)
```{eval-rst}
.. autofunction:: mdit_py_plugins.myst_role.myst_role_plugin
.. autofunction:: mdit_py_plugins.myst_blocks.myst_block_plugin
```
## Write your own
Use the `mdit_py_plugins` as a guide to write your own, following the [markdown-it design principles](markdown_it:architecture).
There are many other plugins which could easily be ported from the JS versions (and hopefully will):
- [subscript](https://github.com/markdown-it/markdown-it-sub)
- [superscript](https://github.com/markdown-it/markdown-it-sup)
- [abbreviation](https://github.com/markdown-it/markdown-it-abbr)
- [emoji](https://github.com/markdown-it/markdown-it-emoji)
- [insert](https://github.com/markdown-it/markdown-it-ins)
- [mark](https://github.com/markdown-it/markdown-it-mark)
- ... and [others](https://www.npmjs.org/browse/keyword/markdown-it-plugin)
mdit-py-plugins-0.3.0/mdit_py_plugins/ 0000775 0000000 0000000 00000000000 14152347745 0017776 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/mdit_py_plugins/__init__.py 0000664 0000000 0000000 00000000026 14152347745 0022105 0 ustar 00root root 0000000 0000000 __version__ = "0.3.0"
mdit-py-plugins-0.3.0/mdit_py_plugins/amsmath/ 0000775 0000000 0000000 00000000000 14152347745 0021430 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/mdit_py_plugins/amsmath/__init__.py 0000664 0000000 0000000 00000010232 14152347745 0023537 0 ustar 00root root 0000000 0000000 """An extension to capture amsmath latex environments."""
import re
from typing import Callable, Optional
from markdown_it import MarkdownIt
from markdown_it.common.utils import escapeHtml
from markdown_it.rules_block import StateBlock
# Taken from amsmath version 2.1
# http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/required/amsmath/amsldoc.pdf
ENVIRONMENTS = [
# 3.2 single equation with an automatically gen-erated number
"equation",
# 3.3 variation equation, used for equations that don’t fit on a single line
"multline",
# 3.5 a group of consecutive equations when there is no alignment desired among them
"gather",
# 3.6 Used for two or more equations when vertical alignment is desired
"align",
# allows the horizontal space between equationsto be explicitly specified.
"alignat",
# stretches the space betweenthe equation columns to the maximum possible width
"flalign",
# 4.1 The pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix have (respectively)
# (),[],{},||,and ‖‖ delimiters built in.
"matrix",
"pmatrix",
"bmatrix",
"Bmatrix",
"vmatrix",
"Vmatrix",
# eqnarray is another math environment, it is not part of amsmath,
# and note that it is better to use align or equation+split instead
"eqnarray",
]
# other "non-top-level" environments:
# 3.4 the split environment is for single equations that are too long to fit on one line
# and hence must be split into multiple lines,
# it is intended for use only inside some other displayed equation structure,
# usually an equation, align, or gather environment
# 3.7 variants gathered, aligned,and alignedat are provided
# whose total width is the actual width of the contents;
# thus they can be used as a component in a containing expression
RE_OPEN = re.compile(r"\\begin\{(" + "|".join(ENVIRONMENTS) + r")([\*]?)\}")
def amsmath_plugin(md: MarkdownIt, *, renderer: Optional[Callable[[str], str]] = None):
"""Parses TeX math equations, without any surrounding delimiters,
only for top-level `amsmath content ::
foo
:: bbb foo baz blah blah content :: name
content
:: hello world xxx this block is closed with 5 markers below auto-closed block :::: content
::: not a code block xxx xxx xxx xxx
::: arg=123 ::: namename
xxx
::: xxx blah blah content xxx yyy
zzz xxx
yyy ::: xxx yyy
::: Definition 1 Definition 2 Third paragraph of definition 2. Definition
with lazy continuation. Second paragraph of the definition. Non-term 1
: Non-term 2
: foo bar foo bar foo bar
Term 2 foo : just a paragraph with a colon bar test test $ $$ a \\varphi 1+1=2 1+1<3 a \\backslash 3$1+2$ $1+2$3 If you solve 1+2 you get $3 \\frac{1}{2} \\begin{pmatrix}x\\\\y\\end{pmatrix} {\\tilde\\bold e}_\\alpha a^{b} a^\*b with a^\* a a
\not=1 b a $a \not=1$ b {e}_x a1+1=2
1+1=2b
cxd x $ x y so-what is x \\sum\_{i=1}^n see a = b + c
c^2=a^2+b^2 (2)
c^2=a^2+b^2 formula in blockquote. \1+1=2
1+1=2\\ some text
$\$a+b=c$$ $ $
$ x$
$x $ $$ a+b\n=c$$ $p_2 = $a $p_2 = $a p_2 = \$1 \p_2 = 1 p_2 = \\aTitle String ¶
:param min_level: minimum header level to apply anchors
:param max_level: maximum header level to apply anchors
:param slug_func: function to convert title text to id slug.
:param permalink: Add a permalink next to the title
:param permalinkSymbol: the symbol to show
:param permalinkBefore: Add the permalink before the title, otherwise after
:param permalinkSpace: Add a space between the permalink and the title
Note, the default slug function aims to mimic the GitHub Markdown format, see:
- https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb
- https://gist.github.com/asabaylus/3071099
"""
selected_levels = list(range(min_level, max_level + 1))
md.core.ruler.push(
"anchor",
_make_anchors_func(
selected_levels,
slug_func or slugify,
permalink,
permalinkSymbol,
permalinkBefore,
permalinkSpace,
),
)
def _make_anchors_func(
selected_levels: List[int],
slug_func: Callable[[str], str],
permalink: bool,
permalinkSymbol: str,
permalinkBefore: bool,
permalinkSpace: bool,
):
slugs: Set[str] = set()
def _anchor_func(state: StateCore):
for (idx, token) in enumerate(state.tokens):
if token.type != "heading_open":
continue
level = int(token.tag[1])
if level not in selected_levels:
continue
inline_token = state.tokens[idx + 1]
assert inline_token.children is not None
title = "".join(
child.content
for child in inline_token.children
if child.type in ["text", "code_inline"]
)
slug = unique_slug(slug_func(title), slugs)
token.attrSet("id", slug)
if permalink:
link_open = Token(
"link_open",
"a",
1,
)
link_open.attrSet("class", "header-anchor")
link_open.attrSet("href", f"#{slug}")
link_tokens = [
link_open,
Token("html_block", "", 0, content=permalinkSymbol),
Token("link_close", "a", -1),
]
if permalinkBefore:
inline_token.children = (
link_tokens
+ (
[Token("text", "", 0, content=" ")]
if permalinkSpace
else []
)
+ inline_token.children
)
else:
inline_token.children.extend(
([Token("text", "", 0, content=" ")] if permalinkSpace else [])
+ link_tokens
)
return _anchor_func
def slugify(title: str):
return re.sub(r"[^\w\u4e00-\u9fff\- ]", "", title.strip().lower().replace(" ", "-"))
def unique_slug(slug: str, slugs: set):
uniq = slug
i = 1
while uniq in slugs:
uniq = f"{slug}-{i}"
i += 1
slugs.add(uniq)
return uniq
mdit-py-plugins-0.3.0/mdit_py_plugins/colon_fence.py 0000664 0000000 0000000 00000006422 14152347745 0022626 0 ustar 00root root 0000000 0000000 from markdown_it import MarkdownIt
from markdown_it.common.utils import escapeHtml, unescapeAll
from markdown_it.rules_block import StateBlock
def colon_fence_plugin(md: MarkdownIt):
"""This plugin directly mimics regular fences, but with `:` colons.
Example::
:::name
contained text
:::
"""
md.block.ruler.before(
"fence",
"colon_fence",
_rule,
{"alt": ["paragraph", "reference", "blockquote", "list", "footnote_def"]},
)
md.add_render_rule("colon_fence", _render)
def _rule(state: StateBlock, startLine: int, endLine: int, silent: bool):
haveEndMarker = False
pos = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]
# if it's indented more than 3 spaces, it should be a code block
if state.sCount[startLine] - state.blkIndent >= 4:
return False
if pos + 3 > maximum:
return False
marker = state.srcCharCode[pos]
# /* : */
if marker != 0x3A:
return False
# scan marker length
mem = pos
pos = state.skipChars(pos, marker)
length = pos - mem
if length < 3:
return False
markup = state.src[mem:pos]
params = state.src[pos:maximum]
# Since start is found, we can report success here in validation mode
if silent:
return True
# search end of block
nextLine = startLine
while True:
nextLine += 1
if nextLine >= endLine:
# unclosed block should be autoclosed by end of document.
# also block seems to be autoclosed by end of parent
break
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine]
maximum = state.eMarks[nextLine]
if pos < maximum and state.sCount[nextLine] < state.blkIndent:
# non-empty line with negative indent should stop the list:
# - ```
# test
break
if state.srcCharCode[pos] != marker:
continue
if state.sCount[nextLine] - state.blkIndent >= 4:
# closing fence should be indented less than 4 spaces
continue
pos = state.skipChars(pos, marker)
# closing code fence must be at least as long as the opening one
if pos - mem < length:
continue
# make sure tail has spaces only
pos = state.skipSpaces(pos)
if pos < maximum:
continue
haveEndMarker = True
# found!
break
# If a fence has heading spaces, they should be removed from its inner block
length = state.sCount[startLine]
state.line = nextLine + (1 if haveEndMarker else 0)
token = state.push("colon_fence", "code", 0)
token.info = params
token.content = state.getLines(startLine + 1, nextLine, length, True)
token.markup = markup
token.map = [startLine, state.line]
return True
def _render(self, tokens, idx, options, env):
token = tokens[idx]
info = unescapeAll(token.info).strip() if token.info else ""
content = escapeHtml(token.content)
block_name = ""
if info:
block_name = info.split()[0]
return (
"
\n"
)
mdit-py-plugins-0.3.0/mdit_py_plugins/container/ 0000775 0000000 0000000 00000000000 14152347745 0021760 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/mdit_py_plugins/container/LICENSE 0000664 0000000 0000000 00000002061 14152347745 0022764 0 ustar 00root root 0000000 0000000 Copyright (c) 2015 Vitaly Puzrin, Alex Kocharin.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
mdit-py-plugins-0.3.0/mdit_py_plugins/container/README.md 0000664 0000000 0000000 00000004745 14152347745 0023251 0 ustar 00root root 0000000 0000000 # markdown-it-container
[](https://travis-ci.org/markdown-it/markdown-it-container)
[](https://www.npmjs.org/package/markdown-it-container)
[](https://coveralls.io/r/markdown-it/markdown-it-container?branch=master)
> Plugin for creating block-level custom containers for [markdown-it](https://github.com/markdown-it/markdown-it) markdown parser.
__v2.+ requires `markdown-it` v5.+, see changelog.__
With this plugin you can create block containers like:
```
::: warning
*here be dragons*
:::
```
.... and specify how they should be rendered. If no renderer defined, `"
+ content
+ "' + md.utils.escapeHtml(m[1]) + '
\n';
} else {
// closing tag
return 'click me
// `) tag plugin for [markdown-it](https://github.com/markdown-it/markdown-it) markdown parser.
__v2.+ requires `markdown-it` v5.+, see changelog.__
Syntax is based on [pandoc definition lists](http://johnmacfarlane.net/pandoc/README.html#definition-lists).
## Install
node.js, browser:
```bash
npm install markdown-it-deflist --save
bower install markdown-it-deflist --save
```
## Use
```js
var md = require('markdown-it')()
.use(require('markdown-it-deflist'));
md.render(/*...*/);
```
_Differences in browser._ If you load script directly into the page, without
package system, module will add itself globally as `window.markdownitDeflist`.
## License
[MIT](https://github.com/markdown-it/markdown-it-deflist/blob/master/LICENSE)
mdit-py-plugins-0.3.0/mdit_py_plugins/deflist/__init__.py 0000664 0000000 0000000 00000000057 14152347745 0023543 0 ustar 00root root 0000000 0000000 from .index import deflist_plugin # noqa F401
mdit-py-plugins-0.3.0/mdit_py_plugins/deflist/index.py 0000664 0000000 0000000 00000016403 14152347745 0023115 0 ustar 00root root 0000000 0000000 """Process definition lists."""
from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock
def deflist_plugin(md: MarkdownIt):
"""Plugin ported from
`markdown-it-deflist
\n'
if options.xhtmlOut
else '
\n'
)
+ '\n'
)
def render_footnote_block_close(self, tokens, idx, options, env):
return "
\n' f"{{{name}}}[{escapeHtml(token.content)}]" ""
)
mdit-py-plugins-0.3.0/mdit_py_plugins/py.typed 0000664 0000000 0000000 00000000032 14152347745 0021470 0 ustar 00root root 0000000 0000000 # Marker file for PEP 561
mdit-py-plugins-0.3.0/mdit_py_plugins/substitution.py 0000664 0000000 0000000 00000006226 14152347745 0023132 0 ustar 00root root 0000000 0000000 from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock
from markdown_it.rules_inline import StateInline
def substitution_plugin(
md: MarkdownIt, start_delimiter: str = "{", end_delimiter: str = "}"
):
"""A plugin to create substitution tokens.
These, token should be handled by the renderer.
Example::
{{ block }}
a {{ inline }} b
"""
start_char = ord(start_delimiter)
end_char = ord(end_delimiter)
def _substitution_inline(state: StateInline, silent: bool):
try:
if (
state.srcCharCode[state.pos] != start_char
or state.srcCharCode[state.pos + 1] != start_char
):
return False
except IndexError:
return False
pos = state.pos + 2
found_closing = False
while True:
try:
end = state.srcCharCode.index(end_char, pos)
except ValueError:
return False
try:
if state.srcCharCode[end + 1] == end_char:
found_closing = True
break
except IndexError:
return False
pos = end + 2
if not found_closing:
return False
text = state.src[state.pos + 2 : end].strip()
state.pos = end + 2
if silent:
return True
token = state.push("substitution_inline", "span", 0)
token.block = False
token.content = text
token.attrSet("class", "substitution")
token.attrSet("text", text)
token.markup = f"{start_delimiter}{end_delimiter}"
return True
def _substitution_block(
state: StateBlock, startLine: int, endLine: int, silent: bool
):
startPos = state.bMarks[startLine] + state.tShift[startLine]
end = state.eMarks[startLine]
# if it's indented more than 3 spaces, it should be a code block
if state.sCount[startLine] - state.blkIndent >= 4:
return False
lineText = state.src[startPos:end].strip()
try:
if (
lineText[0] != start_delimiter
or lineText[1] != start_delimiter
or lineText[-1] != end_delimiter
or lineText[-2] != end_delimiter
or len(lineText) < 5
):
return False
except IndexError:
return False
text = lineText[2:-2].strip()
# special case if multiple on same line, e.g. {{a}}{{b}}
if (end_delimiter * 2) in text:
return False
state.line = startLine + 1
if silent:
return True
token = state.push("substitution_block", "div", 0)
token.block = True
token.content = text
token.attrSet("class", "substitution")
token.attrSet("text", text)
token.markup = f"{start_delimiter}{end_delimiter}"
token.map = [startLine, state.line]
return True
md.block.ruler.before("fence", "substitution_block", _substitution_block)
md.inline.ruler.before("escape", "substitution_inline", _substitution_inline)
mdit-py-plugins-0.3.0/mdit_py_plugins/tasklists/ 0000775 0000000 0000000 00000000000 14152347745 0022017 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/mdit_py_plugins/tasklists/__init__.py 0000664 0000000 0000000 00000013055 14152347745 0024134 0 ustar 00root root 0000000 0000000 """Builds task/todo lists out of markdown lists with items starting with [ ] or [x]"""
# Ported by Wolmar Nyberg Åkerström from https://github.com/revin/markdown-it-task-lists
# ISC License
# Copyright (c) 2016, Revin Guillen
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from typing import List
from uuid import uuid4
from markdown_it import MarkdownIt
from markdown_it.token import Token
def tasklists_plugin(
md: MarkdownIt,
enabled: bool = False,
label: bool = False,
label_after: bool = False,
):
"""Plugin for building task/todo lists out of markdown lists with items starting with [ ] or [x]
.. Nothing else
For example::
- [ ] An item that needs doing
- [x] An item that is complete
The rendered HTML checkboxes are disabled; to change this, pass a truthy value into the enabled
property of the plugin options.
:param enabled: True enables the rendered checkboxes
:param label: True wraps the rendered list items in a H1
H2
H3
.
space:
.
# a b c
.
a b c
.
characters:
.
# a,b\cβÊ
.
a,b\cβÊ
.
emoji:
.
# 🚀a
.
🚀a
.
html entity:
.
# foo&bar
.
foo&bar
.
uniqueness:
.
# a
# a
## a
.
a
a
a
.
standard (permalink after):
.
# a
.
a ¶
.
standard (permalink before):
.
# a
.
¶ a
.
mdit-py-plugins-0.3.0/tests/fixtures/colon_fence.md 0000664 0000000 0000000 00000007705 14152347745 0022410 0 ustar 00root root 0000000 0000000 # The initial tests are adapted from the test for normal code fences in tests/test_port/fixtures/commonmark_spec.md
src line: 1638
.
:::
<
>
:::
.
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1665
.
::
foo
::
.
<
>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1688
.
:::
aaa
```
:::
.
aaa
~~~
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1702
.
::::
aaa
:::
::::::
.
aaa
```
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1729
.
:::
.
aaa
:::
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1736
.
:::::
:::
aaa
.
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1749
.
> :::
> aaa
bbb
.
:::
aaa
aaa
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1779
.
:::
:::
.
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1791
.
:::
aaa
aaa
:::
.
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1803
.
:::
aaa
aaa
aaa
:::
.
aaa
aaa
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1817
.
:::
aaa
aaa
aaa
:::
.
aaa
aaa
aaa
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1833
.
:::
aaa
:::
.
aaa
aaa
aaa
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1848
.
:::
aaa
:::
.
:::
aaa
:::
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1858
.
:::
aaa
:::
.
aaa
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1870
.
:::
aaa
:::
.
aaa
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1884
.
::: :::
aaa
.
aaa
:::
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1907
.
foo
:::
bar
:::
baz
.
aaa
bar
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1974
.
::::;
::::
.
def foo(x)
return 3
end
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 1984
.
::: aa :::
foo
.
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 2007
.
:::
::: aaa
:::
.
foo
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 2007
.
:::
::: aaa
:::
.
::: aaa
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ending marker could be longer
.
::::: name :::::
hello world
::::::::::::::::
.
::: aaa
.
Nested blocks
.
::::: name
:::: name
xxx
::::
:::::
.
hello world
.
Name could be adjacent to marker
.
:::name
xxx
:::
.
:::: name
xxx
::::
.
They should terminate paragraphs
.
blah blah
::: name
content
:::
.
xxx
.
They could be nested in lists
.
- ::: name
- xxx
:::
.
content
.
Or in blockquotes
.
> ::: name
> xxx
>> yyy
> zzz
> :::
.
- xxx
.
List indentation quirks
.
- ::: name
xxx
yyy
:::
- ::: name
xxx
yyy
:::
.
xxx
> yyy
zzz
xxx
yyy
.
mdit-py-plugins-0.3.0/tests/fixtures/container.md 0000664 0000000 0000000 00000004725 14152347745 0022117 0 ustar 00root root 0000000 0000000
Simple container
.
::: name
*content*
:::
.
- ::: name
xxx
yyy
heading
.
Some more indent checks
.
::: name
not a code block
code block
:::
.
::: name
content
:::
code block
.
Or in blockquotes
.
> ::: name
> xxx
>> yyy
> zzz
> :::
.
.
List indentation quirks
.
- ::: name
xxx
yyy
:::
- ::: name
xxx
yyy
:::
.
.
Pandoc again:
.
Term 1
: Definition
with lazy continuation.
Second paragraph of the definition.
.
{ some code, part of Definition 2 }
.
Well, I might just copy-paste the third one while I'm at it:
.
Term 1
~ Definition 1
Term 2
~ Definition 2a
~ Definition 2b
.
.
Now, with our custom ones. Spaces after a colon:
.
Term 1
: paragraph
Term 2
: code block
.
.
There should be something after a colon by the way:
.
Non-term 1
:
Non-term 2
:
.
code block
.
Regression test (first paragraphs shouldn't be tight):
.
Term 1
: foo
bar
Term 2
: foo
.
.
Definition lists should be second last in the queue. Exemplī grātiā, this isn't a valid one:
.
# test
: just a paragraph with a colon
.
test
.
Regression test, tabs
.
Term 1
: code block
.
.
Regression test (blockquote inside deflist)
.
foo
: > bar
: baz
.
code block
.
Coverage, 1 blank line
.
test
.
codea-bcode
code
.
Inline sum. (valid=True)
.
$\\sum\_{i=1}^n$
.
.
display equation in blockquote. (valid=True)
.
> formula
>
> $$ a+b=c$$ (2)
>
> in blockquote.
.
.
mixed syntax:
.
$$
a=1 \\
b=2
$$ (abc)
- ab $c=1$ d
.
.
escaped dollars '\\$' are interpreted as
dollar '$' characters. (valid=True)
.
\\$1+1=2$
$1+1=2\\$
.
.
math-escaping: escaped start $:
.
\$p_2 = $a
.
a
a
a $a=1$ b
. Inline mixed single/double dollars: . Hence, for $\alpha \in (0, 1)$, $$ \mathbb P (\alpha \bar{X} \ge \mu) \le \alpha; $$ i.e., $[\alpha \bar{X}, \infty)$ is a lower 1-sided $1-\alpha$ confidence bound for $\mu$. .Hence, for \alpha \in (0, 1),
content
content running onto new line
paragraph 1
paragraph 2
paragraph 3
paragraph 1
paragraph 2
paragraph 1
paragraph 2
::
. Whitespace only name: . : : .: :
. Name markup: . :inline *markup*: .body markup
code
body
code
item 1 item 2
item 1 item 2
code
body
body
block quote
body
code
.
In list:
.
- :name: body
- item 2
.
body
. mdit-py-plugins-0.3.0/tests/fixtures/footnote.md 0000664 0000000 0000000 00000016574 14152347745 0021777 0 ustar 00root root 0000000 0000000 Pandoc example: . Here is a footnote reference,[^1] and another.[^longnote] [^1]: Here is the footnote. [^longnote]: Here's one with multiple blocks. Subsequent paragraphs are indented to show that they belong to the previous footnote. { some.code } The whole paragraph can be indented, or just the first line. In this way, multi-paragraph footnotes work like multi-paragraph list items. This paragraph won't be part of the note, because it isn't indented. .
- name
body
Here is a footnote reference,[1] and another.[2]
This paragraph won't be part of the note, because it isn't indented.
bar baz ↩︎
[^ foo]: bar baz
[^foo ]: bar baz
. We support inline notes too (pandoc example): . Here is an inline note.^[Inlines notes are easier to write, since you don't have to pick an identifier and move down to type the note.] .Here is an inline note.[1]
Inlines notes are easier to write, since you don't have to pick an identifier and move down to type the note. ↩︎
foo[1]
bar ↩︎
foo ↩︎
blah ↩︎
blah ↩︎
Example[1]
this is another example https://github.com ↩︎
terminates here
abc
def hij
↩︎block
b [1]
Some text
c
d ↩︎
++
. Block Break terminates other blocks: . a +++ - b +++ > c +++ .a
c
()=
. Escaped target: . \(a)= .(a)=
. Indented target: . (a)= . . Target terminates other blocks: . a (a-b)= - b (a b)= > c (a)= .a
. Comment: . % abc . . Comment terminates other blocks: . a % abc - b % abc > c % abc .c
a
. Multiline comment: . a % abc % def - b % abc %def > c %abc % %def .c
a
. mdit-py-plugins-0.3.0/tests/fixtures/myst_role.md 0000664 0000000 0000000 00000002236 14152347745 0022145 0 ustar 00root root 0000000 0000000 Basic: . {abc}`xyz` .c
{abc}[xyz]
{abc}[xyz]{def}[uvw]
a {abc}[xyz] b
{abc}[xy z] d e
{abc}`xyz`
{name}`` a
. Surrounding Code: . `a` {abc}`xyz` `b` .a {abc}[xyz] b
{abc}[xyz]. Multiple ticks: . {abc}``xyz`` .
{abc}[xyz]b
{abc}[xyz]
{abc}[x`yz]
{abc}``xyz`
. Space in name: . {ab c}`xyz` .{ab c}xyz
{abc}xyz
a b
. Basic (no space): . {{block}} a {{inline}} b .a b
. Same line: . {{a}}{{b}} .. No closing: . {{ a {{b} {{c} } .
{{ a
{{b}
{{c} }
. Inside code . `{{ a }}` ```python {{b}} ``` .{{ a }}
{{b}}
.
New line:
.
{{a}}
{{b}}
.
.
Blocks:
.
- {{a}}
> {{b}}
1. {{c}}
.
y
| c |
You get 3$ if you solve
If you solve
a
a (a
\not=1) b
. single block equation, greek index (valid=True) . \[e_\\alpha\] .a
so-what is
code
code
code
. display equation in blockquote. (valid=True) . > formula > > \[ a+b=c\] (2) > > in blockquote. .see
a = b + c c^2=a^2+b^2 (2)c^2=a^2+b^2
. mdit-py-plugins-0.3.0/tests/fixtures/texmath_dollar.md 0000664 0000000 0000000 00000012775 14152347745 0023150 0 ustar 00root root 0000000 0000000 single character inline equation. (valid=True) . $a$ .formula
a+b=c in blockquote.
You get 3$ if you solve
If you solve
a
a $a
\not=1$ b
. single block equation, greek index (valid=True) . $$e_\\alpha$$ .a
so-what is
code
code
code
. display equation in blockquote. (valid=True) . > formula > > $$ a+b=c$$ (2) > > in blockquote. .see
a = b + c c^2=a^2+b^2 (2)c^2=a^2+b^2
. mixed syntax: . $$ a=1 \\ b=2 $$ (abc) - ab $c=1$ d .formula
a+b=c in blockquote.
\$1+1=2$ $1+1=2\$
. empty line between text and display formula is required. (valid=False) . some text \$\\$a+b=c\$\$ .some text $\$a+b=c$$
. whitespace character after opening $ or before closing $ is not allowed. (valid=False) . $ $ $ x$ $x $ .$ $ $ x$ $x $
. mdit-py-plugins-0.3.0/tests/fixtures/wordcount.md 0000664 0000000 0000000 00000006562 14152347745 0022162 0 ustar 00root root 0000000 0000000 syntax (text) . one two three four - five six > seven eight [nine ten](link) . { "minutes": 0, "text": [ "one two", "three four", "five six", "seven eight", "nine ten" ], "words": 10 } . non-words . Geeksforgeeks, is best @# Computer Science Portal.!!! . { "minutes": 0, "words": 6 } . lore ipsum . Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent imperdiet hendrerit dictum. Etiam diam turpis, cursus in varius dignissim, imperdiet nec nibh. Nulla nec finibus dui. Phasellus fermentum venenatis placerat. Donec ut dui in sem rhoncus molestie. Sed auctor sem dapibus augue varius facilisis. Maecenas at suscipit dolor. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum ornare dui ac tristique ultricies. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque arcu erat, ultricies ac lorem at, semper ornare nisl. Donec massa magna, commodo et ultrices ac, rutrum non nulla. Nunc fermentum fringilla ultrices. Morbi ante nibh, accumsan ac viverra quis, gravida rutrum mi. Integer lobortis, purus id laoreet ornare, sapien odio placerat massa, vel vestibulum dolor ante id mi. Donec ex leo, ultricies non ante eget, pharetra dictum orci. Interdum et malesuada fames ac ante ipsum primis in faucibus. Maecenas vitae tortor ut nisi cursus egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi et nunc posuere, pharetra est aliquet, iaculis libero. Aliquam leo nibh, posuere eget eros a, convallis bibendum nibh. Phasellus vulputate bibendum lacus sit amet varius. Integer ut rutrum dolor, ac finibus neque. Maecenas ultrices pretium augue vitae mollis. Fusce semper lorem eu mauris iaculis pulvinar. Morbi ac pretium nunc, ac faucibus enim. Duis consequat nibh metus, at sodales sem luctus nec. Donec id finibus ante. Duis tincidunt vulputate efficitur. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean porttitor augue consectetur, feugiat odio in, rutrum velit. Aliquam et mi lacinia, efficitur nisl nec, rutrum mauris. Mauris efficitur eros in maximus tempor. Suspendisse potenti. Quisque cursus non libero in faucibus. Etiam dignissim urna vel nibh feugiat, at vehicula dui vulputate. Praesent malesuada arcu quis neque condimentum vestibulum. Aliquam pretium eleifend neque, eget vulputate erat faucibus at. Quisque egestas nunc ac hendrerit fringilla. Vestibulum at tristique lacus, eget placerat risus. Aenean a metus ullamcorper, eleifend ante ut, feugiat lacus. Proin eget semper purus, ac vehicula nisl. Suspendisse eu mi enim. Nullam aliquam purus eu orci iaculis suscipit. Mauris dapibus non neque eu hendrerit. Sed eros purus, finibus ut ex ac, ultricies luctus enim. Quisque non lacus arcu. Ut dictum mauris ac tristique pulvinar. Aenean ut nisl massa. Donec nec dui scelerisque, egestas arcu sit amet, tempor eros. Donec sit amet faucibus tellus. Cras auctor mi id quam rhoncus, eget porttitor magna ultrices. Sed tristique ut augue in facilisis. Duis in finibus diam. In hac habitasse platea dictumst. Vestibulum in pulvinar orci. Sed a justo cursus enim ultrices egestas sed sit amet leo. Donec sed auctor urna. Praesent vitae dapibus ipsum. Nulla facilisi. Pellentesque non nisi sem. Sed ac mi rutrum, blandit purus ut, facilisis ipsum. . { "minutes": 2, "words": 458 } . mdit-py-plugins-0.3.0/tests/test_amsmath.py 0000664 0000000 0000000 00000001577 14152347745 0021007 0 ustar 00root root 0000000 0000000 from pathlib import Path from textwrap import dedent import pytest from markdown_it import MarkdownIt from markdown_it.utils import read_fixture_file from mdit_py_plugins.amsmath import amsmath_plugin FIXTURE_PATH = Path(__file__).parent def test_plugin_parse(data_regression): md = MarkdownIt().use(amsmath_plugin) tokens = md.parse( dedent( """\ a \\begin{equation} b=1 c=2 \\end{equation} d """ ) ) data_regression.check([t.as_dict() for t in tokens]) @pytest.mark.parametrize( "line,title,input,expected", read_fixture_file(FIXTURE_PATH.joinpath("fixtures", "amsmath.md")), ) def test_fixtures(line, title, input, expected): md = MarkdownIt("commonmark").use(amsmath_plugin) md.options["xhtmlOut"] = False text = md.render(input) print(text) assert text.rstrip() == expected.rstrip() mdit-py-plugins-0.3.0/tests/test_amsmath/ 0000775 0000000 0000000 00000000000 14152347745 0020423 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/tests/test_amsmath/test_plugin_parse.yml 0000664 0000000 0000000 00000003313 14152347745 0024675 0 ustar 00root root 0000000 0000000 - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: - 0 - 1 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: a hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: a hidden: false info: '' level: 1 map: - 0 - 1 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '\begin{equation} b=1 c=2 \end{equation}' hidden: false info: '' level: 0 map: - 1 - 4 markup: '' meta: environment: equation numbered: '' nesting: 0 tag: math type: amsmath - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: - 5 - 6 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: d hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: d hidden: false info: '' level: 1 map: - 5 - 6 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close mdit-py-plugins-0.3.0/tests/test_anchors.py 0000664 0000000 0000000 00000001161 14152347745 0020777 0 ustar 00root root 0000000 0000000 from pathlib import Path import pytest from markdown_it import MarkdownIt from markdown_it.utils import read_fixture_file from mdit_py_plugins.anchors import anchors_plugin FIXTURE_PATH = Path(__file__).parent @pytest.mark.parametrize( "line,title,input,expected", read_fixture_file(FIXTURE_PATH.joinpath("fixtures", "anchors.md")), ) def test_fixtures(line, title, input, expected): md = MarkdownIt("commonmark").use( anchors_plugin, permalink="(permalink" in title, permalinkBefore="before)" in title, ) text = md.render(input) assert text.rstrip() == expected.rstrip() mdit-py-plugins-0.3.0/tests/test_colon_fence.py 0000664 0000000 0000000 00000001637 14152347745 0021624 0 ustar 00root root 0000000 0000000 from pathlib import Path from textwrap import dedent import pytest from markdown_it import MarkdownIt from markdown_it.utils import read_fixture_file from mdit_py_plugins.colon_fence import colon_fence_plugin FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures", "colon_fence.md") @pytest.mark.parametrize("line,title,input,expected", read_fixture_file(FIXTURE_PATH)) def test_fixtures(line, title, input, expected): md = MarkdownIt("commonmark").use(colon_fence_plugin) md.options["xhtmlOut"] = False text = md.render(input) try: assert text.rstrip() == expected.rstrip() except AssertionError: print(text) raise def test_plugin_parse(data_regression): md = MarkdownIt().use(colon_fence_plugin) tokens = md.parse( dedent( """\ ::: name *content* ::: """ ) ) data_regression.check([t.as_dict() for t in tokens]) mdit-py-plugins-0.3.0/tests/test_colon_fence/ 0000775 0000000 0000000 00000000000 14152347745 0021243 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/tests/test_colon_fence/test_plugin_parse.yml 0000664 0000000 0000000 00000000320 14152347745 0025510 0 ustar 00root root 0000000 0000000 - attrs: null block: true children: null content: '*content* ' hidden: false info: ' name' level: 0 map: - 0 - 3 markup: ':::' meta: {} nesting: 0 tag: code type: colon_fence mdit-py-plugins-0.3.0/tests/test_container.py 0000664 0000000 0000000 00000002256 14152347745 0021332 0 ustar 00root root 0000000 0000000 from pathlib import Path from textwrap import dedent import pytest from markdown_it import MarkdownIt from markdown_it.utils import read_fixture_file from mdit_py_plugins.container import container_plugin def test_plugin_parse(data_regression): md = MarkdownIt().use(container_plugin, "name") tokens = md.parse( dedent( """\ ::: name *content* ::: """ ) ) data_regression.check([t.as_dict() for t in tokens]) def test_no_new_line_issue(data_regression): """Fixed an IndexError when no newline on final line.""" md = MarkdownIt().use(container_plugin, "name") tokens = md.parse( dedent( """\ ::: name *content* :::""" ) ) data_regression.check([t.as_dict() for t in tokens]) FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures", "container.md") @pytest.mark.parametrize("line,title,input,expected", read_fixture_file(FIXTURE_PATH)) def test_all(line, title, input, expected): md = MarkdownIt("commonmark").use(container_plugin, "name") md.options["xhtmlOut"] = False text = md.render(input) print(text) assert text.rstrip() == expected.rstrip() mdit-py-plugins-0.3.0/tests/test_container/ 0000775 0000000 0000000 00000000000 14152347745 0020753 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/tests/test_container/test_no_new_line_issue.yml 0000664 0000000 0000000 00000003004 14152347745 0026236 0 ustar 00root root 0000000 0000000 - attrs: null block: true children: null content: '' hidden: false info: ' name' level: 0 map: - 0 - 2 markup: ':::' meta: {} nesting: 1 tag: div type: container_name_open - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 1 - 2 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: '' hidden: false info: '' level: 0 map: null markup: '*' meta: {} nesting: 1 tag: em type: em_open - attrs: null block: false children: null content: content hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: 0 tag: '' type: text - attrs: null block: false children: null content: '' hidden: false info: '' level: 0 map: null markup: '*' meta: {} nesting: -1 tag: em type: em_close content: '*content*' hidden: false info: '' level: 2 map: - 1 - 2 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: null markup: ':::' meta: {} nesting: -1 tag: div type: container_name_close mdit-py-plugins-0.3.0/tests/test_container/test_plugin_parse.yml 0000664 0000000 0000000 00000003004 14152347745 0025222 0 ustar 00root root 0000000 0000000 - attrs: null block: true children: null content: '' hidden: false info: ' name' level: 0 map: - 0 - 2 markup: ':::' meta: {} nesting: 1 tag: div type: container_name_open - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 1 - 2 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: '' hidden: false info: '' level: 0 map: null markup: '*' meta: {} nesting: 1 tag: em type: em_open - attrs: null block: false children: null content: content hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: 0 tag: '' type: text - attrs: null block: false children: null content: '' hidden: false info: '' level: 0 map: null markup: '*' meta: {} nesting: -1 tag: em type: em_close content: '*content*' hidden: false info: '' level: 2 map: - 1 - 2 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: null markup: ':::' meta: {} nesting: -1 tag: div type: container_name_close mdit-py-plugins-0.3.0/tests/test_deflist.py 0000664 0000000 0000000 00000001600 14152347745 0020772 0 ustar 00root root 0000000 0000000 from pathlib import Path from textwrap import dedent import pytest from markdown_it import MarkdownIt from markdown_it.utils import read_fixture_file from mdit_py_plugins.deflist import deflist_plugin FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures", "deflist.md") def test_plugin_parse(data_regression): md = MarkdownIt().use(deflist_plugin) tokens = md.parse( dedent( """\ Term 1 : Definition 1 Term 2 ~ Definition 2a ~ Definition 2b """ ) ) data_regression.check([t.as_dict() for t in tokens]) @pytest.mark.parametrize("line,title,input,expected", read_fixture_file(FIXTURE_PATH)) def test_all(line, title, input, expected): md = MarkdownIt("commonmark").use(deflist_plugin) md.options["xhtmlOut"] = False text = md.render(input) print(text) assert text.rstrip() == expected.rstrip() mdit-py-plugins-0.3.0/tests/test_deflist/ 0000775 0000000 0000000 00000000000 14152347745 0020423 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/tests/test_deflist/test_plugin_parse.yml 0000664 0000000 0000000 00000012014 14152347745 0024673 0 ustar 00root root 0000000 0000000 - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: - 0 - 7 markup: '' meta: {} nesting: 1 tag: dl type: dl_open - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 0 - 0 markup: '' meta: {} nesting: 1 tag: dt type: dt_open - attrs: null block: true children: - attrs: null block: false children: null content: Term 1 hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: Term 1 hidden: false info: '' level: 2 map: - 0 - 0 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dt type: dt_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 2 - 4 markup: '' meta: {} nesting: 1 tag: dd type: dd_open - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: - 2 - 3 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: Definition 1 hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: Definition 1 hidden: false info: '' level: 3 map: - 2 - 3 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dd type: dd_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 4 - 4 markup: '' meta: {} nesting: 1 tag: dt type: dt_open - attrs: null block: true children: - attrs: null block: false children: null content: Term 2 hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: Term 2 hidden: false info: '' level: 2 map: - 4 - 4 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dt type: dt_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 4 - 6 markup: '' meta: {} nesting: 1 tag: dd type: dd_open - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: - 5 - 6 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: Definition 2a hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: Definition 2a hidden: false info: '' level: 3 map: - 5 - 6 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dd type: dd_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 6 - 7 markup: '' meta: {} nesting: 1 tag: dd type: dd_open - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: - 6 - 7 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: Definition 2b hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: Definition 2b hidden: false info: '' level: 3 map: - 6 - 7 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dd type: dd_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: -1 tag: dl type: dl_close mdit-py-plugins-0.3.0/tests/test_dollarmath.py 0000664 0000000 0000000 00000004447 14152347745 0021503 0 ustar 00root root 0000000 0000000 from pathlib import Path from textwrap import dedent import pytest from markdown_it import MarkdownIt from markdown_it.rules_block import StateBlock from markdown_it.rules_inline import StateInline from markdown_it.utils import read_fixture_file from mdit_py_plugins.dollarmath import dollarmath_plugin from mdit_py_plugins.dollarmath import index as main FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") def test_inline_func(): inline_func = main.math_inline_dollar() md = MarkdownIt() src = r"$a=1$ $b=2$" tokens = [] state = StateInline(src, md, {}, tokens) inline_func(state, False) assert tokens[0].as_dict() == { "type": "math_inline", "tag": "math", "nesting": 0, "attrs": None, "map": None, "level": 0, "children": None, "content": "a=1", "markup": "$", "info": "", "meta": {}, "block": False, "hidden": False, } assert state.pos == 5 def test_block_func(): block_func = main.math_block_dollar() md = MarkdownIt() src = r"$$\na=1\n\nc\nb=2$$ (abc)" tokens = [] state = StateBlock(src, md, {}, tokens) block_func(state, 0, 10, False) print(tokens[0].as_dict()) assert tokens[0].as_dict() == { "type": "math_block_label", "tag": "math", "nesting": 0, "attrs": None, "map": [0, 1], "level": 0, "children": None, "content": "\\na=1\\n\\nc\\nb=2", "markup": "$$", "info": "abc", "meta": {}, "block": True, "hidden": False, } def test_plugin_parse(data_regression): md = MarkdownIt().use(dollarmath_plugin) tokens = md.parse( dedent( """\ $$ a=1 b=2 $$ (abc) - ab $c=1$ d """ ) ) data_regression.check([t.as_dict() for t in tokens]) @pytest.mark.parametrize( "line,title,input,expected", read_fixture_file(FIXTURE_PATH.joinpath("dollar_math.md")), ) def test_dollarmath_fixtures(line, title, input, expected): md = MarkdownIt("commonmark").use( dollarmath_plugin, allow_space=False, allow_digits=False, double_inline=True ) md.options.xhtmlOut = False text = md.render(input) print(text) assert text.rstrip() == expected.rstrip() mdit-py-plugins-0.3.0/tests/test_dollarmath/ 0000775 0000000 0000000 00000000000 14152347745 0021120 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/tests/test_dollarmath/test_plugin_parse.yml 0000664 0000000 0000000 00000004067 14152347745 0025401 0 ustar 00root root 0000000 0000000 - attrs: null block: true children: null content: ' a=1 b=2 ' hidden: false info: abc level: 0 map: - 0 - 4 markup: $$ meta: {} nesting: 0 tag: math type: math_block_label - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: - 5 - 6 markup: '-' meta: {} nesting: 1 tag: ul type: bullet_list_open - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 5 - 6 markup: '-' meta: {} nesting: 1 tag: li type: list_item_open - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: - 5 - 6 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: 'ab ' hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text - attrs: null block: false children: null content: c=1 hidden: false info: '' level: 0 map: null markup: $ meta: {} nesting: 0 tag: math type: math_inline - attrs: null block: false children: null content: ' d' hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: ab $c=1$ d hidden: false info: '' level: 3 map: - 5 - 6 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: true info: '' level: 2 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '-' meta: {} nesting: -1 tag: li type: list_item_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: null markup: '-' meta: {} nesting: -1 tag: ul type: bullet_list_close mdit-py-plugins-0.3.0/tests/test_field_list.py 0000664 0000000 0000000 00000001531 14152347745 0021461 0 ustar 00root root 0000000 0000000 from pathlib import Path from textwrap import dedent import pytest from markdown_it import MarkdownIt from markdown_it.utils import read_fixture_file from mdit_py_plugins.field_list import fieldlist_plugin FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures", "field_list.md") def test_plugin_parse(data_regression): md = MarkdownIt().use(fieldlist_plugin) tokens = md.parse( dedent( """\ :abc: Content :def: Content """ ) ) data_regression.check([t.as_dict() for t in tokens]) @pytest.mark.parametrize("line,title,input,expected", read_fixture_file(FIXTURE_PATH)) def test_all(line, title, input, expected): md = MarkdownIt("commonmark").use(fieldlist_plugin) md.options["xhtmlOut"] = False text = md.render(input) print(text) assert text.rstrip() == expected.rstrip() mdit-py-plugins-0.3.0/tests/test_field_list/ 0000775 0000000 0000000 00000000000 14152347745 0021107 5 ustar 00root root 0000000 0000000 mdit-py-plugins-0.3.0/tests/test_field_list/test_plugin_parse.yml 0000664 0000000 0000000 00000010043 14152347745 0025357 0 ustar 00root root 0000000 0000000 - attrs: - - class - field-list block: true children: null content: '' hidden: false info: '' level: 0 map: - 0 - 2 markup: '' meta: {} nesting: 1 tag: dl type: field_list_open - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 0 - 0 markup: '' meta: {} nesting: 1 tag: dt type: fieldlist_name_open - attrs: null block: true children: - attrs: null block: false children: null content: abc hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: abc hidden: false info: '' level: 2 map: - 0 - 0 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dt type: fieldlist_name_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 0 - 1 markup: '' meta: {} nesting: 1 tag: dd type: fieldlist_body_open - attrs: null block: true children: null content: '' hidden: false info: '' level: 2 map: - 0 - 1 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: Content hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: Content hidden: false info: '' level: 3 map: - 0 - 1 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 2 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dd type: fieldlist_body_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 1 - 1 markup: '' meta: {} nesting: 1 tag: dt type: fieldlist_name_open - attrs: null block: true children: - attrs: null block: false children: null content: def hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: def hidden: false info: '' level: 2 map: - 1 - 1 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dt type: fieldlist_name_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: - 1 - 2 markup: '' meta: {} nesting: 1 tag: dd type: fieldlist_body_open - attrs: null block: true children: null content: '' hidden: false info: '' level: 2 map: - 1 - 2 markup: '' meta: {} nesting: 1 tag: p type: paragraph_open - attrs: null block: true children: - attrs: null block: false children: null content: Content hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: 0 tag: '' type: text content: Content hidden: false info: '' level: 3 map: - 1 - 2 markup: '' meta: {} nesting: 0 tag: '' type: inline - attrs: null block: true children: null content: '' hidden: false info: '' level: 2 map: null markup: '' meta: {} nesting: -1 tag: p type: paragraph_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 1 map: null markup: '' meta: {} nesting: -1 tag: dd type: fieldlist_body_close - attrs: null block: true children: null content: '' hidden: false info: '' level: 0 map: null markup: '' meta: {} nesting: -1 tag: dl type: field_list_close mdit-py-plugins-0.3.0/tests/test_footnote.py 0000664 0000000 0000000 00000027662 14152347745 0021215 0 ustar 00root root 0000000 0000000 from pathlib import Path from textwrap import dedent import pytest from markdown_it import MarkdownIt from markdown_it.rules_block import StateBlock from markdown_it.rules_inline import StateInline from markdown_it.token import Token from markdown_it.utils import read_fixture_file from mdit_py_plugins.footnote import footnote_plugin, index FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures", "footnote.md") def test_footnote_def(): md = MarkdownIt() src = r"[^a]: xyz" tokens = [] state = StateBlock(src, md, {}, tokens) index.footnote_def(state, 0, 1, False) assert [t.as_dict() for t in tokens] == [ { "type": "footnote_reference_open", "tag": "", "nesting": 1, "attrs": None, "map": [0, 1], "level": 0, "children": None, "content": "", "markup": "", "info": "", "meta": {"label": "a"}, "block": False, "hidden": False, }, { "type": "paragraph_open", "tag": "p", "nesting": 1, "attrs": None, "map": [0, 1], "level": 1, "children": None, "content": "", "markup": "", "info": "", "meta": {}, "block": True, "hidden": False, }, { "type": "inline", "tag": "", "nesting": 0, "attrs": None, "map": [0, 1], "level": 2, "children": [], "content": "xyz", "markup": "", "info": "", "meta": {}, "block": True, "hidden": False, }, { "type": "paragraph_close", "tag": "p", "nesting": -1, "attrs": None, "map": None, "level": 1, "children": None, "content": "", "markup": "", "info": "", "meta": {}, "block": True, "hidden": False, }, { "type": "footnote_reference_close", "tag": "", "nesting": -1, "attrs": None, "map": None, "level": 0, "children": None, "content": "", "markup": "", "info": "", "meta": {}, "block": False, "hidden": False, }, ] assert state.env == {"footnotes": {"refs": {":a": -1}}} def test_footnote_ref(): md = MarkdownIt() src = r"[^a]" tokens = [] state = StateInline(src, md, {}, tokens) state.env = {"footnotes": {"refs": {":a": -1}}} index.footnote_ref(state, False) # print([t.as_dict() for t in tokens]) assert [t.as_dict() for t in tokens] == [ { "type": "footnote_ref", "tag": "", "nesting": 0, "attrs": None, "map": None, "level": 0, "children": None, "content": "", "markup": "", "info": "", "meta": {"id": 0, "subId": 0, "label": "a"}, "block": False, "hidden": False, } ] assert state.env == { "footnotes": {"refs": {":a": 0}, "list": {0: {"label": "a", "count": 1}}} } def test_footnote_inline(): md = MarkdownIt().use(footnote_plugin) src = r"^[a]" tokens = [] state = StateInline(src, md, {}, tokens) state.env = {"footnotes": {"refs": {":a": -1}}} index.footnote_inline(state, False) # print([t.as_dict() for t in tokens]) assert [t.as_dict() for t in tokens] == [ { "type": "footnote_ref", "tag": "", "nesting": 0, "attrs": None, "map": None, "level": 0, "children": None, "content": "", "markup": "", "info": "", "meta": {"id": 0}, "block": False, "hidden": False, } ] assert state.env == { "footnotes": { "refs": {":a": -1}, "list": { 0: { "content": "a", "tokens": [ Token( type="text", tag="", nesting=0, attrs=None, map=None, level=0, children=None, content="a", markup="", info="", meta={}, block=False, hidden=False, ) ], } }, } } def test_footnote_tail(): md = MarkdownIt() tokens = [ Token( **{ "type": "footnote_reference_open", "tag": "", "nesting": 1, "attrs": None, "map": None, "level": 0, "children": None, "content": "", "markup": "", "info": "", "meta": {"label": "a"}, "block": False, "hidden": False, } ), Token( **{ "type": "paragraph_open", "tag": "p", "nesting": 1, "attrs": None, "map": [0, 1], "level": 1, "children": None, "content": "", "markup": "", "info": "", "meta": {}, "block": True, "hidden": False, } ), Token( **{ "type": "inline", "tag": "", "nesting": 0, "attrs": None, "map": [0, 1], "level": 2, "children": [], "content": "xyz", "markup": "", "info": "", "meta": {}, "block": True, "hidden": False, } ), Token( **{ "type": "paragraph_close", "tag": "p", "nesting": -1, "attrs": None, "map": None, "level": 1, "children": None, "content": "", "markup": "", "info": "", "meta": {}, "block": True, "hidden": False, } ), Token( **{ "type": "footnote_reference_close", "tag": "", "nesting": -1, "attrs": None, "map": None, "level": 0, "children": None, "content": "", "markup": "", "info": "", "meta": {}, "block": False, "hidden": False, } ), Token("other", "", 0), ] env = {"footnotes": {"refs": {":a": 0}, "list": {0: {"label": "a", "count": 1}}}} state = StateBlock("", md, env, tokens) index.footnote_tail(state) assert state.tokens == [ Token( type="other", tag="", nesting=0, attrs=None, map=None, level=0, children=None, content="", markup="", info="", meta={}, block=False, hidden=False, ), Token( type="footnote_block_open", tag="", nesting=1, attrs=None, map=None, level=0, children=None, content="", markup="", info="", meta={}, block=False, hidden=False, ), Token( type="footnote_open", tag="", nesting=1, attrs=None, map=None, level=0, children=None, content="", markup="", info="", meta={"id": 0, "label": "a"}, block=False, hidden=False, ), Token( type="paragraph_open", tag="p", nesting=1, attrs=None, map=[0, 1], level=1, children=None, content="", markup="", info="", meta={}, block=True, hidden=False, ), Token( type="inline", tag="", nesting=0, attrs=None, map=[0, 1], level=2, children=[], content="xyz", markup="", info="", meta={}, block=True, hidden=False, ), Token( type="footnote_anchor", tag="", nesting=0, attrs=None, map=None, level=0, children=None, content="", markup="", info="", meta={"id": 0, "subId": 0, "label": "a"}, block=False, hidden=False, ), Token( type="paragraph_close", tag="p", nesting=-1, attrs=None, map=None, level=1, children=None, content="", markup="", info="", meta={}, block=True, hidden=False, ), Token( type="footnote_close", tag="", nesting=-1, attrs=None, map=None, level=0, children=None, content="", markup="", info="", meta={}, block=False, hidden=False, ), Token( type="footnote_block_close", tag="", nesting=-1, attrs=None, map=None, level=0, children=None, content="", markup="", info="", meta={}, block=False, hidden=False, ), ] def test_plugin_render(): md = MarkdownIt().use(footnote_plugin) text = md.render( dedent( """\ [^1] ^[a] [^a] [^a] [^1]: abc [^a]: xyz """ ) ) assert text == ( dedent( """\