Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unreleased mdformat 0.7.19 that escapes square brackets less #45

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
hooks:
- id: docformatter
- repo: https://github.com/executablebooks/mdformat
rev: 08fba30538869a440b5059de90af03e3502e35fb # frozen: 0.7.17
rev: 86542e37a3a40974eb812b16b076220fe9bb4278 # frozen: 0.7.18
hooks:
- id: mdformat
files: 'README.md'
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ making the tool able to format the following syntax extensions:
## Install

```sh
pip install mdformat-gfm
pipx install mdformat
pipx inject mdformat mdformat-gfm
```

## Usage
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ description = "Run tests under {base_python}"
deps = ["-r tests/requirements.txt"]
commands = [["pytest", { replace = "posargs", extend = true }]]

[tool.tox.env."git-mdformat"]
description = "Run tests against unreleased mdformat from git"
deps = [
"-r tests/requirements.txt",
"git+https://github.com/executablebooks/mdformat.git@master",
"git+https://github.com/executablebooks/mdformat-tables.git@master",
]

[tool.tox.env."mypy"]
base_python = ["python3.11"]
description = "Run mypy under {base_python}"
Expand Down
16 changes: 15 additions & 1 deletion src/mdformat_gfm/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,23 @@ def _escape_text(text: str, node: RenderTreeNode, context: RenderContext) -> str
return text


_RE_GFM_TICK_BOX = re.compile(r"^\[([ xX])]", flags=re.MULTILINE)


def _escape_paragraph(text: str, node: RenderTreeNode, context: RenderContext) -> str:
# Escape tasklists
text = _RE_GFM_TICK_BOX.sub(r"\[" + r"\g<1>" + r"\]", text)

return text


RENDERERS = {
"s": _strikethrough_renderer,
"list_item": _list_item_renderer,
"link": _link_renderer,
}
POSTPROCESSORS = {"text": _escape_text, "inline": _postprocess_inline}
POSTPROCESSORS = {
"text": _escape_text,
"inline": _postprocess_inline,
"paragraph": _escape_paragraph,
}
9 changes: 9 additions & 0 deletions tests/data/default_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@ test.com:443
.
test.com:443
.

Tasklist escape
.
- [x] foo
- \[ ] bim
.
- [x] foo
- \[ \] bim
.