Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Mar 6, 2023
2 parents 65d763a + be14587 commit 5412706
Show file tree
Hide file tree
Showing 54 changed files with 1,696 additions and 230 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ jobs:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [pypy3, 3.6, 3.7, 3.8, 3.9]
python-version: ['pypy-3.7', '3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -64,13 +65,13 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Build package
python-version: "3.8"
- name: install flit
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 }}
pip install flit~=3.4
- name: Build and publish
run: |
flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}
31 changes: 8 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,30 @@ exclude: >
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.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.48"
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.10.1
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.6.0
rev: 23.1.0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.247
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==21.3.1]
- id: ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
rev: v1.0.0
hooks:
- id: mypy
additional_dependencies: [markdown-it-py~=1.0]
additional_dependencies: [markdown-it-py~=2.0]
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# Change Log

## 0.3.5 - 2023-03-02

- 🐛 FIX: Regression in dollarmath by @chrisjsewell in [#69](https://github.com/executablebooks/mdit-py-plugins/pull/69)
- 🐛 Fix regression in amsmath by @chrisjsewell in [#70](https://github.com/executablebooks/mdit-py-plugins/pull/70)
- 🔧 Correct project documentation link by @andersk in [#73](https://github.com/executablebooks/mdit-py-plugins/pull/73)

## 0.3.4 - 2023-02-18

- ✨ NEW: Add attrs_block_plugin by @chrisjsewell in [#66](https://github.com/executablebooks/mdit-py-plugins/pull/66)
- 👌 Improve field lists by @chrisjsewell in [#65](https://github.com/executablebooks/mdit-py-plugins/pull/65)
- 🔧 Update pre-commit by @chrisjsewell in [#64](https://github.com/executablebooks/mdit-py-plugins/pull/64) (moving from flake8 to ruff)

**Full Changelog**: [v0.3.3...v0.3.](https://github.com/executablebooks/mdit-py-plugins/compare/v0.3.3...v0.3.4)

## 0.3.3 - 2022-12-06

🐛 FIX: span with end of inline before attrs

## 0.3.2 - 2022-12-05

- ✨ NEW: Port `admon` plugin by @KyleKing ([#53](https://github.com/executablebooks/mdit-py-plugins/pull/53))
- ✨ NEW: Add span parsing to inline attributes plugin by @chrisjsewell ([#55](https://github.com/executablebooks/mdit-py-plugins/pull/55))
- 🐛 FIX: Task list item marker can be followed by any GFM whitespace by @hukkin in ([#42](https://github.com/executablebooks/mdit-py-plugins/pull/42))

**Full Changelog**: [v0.3.1...v0.4.0](https://github.com/executablebooks/mdit-py-plugins/compare/v0.3.1...v0.4.0)

## 0.3.1 - 2022-09-27

- ⬆️ UPGRADE: Drop Python 3.6, support Python 3.10
- 🐛 FIX: Parsing when newline is between footnote ID and first paragraph
- 🐛 FIX: Anchor ids in separate renders no longer affect each other.
- ✨ NEW: Add `attrs_plugin`
- 🔧 MAINTAIN: Use flit PEP 621 package build

## 0.3.0 - 2021-12-03

- ⬆️ UPGRADE: Compatible with markdown-it-py `v2`.
Expand Down
17 changes: 0 additions & 17 deletions MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ coverage:
status:
project:
default:
target: 93%
target: 92%
threshold: 0.2%
patch:
default:
Expand Down
14 changes: 14 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ html_string = md.render("some *Markdown*")
.. autofunction:: mdit_py_plugins.container.container_plugin
```

```{eval-rst}
.. autofunction:: mdit_py_plugins.admon.admon_plugin
```

## Attributes

```{eval-rst}
.. autofunction:: mdit_py_plugins.attrs.attrs_plugin
```

```{eval-rst}
.. autofunction:: mdit_py_plugins.attrs.attrs_block_plugin
```

## Math

```{eval-rst}
Expand Down
2 changes: 1 addition & 1 deletion mdit_py_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.0"
__version__ = "0.3.5"
24 changes: 24 additions & 0 deletions mdit_py_plugins/admon/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2015 Vitaly Puzrin, Alex Kocharin.
Copyright (c) 2018 jebbs
Copyright (c) 2021- commenthol

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.
1 change: 1 addition & 0 deletions mdit_py_plugins/admon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .index import admon_plugin # noqa: F401
172 changes: 172 additions & 0 deletions mdit_py_plugins/admon/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Process admonitions and pass to cb.

import math
from typing import Callable, Optional, Tuple

from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock


def get_tag(params: str) -> Tuple[str, str]:
if not params.strip():
return "", ""

tag, *_title = params.strip().split(" ")
joined = " ".join(_title)

title = ""
if not joined:
title = tag.title()
elif joined != '""':
title = joined
return tag.lower(), title


def validate(params: str) -> bool:
tag = params.strip().split(" ", 1)[-1] or ""
return bool(tag)


MIN_MARKERS = 3
MARKER_STR = "!"
MARKER_CHAR = ord(MARKER_STR)
MARKER_LEN = len(MARKER_STR)


def admonition(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bool:
start = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]

# Check out the first character quickly, which should filter out most of non-containers
if ord(state.src[start]) != MARKER_CHAR:
return False

# Check out the rest of the marker string
pos = start + 1
while pos <= maximum and MARKER_STR[(pos - start) % MARKER_LEN] == state.src[pos]:
pos += 1

marker_count = math.floor((pos - start) / MARKER_LEN)
if marker_count < MIN_MARKERS:
return False
marker_pos = pos - ((pos - start) % MARKER_LEN)
params = state.src[marker_pos:maximum]
markup = state.src[start:marker_pos]

if not validate(params):
return False

# Since start is found, we can report success here in validation mode
if silent:
return True

old_parent = state.parentType
old_line_max = state.lineMax
old_indent = state.blkIndent

blk_start = pos
while blk_start < maximum and state.src[blk_start] == " ":
blk_start += 1

state.parentType = "admonition"
state.blkIndent += blk_start - start

was_empty = False

# Search for the end of the block
next_line = startLine
while True:
next_line += 1
if next_line >= endLine:
# unclosed block should be autoclosed by end of document.
# also block seems to be autoclosed by end of parent
break
pos = state.bMarks[next_line] + state.tShift[next_line]
maximum = state.eMarks[next_line]
is_empty = state.sCount[next_line] < state.blkIndent

# two consecutive empty lines autoclose the block
if is_empty and was_empty:
break
was_empty = is_empty

if pos < maximum and state.sCount[next_line] < state.blkIndent:
# non-empty line with negative indent should stop the block:
# - !!!
# test
break

# this will prevent lazy continuations from ever going past our end marker
state.lineMax = next_line

tag, title = get_tag(params)

token = state.push("admonition_open", "div", 1)
token.markup = markup
token.block = True
token.attrs = {"class": f"admonition {tag}"}
token.meta = {"tag": tag}
token.content = title
token.info = params
token.map = [startLine, next_line]

if title:
title_markup = f"{markup} {tag}"
token = state.push("admonition_title_open", "p", 1)
token.markup = title_markup
token.attrs = {"class": "admonition-title"}
token.map = [startLine, startLine + 1]

token = state.push("inline", "", 0)
token.content = title
token.map = [startLine, startLine + 1]
token.children = []

token = state.push("admonition_title_close", "p", -1)
token.markup = title_markup

state.md.block.tokenize(state, startLine + 1, next_line)

token = state.push("admonition_close", "div", -1)
token.markup = state.src[start:pos]
token.block = True

state.parentType = old_parent
state.lineMax = old_line_max
state.blkIndent = old_indent
state.line = next_line

return True


def admon_plugin(md: MarkdownIt, render: Optional[Callable] = None) -> None:
"""Plugin to use
`python-markdown style admonitions
<https://python-markdown.github.io/extensions/admonition>`_.
.. code-block:: md
!!! note
*content*
Note, this is ported from
`markdown-it-admon
<https://github.com/commenthol/markdown-it-admon>`_.
"""

def renderDefault(self, tokens, idx, _options, env):
return self.renderToken(tokens, idx, _options, env)

render = render or renderDefault

md.add_render_rule("admonition_open", render)
md.add_render_rule("admonition_close", render)
md.add_render_rule("admonition_title_open", render)
md.add_render_rule("admonition_title_close", render)

md.block.ruler.before(
"fence",
"admonition",
admonition,
{"alt": ["paragraph", "reference", "blockquote", "list"]},
)
4 changes: 4 additions & 0 deletions mdit_py_plugins/admon/port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- package: markdown-it-admon
commit: 9820ba89415c464a3cc18a780f222a0ceb3e18bd
date: Jul 3, 2021
version: 1.0.0
Loading

0 comments on commit 5412706

Please sign in to comment.