-
Notifications
You must be signed in to change notification settings - Fork 171
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
[ENH] allow using of mkdoc admonitions #1711
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
224ad94
add script to remove admonitions and run it during pdf build
Remi-Gau b18e0e5
drop rich
Remi-Gau 9183304
turn off code block style check
Remi-Gau 908e654
update test data
Remi-Gau f1b5d76
example admonition
Remi-Gau 15b4d6c
support more admonitions
Remi-Gau dbcb962
update style guide
Remi-Gau f9e699b
Merge branch 'master' into admonition
sappelhoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""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 = " " | ||
|
||
|
||
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__": | ||
"""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) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this is not run automatically in CI. |
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 = [x for x in 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 |
Remi-Gau marked this conversation as resolved.
Show resolved
Hide resolved
|
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. |
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,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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the step ordering... Because we will have to change it everytime steps are added.