Skip to content
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 .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10
python-version: "3.10"

- name: install pandoc
uses: r-lib/actions/setup-pandoc@v2
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e .[testing,linkify]
- name: Check spec file is up to date
run: |
python tests/test_cmark_spec/get_cmark_spec.py
- name: Run pytest
run: |
pytest tests/ --cov=markdown_it --cov-report=xml --cov-report=term-missing
Expand Down
16 changes: 16 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ For documentation build tests:
>> make html-strict
```

### Updating the commonmark specification

If you need to update the commonmark specification, you can do so by running:

```shell
>> cd markdown-it-py
>> python tests/test_cmark_spec/get_cmark_spec.py
```

or

```shell
>> cd markdown-it-py
>> uv run tests/test_cmark_spec/get_cmark_spec.py
```

## Contributing a plugin

1. Does it already exist as JavaScript implementation ([see npm](https://www.npmjs.com/search?q=keywords:markdown-it-plugin))?
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ testing = [
"pytest",
"pytest-cov",
"pytest-regressions",
"requests",
]
benchmarking = [
"psutil",
Expand Down
77 changes: 77 additions & 0 deletions tests/test_cmark_spec/get_cmark_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# /// script
# dependencies = [
# "requests",
# ]
# ///
from pathlib import Path

default_version = "0.30"
default_output_path = Path(__file__).parent / "commonmark.json"
default_fixture_test_path = (
Path(__file__).parent.parent / "test_port" / "fixtures" / "commonmark_spec.md"
)


def create_argparser():
import argparse

parser = argparse.ArgumentParser(description="Download CommonMark spec JSON")
parser.add_argument(
"version",
nargs="?",
default=default_version,
help=f"CommonMark spec version to download (default: {default_version})",
)
parser.add_argument(
"--output",
"-o",
type=Path,
default=default_output_path,
help=f"Output file path (default: {default_output_path})",
)
parser.add_argument(
"--test-fixture",
type=Path,
default=default_fixture_test_path,
help=f"Write to test fixture (default: {default_fixture_test_path})",
)
return parser


if __name__ == "__main__":
import requests # type: ignore[import-untyped]

args = create_argparser().parse_args()
version: str = args.version
output_path: Path = args.output
write_to_test_fixture = True
test_fixture: Path = args.test_fixture
changed = False
url = f"https://spec.commonmark.org/{version}/spec.json"
print(f"Downloading CommonMark spec from {url}")
response = requests.get(url)
response.raise_for_status()
if not output_path.exists() or output_path.read_text() != response.text:
changed = True
with output_path.open("w") as f:
f.write(response.text)
print(f"Updated to {output_path}")
else:
print(f"Spec file {output_path} is up to date, not overwriting")

if write_to_test_fixture:
data = response.json()
text = ""
for item in data:
text += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
text += f"src line: {item['start_line'] - 1}\n\n"
text += f".\n{item['markdown']}.\n{item['html']}.\n\n"
if not test_fixture.exists() or test_fixture.read_text() != text:
changed = True
with test_fixture.open("w") as f:
f.write(text)
print(f"Also updated to {test_fixture}")
else:
print(f"Fixture file {test_fixture} is up to date, not overwriting")

raise SystemExit(0 if not changed else 1)
26 changes: 0 additions & 26 deletions tests/test_cmark_spec/spec.sh

This file was deleted.