Skip to content
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] Add filename template legend #1259

Merged
merged 5 commits into from
Aug 30, 2022
Merged
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
33 changes: 33 additions & 0 deletions tools/schemacode/bidsschematools/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pandas as pd
import yaml
from markdown_it import MarkdownIt
from tabulate import tabulate

from . import utils
Expand Down Expand Up @@ -469,11 +470,43 @@ def make_filename_template(
)

codeblock = codeblock.expandtabs(4)
codeblock = append_filename_template_legend(codeblock, pdf_format)
codeblock = codeblock.replace("SPEC_ROOT", get_relpath(src_path))

return codeblock


def append_filename_template_legend(text, pdf_format=False):
legend = """
- Filename entities or folders between square brackets
(for example, `[_ses-<label>]`) are OPTIONAL.
- Some entities may only allow specific values,
in which case those values are listed in `<>`, separated by `|`.
- `_<suffix>` means that there are several (>6) valid suffixes for this filename pattern.
- `.<extension>` means that there are several (>6) valid extensions for this file type.
- `[.gz]` means that both the unzipped and gzipped versions of the extension are valid.
"""

if pdf_format:
text += f"""

**Legend**:

{legend}

"""
else:
md = MarkdownIt()
text += f"""
<details>
<summary><strong>Legend:</strong></summary>
{md.render(legend)}
</details>
"""

return text


def make_entity_table(schema, tablefmt="github", **kwargs):
"""Produce entity table (markdown) based on schema.

Expand Down
1 change: 1 addition & 0 deletions tools/schemacode/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ doc =
render =
tabulate
pandas
markdown-it-py
tests =
codecov
coverage[toml]
Expand Down