|
21 | 21 | "files": "files and directories",
|
22 | 22 | "formats": "format",
|
23 | 23 | "metadata": "metadata",
|
| 24 | + "metaentities": "meta-entity", |
24 | 25 | "top_level_files": "top level file",
|
25 | 26 | "suffixes": "suffix",
|
26 | 27 | }
|
@@ -150,12 +151,6 @@ def make_glossary(schema, src_path=None):
|
150 | 151 | obj_desc = obj_def.get("description", None)
|
151 | 152 | if obj_desc is None:
|
152 | 153 | raise ValueError(f"{obj_marker} has no description.")
|
153 |
| - # A backslash before a newline means continue a string |
154 |
| - obj_desc = obj_desc.replace("\\\n", "") |
155 |
| - # Two newlines should be respected |
156 |
| - obj_desc = obj_desc.replace("\n\n", "<br>") |
157 |
| - # Otherwise a newline corresponds to a space |
158 |
| - obj_desc = obj_desc.replace("\n", " ") |
159 | 154 |
|
160 | 155 | text += f'\n<a name="{obj_marker}"></a>'
|
161 | 156 | text += f"\n## {obj_key}\n\n"
|
@@ -183,7 +178,9 @@ def make_glossary(schema, src_path=None):
|
183 | 178 | levels = [level["name"] if isinstance(level, dict) else level for level in levels]
|
184 | 179 | text += f"**Allowed values**: `{'`, `'.join(levels)}`\n\n"
|
185 | 180 |
|
186 |
| - text += f"**Description**:\n{obj_desc}\n\n" |
| 181 | + # Convert description into markdown and append to text |
| 182 | + obj_desc = MarkdownIt().render(f"**Description**:\n{obj_desc}") |
| 183 | + text += f"{obj_desc}\n\n" |
187 | 184 |
|
188 | 185 | reduced_obj_def = {k: v for k, v in obj_def.items() if k not in keys_to_drop}
|
189 | 186 |
|
@@ -235,6 +232,9 @@ def make_filename_template(
|
235 | 232 | src_path=None,
|
236 | 233 | n_dupes_to_combine=6,
|
237 | 234 | pdf_format=False,
|
| 235 | + placeholders=False, |
| 236 | + empty_dirs=None, |
| 237 | + show_entities=tuple(), |
238 | 238 | **kwargs,
|
239 | 239 | ):
|
240 | 240 | """Create codeblocks containing example filename patterns for a given datatype.
|
@@ -262,6 +262,20 @@ def make_filename_template(
|
262 | 262 | If False, the filename template will use HTML and include hyperlinks.
|
263 | 263 | This works on the website.
|
264 | 264 | Default is False.
|
| 265 | + placeholders : bool, optional |
| 266 | + If True, placeholder meta-entities will replace keyword-value entities in the |
| 267 | + filename. |
| 268 | + If ``dstype`` is ``"raw"``, the placeholder meta-entity is ``<matches>``. |
| 269 | + If ``dstype`` is ``"derivatives"``, the placeholder meta-entity is ``<source_entities>``. |
| 270 | + Default is False. |
| 271 | + empty_dirs: bool, optional |
| 272 | + If False, empty datatype directories are not included. If ``placeholders`` is True, |
| 273 | + this option is set False. |
| 274 | + Default is True. |
| 275 | + show_entities: tuple, optional |
| 276 | + If ``placeholders`` is ``False`` this argument is ignored. |
| 277 | + When using placeholders, this argument can be set to a list or tuple of entity |
| 278 | + names that will be "extracted" out of the placeholder. |
265 | 279 |
|
266 | 280 | Other Parameters
|
267 | 281 | ----------------
|
@@ -313,19 +327,39 @@ def make_filename_template(
|
313 | 327 | for datatype in rule.datatypes:
|
314 | 328 | file_groups.setdefault(datatype, []).append(rule)
|
315 | 329 |
|
| 330 | + if empty_dirs is None: |
| 331 | + empty_dirs = not placeholders |
| 332 | + |
| 333 | + entity_list = schema.rules.entities |
| 334 | + start_string = "" |
| 335 | + if placeholders: |
| 336 | + metaentity_name = "matches" if dstype == "raw" else "source_entities" |
| 337 | + start_string = ( |
| 338 | + lt |
| 339 | + + utils._link_with_html( |
| 340 | + metaentity_name, |
| 341 | + html_path=GLOSSARY_PATH + ".html", |
| 342 | + heading=f"{metaentity_name}-metaentities", |
| 343 | + pdf_format=pdf_format, |
| 344 | + ) |
| 345 | + + gt |
| 346 | + ) |
| 347 | + entity_list = show_entities |
| 348 | + |
316 | 349 | for datatype in sorted(file_groups):
|
| 350 | + group_lines = [] |
317 | 351 | datatype_string = utils._link_with_html(
|
318 | 352 | datatype,
|
319 | 353 | html_path=GLOSSARY_PATH + ".html",
|
320 | 354 | heading=f"{datatype.lower()}-datatypes",
|
321 | 355 | pdf_format=pdf_format,
|
322 | 356 | )
|
323 |
| - lines.append(f"\t\t{datatype_string}/") |
| 357 | + group_lines.append(f"\t\t{datatype_string}/") |
324 | 358 |
|
325 | 359 | # Unique filename patterns
|
326 | 360 | for group in file_groups[datatype]:
|
327 |
| - ent_string = "" |
328 |
| - for ent in schema.rules.entities: |
| 361 | + ent_string = start_string |
| 362 | + for ent in entity_list: |
329 | 363 | if ent not in group.entities:
|
330 | 364 | continue
|
331 | 365 |
|
@@ -413,12 +447,18 @@ def make_filename_template(
|
413 | 447 | pdf_format=pdf_format,
|
414 | 448 | )
|
415 | 449 |
|
416 |
| - lines.extend( |
| 450 | + group_lines.extend( |
417 | 451 | f"\t\t\t{ent_string}_{suffix}{extension}"
|
418 | 452 | for suffix in sorted(suffixes)
|
419 | 453 | for extension in sorted(extensions)
|
420 | 454 | )
|
421 | 455 |
|
| 456 | + # If the datatype does not have any files, skip |
| 457 | + if not empty_dirs and len(group_lines) == 1: |
| 458 | + continue |
| 459 | + |
| 460 | + lines.extend(group_lines) |
| 461 | + |
422 | 462 | paragraph = "\n".join(lines)
|
423 | 463 | if pdf_format:
|
424 | 464 | codeblock = f"Template:\n```Text\n{paragraph}\n```"
|
@@ -459,6 +499,11 @@ def append_filename_template_legend(text, pdf_format=False):
|
459 | 499 | """
|
460 | 500 |
|
461 | 501 | legend = f"""{info_str}
|
| 502 | +- `<matches>` is a placeholder to denote an arbitrary (and valid) sequence of entities |
| 503 | + and labels at the beginning of the filename (only BIDS "raw"). |
| 504 | +- `<source_entities>` is a placeholder to denote an arbitrary sequence of entities and labels |
| 505 | + at the beginning of the filename matching a source file from which the file derives |
| 506 | + (only BIDS-Derivatives). |
462 | 507 | - Filename entities or directories between square brackets
|
463 | 508 | (for example, `[_ses-<label>]`) are OPTIONAL.
|
464 | 509 | - Some entities may only allow specific values,
|
|
0 commit comments