Skip to content

Commit

Permalink
Allow to keep heading of admonition in PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Apr 11, 2024
1 parent 83b12e9 commit e7eed96
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
25 changes: 18 additions & 7 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,18 +34,29 @@ def remove_admonitions(
with open(output_file, "w", encoding="utf8") as f:

is_admonition = False
counter = 0
# counter = 0
for line in content:

if any(line.startswith(x) for x in ADMONITION_DELIMITERS):
is_admonition = True
counter = 0
# counter = 0
line = line.replace("\n", "")
line = line.replace('"', "")
for x in ADMONITION_DELIMITERS:
line = line.replace(x, "", 1)
line = line.lstrip()
words = line.split(" ")
print(words)
words[0] = f"{words[0].capitalize()}:"
line = "**" + " ".join(words) + "**\n"
f.write(line)
print(line)
continue

# skip first line after admonition
if is_admonition and counter == 0:
counter += 1
continue
# # skip first line after admonition
# if is_admonition and counter == 0:
# counter += 1
# continue

if line != "\n" and not line.startswith(indent):
is_admonition = False
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

0 comments on commit e7eed96

Please sign in to comment.