-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to remove admonitions and run it during pdf build
- Loading branch information
Showing
8 changed files
with
114 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Script to remove all mkdocs admonition from the markdown files in a directory.""" | ||
from __future__ import annotations | ||
from pathlib import Path | ||
from rich import print | ||
import shutil | ||
|
||
INDENT = " " | ||
|
||
|
||
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 line.startswith("!!!"): | ||
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__": | ||
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,13 @@ | ||
# 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. |
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,15 @@ | ||
# 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. |
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