diff --git a/macros_doc.md b/macros_doc.md index c202891717..cc238c6781 100644 --- a/macros_doc.md +++ b/macros_doc.md @@ -78,7 +78,7 @@ consistency. ## What macros are available? All the macros we use are in listed in this -[python file](https://github.com/bids-standard/bids-specification/blob/master/tools/mkdocs_macros_bids/macros.py). +[Python file](https://github.com/bids-standard/bids-specification/blob/master/tools/mkdocs_macros_bids/macros.py). | Name | Purpose | Uses schema | Example | | ----------------------- | -------------------------------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | diff --git a/pdf_build_src/process_markdowns.py b/pdf_build_src/process_markdowns.py index 31bf6eb746..4f594b2927 100644 --- a/pdf_build_src/process_markdowns.py +++ b/pdf_build_src/process_markdowns.py @@ -562,6 +562,13 @@ def edit_titlepage(): file.writelines(data) +class MockPage: + pass + +class MockFile: + pass + + def process_macros(duplicated_src_dir_path): """Search for mkdocs macros in the specification, run the embedded functions, and replace the macros with their outputs. @@ -594,6 +601,15 @@ def process_macros(duplicated_src_dir_path): with open(filename, "r") as fo: contents = fo.read() + # Create a mock MkDocs Page object that has a "file" attribute, + # which is a mock MkDocs File object with a str "src_path" attribute + # The src_path + mock_file = MockFile() + mock_file.src_path = os.sep.join(filename.split(os.sep)[1::]) + + page = MockPage() + page.file = mock_file + # Replace code snippets in the text with their outputs matches = re.findall(re_code_snippets, contents) for m in matches: diff --git a/src/02-common-principles.md b/src/02-common-principles.md index 5e1379b163..b94bc73f19 100644 --- a/src/02-common-principles.md +++ b/src/02-common-principles.md @@ -486,7 +486,8 @@ and a guide for using macros can be found at "Units": "RECOMMENDED", "TermURL": "RECOMMENDED", "HED": "OPTIONAL", - } + }, + page.file ) }} Please note that while both `Units` and `Levels` are RECOMMENDED, typically only one diff --git a/src/03-modality-agnostic-files.md b/src/03-modality-agnostic-files.md index 82bdc20af0..7483c34844 100644 --- a/src/03-modality-agnostic-files.md +++ b/src/03-modality-agnostic-files.md @@ -36,7 +36,8 @@ and a guide for using macros can be found at "DatasetDOI": "OPTIONAL", "GeneratedBy": "RECOMMENDED", "SourceDatasets": "RECOMMENDED", - } + }, + page.file ) }} Each object in the `GeneratedBy` array includes the following REQUIRED, RECOMMENDED @@ -114,7 +115,8 @@ and a guide for using macros can be found at {{ MACROS___make_metadata_table( { "GeneratedBy": "REQUIRED" - } + }, + page.file ) }} If a derived dataset is stored as a subdirectory of the raw dataset, then the `Name` field @@ -236,7 +238,8 @@ and a guide for using macros can be found at "handedness": "RECOMMENDED", "strain": "RECOMMENDED", "strain_rrid": "RECOMMENDED", - } + }, + page.file ) }} Throughout BIDS you can indicate missing values with `n/a` (for "not @@ -319,7 +322,8 @@ and a guide for using macros can be found at "sample_type": "REQUIRED", "pathology": "RECOMMENDED", "derived_from": "RECOMMENDED", - } + }, + page.file ) }} `samples.tsv` example: @@ -392,7 +396,8 @@ and a guide for using macros can be found at { "MeasurementToolMetadata": "OPTIONAL", "Derivative": "OPTIONAL", - } + }, + page.file ) }} As an example, consider the contents of a file called @@ -464,7 +469,8 @@ and a guide for using macros can be found at { "filename": ("REQUIRED", "There MUST be exactly one row for each file."), "acq_time__scans": ("OPTIONAL"), - } + }, + page.file ) }} Additional fields can include external behavioral measures relevant to the @@ -514,7 +520,8 @@ and a guide for using macros can be found at "session_id": ("REQUIRED", "There MUST be exactly one row for each session."), "acq_time__sessions": ("OPTIONAL"), "pathology": "RECOMMENDED", - } + }, + page.file ) }} `_sessions.tsv` example: diff --git a/src/04-modality-specific-files/01-magnetic-resonance-imaging-data.md b/src/04-modality-specific-files/01-magnetic-resonance-imaging-data.md index 917b0d03aa..dc9474c053 100644 --- a/src/04-modality-specific-files/01-magnetic-resonance-imaging-data.md +++ b/src/04-modality-specific-files/01-magnetic-resonance-imaging-data.md @@ -36,7 +36,8 @@ and a guide for using macros can be found at "MRTransmitCoilSequence": "RECOMMENDED", "MatrixCoilMode": "RECOMMENDED", "CoilCombinationMethod": "RECOMMENDED", - } + }, + page.file ) }} Example for `ReceiveCoilActiveElements`: @@ -83,7 +84,8 @@ and a guide for using macros can be found at "SpoilingRFPhaseIncrement": 'RECOMMENDED if the SpoilingType is `"RF"` or `"COMBINED"`.', "SpoilingGradientMoment": 'RECOMMENDED if the SpoilingType is `"GRADIENT"` or `"COMBINED"`.', "SpoilingGradientDuration": 'RECOMMENDED if the SpoilingType is `"GRADIENT"` or `"COMBINED"`.', - } + }, + page.file ) }} ### In-Plane Spatial Encoding @@ -119,7 +121,8 @@ and a guide for using macros can be found at "directions](#case-4-multiple-phase-encoded-directions-pepolar)).", ), "MixingTime": "RECOMMENDED", - } + }, + page.file ) }} 2Conveniently, for Siemens data, this value is easily obtained as @@ -148,7 +151,8 @@ and a guide for using macros can be found at "SliceTiming": "RECOMMENDED, but REQUIRED for sparse sequences that do not have the `DelayTime` field set, and Arterial Spin Labeling with `MRAcquisitionType` set on `2D`.", "SliceEncodingDirection": "RECOMMENDED", "DwellTime": "RECOMMENDED", - } + }, + page.file ) }} ### RF & Contrast @@ -163,7 +167,8 @@ and a guide for using macros can be found at { "FlipAngle": "RECOMMENDED, but REQUIRED if `LookLocker` is set `true`", "NegativeContrast": "OPTIONAL", - } + }, + page.file ) }} ### Slice Acceleration @@ -177,7 +182,8 @@ and a guide for using macros can be found at {{ MACROS___make_metadata_table( { "MultibandAccelerationFactor": "RECOMMENDED", - } + }, + page.file ) }} ### Anatomical landmarks @@ -193,7 +199,8 @@ and a guide for using macros can be found at {{ MACROS___make_metadata_table( { "AnatomicalLandmarkCoordinates__mri": "RECOMMENDED", - } + }, + page.file ) }} ### Echo-Planar Imaging and *B0* mapping @@ -220,7 +227,8 @@ and a guide for using macros can be found at { "B0FieldIdentifier": "RECOMMENDED", "B0FieldSource": "RECOMMENDED", - } + }, + page.file ) }} ### Institution information @@ -236,7 +244,8 @@ and a guide for using macros can be found at "InstitutionName": ("RECOMMENDED", "Corresponds to DICOM Tag 0008, 0080 `InstitutionName`."), "InstitutionAddress": ("RECOMMENDED", "Corresponds to DICOM Tag 0008, 0081 `InstitutionAddress`."), "InstitutionalDepartmentName": ("RECOMMENDED", "Corresponds to DICOM Tag 0008, 1040 `Institutional Department Name`.") - } + }, + page.file ) }} When adding additional metadata please use the CamelCase version of @@ -276,7 +285,8 @@ and a guide for using macros can be found at "PDT2", "UNIT1", "angio", - ] + ], + page.file ) }} @@ -335,7 +345,8 @@ and a guide for using macros can be found at "ContrastBolusIngredient": "OPTIONAL", "RepetitionTimeExcitation": "OPTIONAL", "RepetitionTimePreparation": "OPTIONAL", - } + }, + page.file ) }} The [`part-