forked from bids-standard/bids-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bids-standard:master' into master
- Loading branch information
Showing
25 changed files
with
292 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Script to remove all mkdocs admonition from the markdown files in a directory. | ||
See the pdf_build_src/tests/data/input directory to see what admonitions look like. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import shutil | ||
from pathlib import Path | ||
|
||
INDENT = " " | ||
|
||
ADMONITION_DELIMITERS = ["!!!", "???", "???+"] | ||
|
||
|
||
def remove_admonitions( | ||
input_folder: str | Path, output_folder: str | Path, indent: str = None | ||
): | ||
|
||
if indent is None: | ||
indent = INDENT | ||
|
||
md_files = Path(input_folder).glob("**/*.md") | ||
|
||
for file in md_files: | ||
|
||
with open(file, "r", encoding="utf8") as f: | ||
content = f.readlines() | ||
|
||
output_file = Path(output_folder) / file.relative_to(input_folder) | ||
output_file.parent.mkdir(parents=True, exist_ok=True) | ||
print(f"processing: {file}\n to: {output_file}") | ||
|
||
with open(output_file, "w", encoding="utf8") as f: | ||
|
||
is_admonition = False | ||
counter = 0 | ||
for line in content: | ||
|
||
if any(line.startswith(x) for x in ADMONITION_DELIMITERS): | ||
is_admonition = True | ||
counter = 0 | ||
continue | ||
|
||
# skip first line after admonition | ||
if is_admonition and counter == 0: | ||
counter += 1 | ||
continue | ||
|
||
if not line.startswith(indent): | ||
is_admonition = False | ||
|
||
if is_admonition: | ||
line = line.lstrip(indent) | ||
|
||
f.write(line) | ||
|
||
|
||
if __name__ == "__main__": | ||
"""If run as a script this will just run the main function on test data.""" | ||
input_folder = Path(__file__).parent / "tests" / "data" / "input" | ||
output_folder = Path(__file__).parent / "tests" / "data" / "output" | ||
shutil.rmtree(output_folder) | ||
remove_admonitions(input_folder, output_folder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pathlib import Path | ||
|
||
from remove_admonitions import remove_admonitions | ||
|
||
|
||
def test_remove_admonitions(tmp_path): | ||
input_folder = Path(__file__).parent / "tests" / "data" / "input" | ||
expected_folder = Path(__file__).parent / "tests" / "data" / "expected" | ||
|
||
remove_admonitions(input_folder, tmp_path) | ||
|
||
generated_files = list(tmp_path.glob("**/*.md")) | ||
|
||
for file in generated_files: | ||
|
||
expected = expected_folder / file.relative_to(tmp_path) | ||
|
||
with open(expected, "r", encoding="utf8") as f: | ||
expected_content = f.readlines() | ||
|
||
with open(file, "r", encoding="utf8") as f: | ||
generated_content = f.readlines() | ||
|
||
for expected_line, generated_line in zip(expected_content, generated_content): | ||
assert generated_line == expected_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Test inputs | ||
|
||
This input directory contains data to use for testing the pdf build code of the BIDS specification. | ||
|
||
For example the following admonition should be removed by `pdf_build_src/remove_admonitions.py`. | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
Nulla et euismod nulla. | ||
Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, | ||
nec semper lorem quam in massa. | ||
|
||
The `expected` directory should contain the documents | ||
as they should look like after processing. | ||
|
||
[Mkdocs admonitions](https://squidfunk.github.io/mkdocs-material/reference/admonitions/#inline-blocks-inline-end) | ||
come in different type. In aaddtion of the classical admonitions show above you have also: | ||
|
||
Collapsible admonitions start with 3 questions marks (`???`). | ||
|
||
Collapsible admonitions that will be shown as expanded | ||
start with 3 questions marks and a plus sign (`???+`). |
8 changes: 8 additions & 0 deletions
8
.../tests/data/expected/modality-specific-files/magnetic-resonance-imaging-data.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Magnetic Resonance Imaging | ||
|
||
## Common metadata fields | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
Nulla et euismod nulla. | ||
Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, | ||
nec semper lorem quam in massa. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Test inputs | ||
|
||
This input directory contains data to use for testing the pdf build code of the BIDS specification. | ||
|
||
For example the following admonition should be removed by `pdf_build_src/remove_admonitions.py`. | ||
|
||
!!! note | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
Nulla et euismod nulla. | ||
Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, | ||
nec semper lorem quam in massa. | ||
|
||
The `expected` directory should contain the documents | ||
as they should look like after processing. | ||
|
||
[Mkdocs admonitions](https://squidfunk.github.io/mkdocs-material/reference/admonitions/#inline-blocks-inline-end) | ||
come in different type. In aaddtion of the classical admonitions show above you have also: | ||
|
||
??? note "Collapsible admonitions" | ||
|
||
Collapsible admonitions start with 3 questions marks (`???`). | ||
|
||
???+ note "Expanded collapsible admonitions" | ||
|
||
Collapsible admonitions that will be shown as expanded | ||
start with 3 questions marks and a plus sign (`???+`). |
10 changes: 10 additions & 0 deletions
10
...src/tests/data/input/modality-specific-files/magnetic-resonance-imaging-data.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Magnetic Resonance Imaging | ||
|
||
## Common metadata fields | ||
|
||
!!! warning "foo bar" | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
Nulla et euismod nulla. | ||
Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, | ||
nec semper lorem quam in massa. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.