Skip to content

[ENH] Allow to keep heading of admonition in PDF #1768

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 15 additions & 8 deletions pdf_build_src/remove_admonitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

INDENT = " "

ADMONITION_DELIMITERS = ["!!!", "???", "???+"]
ADMONITION_DELIMITERS = ["???+", "!!!", "???"]


def remove_admonitions(
Expand All @@ -34,17 +34,12 @@ def remove_admonitions(
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
line = process_admonition_heading(line)
f.write(line)
continue

if line != "\n" and not line.startswith(indent):
Expand All @@ -56,6 +51,18 @@ def remove_admonitions(
f.write(line)


def process_admonition_heading(line: str) -> str:
line = line.replace("\n", "")
line = line.replace('"', "")
for x in ADMONITION_DELIMITERS:
line = line.replace(x, "", 1)
line = line.lstrip()
words = line.split(" ")
words[0] = f"{words[0].capitalize()}:"
line = "**" + " ".join(words) + "**\n"
return 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"
Expand Down
8 changes: 8 additions & 0 deletions pdf_build_src/tests/data/expected/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This input directory contains data to use for testing the pdf build code of the

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,
Expand All @@ -15,13 +17,19 @@ 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 (`???+`).



**Example: non ordered list should be handle properly**

Let's see

- [`UK biobank`](https://github.com/bids-standard/bids-examples/tree/master/genetics_ukbb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 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,
Expand Down
2 changes: 1 addition & 1 deletion pdf_build_src/tests/data/input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ come in different type. In aaddtion of the classical admonitions show above you



!!! example "non ordered list should be handle propeler"
!!! example "non ordered list should be handle properly"

Let's see

Expand Down
8 changes: 8 additions & 0 deletions src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ Alternatively, to get started please read [the introduction to the specification

For an overview of the BIDS ecosystem, visit the [BIDS homepage](https://bids.neuroimaging.io).
The entire specification can also be [downloaded as PDF](https://doi.org/10.5281/zenodo.3686061).

::: note
FOO barr
:::

::: warning
FOO barr
:::