Skip to content

Commit b10896f

Browse files
authored
Encourage R users to check out animovement (#335)
* added tip for R users * added script for converting admonitions to myst * refactored conversion script
1 parent 7813e7c commit b10896f

File tree

8 files changed

+119
-11
lines changed

8 files changed

+119
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ docs/build/
6161
docs/source/examples/
6262
docs/source/api/
6363
docs/source/api_index.rst
64+
docs/source/snippets/admonitions.md
6465
sg_execution_times.rst
6566

6667
# MkDocs documentation

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,13 @@ make html
296296
```
297297
The local build can be viewed by opening `docs/build/html/index.html` in a browser.
298298

299-
To re-build the documentation after making changes, we recommend removing existing build files first.
299+
To re-build the documentation after making changes,
300+
we recommend removing existing build files first.
300301
The following command will remove all generated files in `docs/`,
301-
including the auto-generated API index `source/api_index.rst`, and those in `build/`, `source/api/`, and `source/examples/`. It will then re-build the documentation:
302+
including the auto-generated files `source/api_index.rst` and
303+
`source/snippets/admonitions.md`, as well as all files in
304+
`build/`, `source/api/`, and `source/examples/`.
305+
It will then re-build the documentation:
302306

303307
```sh
304308
make clean html

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,19 @@ We aim to support a range of pose estimation packages, along with 2D or 3D track
3434

3535
Find out more on our [mission and scope](https://movement.neuroinformatics.dev/community/mission-scope.html) statement and our [roadmap](https://movement.neuroinformatics.dev/community/roadmaps.html).
3636

37-
## Status
37+
<!-- Start Admonitions -->
38+
3839
> [!Warning]
3940
> 🏗️ The package is currently in early development and the interface is subject to change. Feel free to play around and provide feedback.
4041
42+
> [!Tip]
43+
> If you prefer analysing your data in R, we recommend checking out the
44+
> [animovement](https://www.roald-arboel.com/animovement/) toolbox, which is similar in scope.
45+
> We are working together with its developer
46+
> to gradually converge on common data standards and workflows.
47+
48+
<!-- End Admonitions -->
49+
4150
## Join the movement
4251

4352
Contributions to movement are absolutely encouraged, whether to fix a bug, develop a new feature, or improve the documentation.

docs/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ help:
1919
api_index.rst:
2020
python make_api_index.py
2121

22+
# Generate the snippets/admonitions.md file
23+
# by converting the admonitions in the repo's README.md to MyST format
24+
admonitions.md:
25+
python convert_admonitions.py
26+
2227
# Remove all generated files
2328
clean:
2429
rm -rf ./build
2530
rm -f ./source/api_index.rst
2631
rm -rf ./source/api
2732
rm -rf ./source/examples
33+
rm -rf ./source/snippets/admonitions.md
2834

2935
# Catch-all target: route all unknown targets to Sphinx using the new
3036
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
31-
%: Makefile api_index.rst
37+
%: Makefile api_index.rst admonitions.md
3238
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/convert_admonitions.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Convert admonitions GitHub Flavored Markdown (GFM) to MyST Markdown."""
2+
3+
import re
4+
from pathlib import Path
5+
6+
# Valid admonition types supported by both GFM and MyST (case-insensitive)
7+
VALID_TYPES = {"note", "tip", "important", "warning", "caution"}
8+
9+
10+
def convert_gfm_admonitions_to_myst_md(
11+
input_path: Path, output_path: Path, exclude: set[str] | None = None
12+
):
13+
"""Convert admonitions from GitHub Flavored Markdown to MyST.
14+
15+
Extracts GitHub Flavored Markdown admonitions from the input file and
16+
writes them to the output file as MyST Markdown admonitions.
17+
The original admonition type and order are preserved.
18+
19+
Parameters
20+
----------
21+
input_path : Path
22+
Path to the input file containing GitHub Flavored Markdown.
23+
output_path : Path
24+
Path to the output file to write the MyST Markdown admonitions.
25+
exclude : set[str], optional
26+
Set of admonition types to exclude from conversion (case-insensitive).
27+
Default is None.
28+
29+
"""
30+
excluded_types = {s.lower() for s in (exclude or set())}
31+
32+
# Read the input file
33+
gfm_text = input_path.read_text(encoding="utf-8")
34+
35+
# Regex pattern to match GFM admonitions
36+
pattern = r"(^> \[!(\w+)\]\n(?:^> .*\n?)*)"
37+
matches = re.finditer(pattern, gfm_text, re.MULTILINE)
38+
39+
# Process matches and collect converted admonitions
40+
admonitions = []
41+
for match in matches:
42+
adm_myst = _process_match(match, excluded_types)
43+
if adm_myst:
44+
admonitions.append(adm_myst)
45+
46+
if admonitions:
47+
# Write all admonitions to a single file
48+
output_path.write_text("\n".join(admonitions) + "\n", encoding="utf-8")
49+
print(f"Admonitions written to {output_path}")
50+
else:
51+
print("No GitHub Markdown admonitions found.")
52+
53+
54+
def _process_match(match: re.Match, excluded_types: set[str]) -> str | None:
55+
"""Process a regex match and return the converted admonition if valid."""
56+
# Extract the admonition type
57+
adm_type = match.group(2).lower()
58+
if adm_type not in VALID_TYPES or adm_type in excluded_types:
59+
return None
60+
61+
# Extract the content lines
62+
full_block = match.group(0)
63+
content = "\n".join(
64+
line[2:].strip()
65+
for line in full_block.split("\n")
66+
if line.startswith("> ") and not line.startswith("> [!")
67+
).strip()
68+
69+
# Return the converted admonition
70+
return ":::{" + adm_type + "}\n" + content + "\n" + ":::\n"
71+
72+
73+
if __name__ == "__main__":
74+
# Path to the README.md file
75+
# (1 level above the current script)
76+
docs_dir = Path(__file__).resolve().parent
77+
readme_path = docs_dir.parent / "README.md"
78+
79+
# Path to the output file
80+
# (inside the docs/source/snippets directory)
81+
snippets_dir = docs_dir / "source" / "snippets"
82+
target_path = snippets_dir / "admonitions.md"
83+
84+
# Call the function
85+
convert_gfm_admonitions_to_myst_md(
86+
readme_path, target_path, exclude={"note"}
87+
)

docs/make.bat

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ if "%1" == "" goto help
2828

2929
:process_targets
3030
if "%1" == "clean" (
31-
@echo Removing auto-generated files under 'docs' and 'src'...
31+
echo Removing auto-generated files...
3232
rmdir /S /Q %BUILDDIR%
3333
del /Q %SOURCEDIR%\api_index.rst
3434
rmdir /S /Q %SOURCEDIR%\api\
3535
rmdir /S /Q %SOURCEDIR%\examples\
36+
del /Q %SOURCEDIR%\snippets\admonitions.md
3637
) else (
37-
@echo Generating API index...
38+
echo Generating API index...
3839
python make_api_index.py
40+
41+
echo Converting admonitions...
42+
python convert_admonitions.py
43+
3944
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
4045
)
4146

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ We aim to support a range of pose estimation packages, along with 2D or 3D track
3939

4040
Find out more on our [mission and scope](target-mission) statement and our [roadmap](target-roadmaps).
4141

42-
```{include} /snippets/status-warning.md
42+
```{include} /snippets/admonitions.md
4343
```
4444

4545
## Citation

docs/source/snippets/status-warning.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)