From e2ab4c9489c2392cc2f718eb2b688e791309fa88 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Fri, 24 Nov 2023 17:44:06 -0800 Subject: [PATCH 01/22] sets up code splitting using yaml imports --- .metadock/content_schematics/cli.yml | 45 ++++ .../content_schematics/example_project.yml | 115 +++++++++++ .../content_schematics/python_interfaces.yml | 26 +++ .metadock/content_schematics/repo_readme.yml | 194 +----------------- .metadock/generated_documents/README.html | 18 +- .metadock/generated_documents/README.md | 16 +- .../repo_readme_template.md | 20 +- README.md | 16 +- metadock/engine.py | 7 +- metadock/exceptions.py | 4 + metadock/yaml_utils.py | 61 +++++- tests/test_engine.py | 45 +++- tests/test_yaml_utils.py | 61 ++++++ 13 files changed, 395 insertions(+), 233 deletions(-) create mode 100644 .metadock/content_schematics/cli.yml create mode 100644 .metadock/content_schematics/example_project.yml create mode 100644 .metadock/content_schematics/python_interfaces.yml diff --git a/.metadock/content_schematics/cli.yml b/.metadock/content_schematics/cli.yml new file mode 100644 index 0000000..a298d64 --- /dev/null +++ b/.metadock/content_schematics/cli.yml @@ -0,0 +1,45 @@ +cli: + usage_string: | + usage: metadock [-h] [-p PROJECT_DIR] {init,validate,build,list,clean} ... + + Generates and formats Jinja documentation templates from yaml sources. + + positional arguments: + {init,validate,build,list,clean} + Metadock command + init Initialize a new Metadock project in a folder which does not currently have one. + validate Validate the structure of an existing Metadock project. + build Build a Metadock project, rendering some or all documents. + list List all recognized documents which can be generated from a given selection. + clean Cleans the generated_documents directory for the Metadock project. + + options: + -h, --help show this help message and exit + -p PROJECT_DIR, --project-dir PROJECT_DIR + Project directory containing a .metadock directory. + + commands: + init: + description: Used to initialize a fresh Metadock project in a folder which does not currently have one. + usage: metadock [-p PROJECT_DIR] init + python_interface: { import: python_interfaces.yml, key: python_interfaces.init } + + validate: + description: Used to validate the structure of an existing Metadock project. + usage: metadock [-p PROJECT_DIR] validate + python_interface: { import: python_interfaces.yml, key: python_interfaces.validate } + + build: + description: Used to build a Metadock project, rendering some or all documents. + usage: metadock [-p PROJECT_DIR] build [-s SCHEMATIC_GLOBS [SCHEMATIC_GLOBS ...]] [-t TEMPLATE_GLOBS [TEMPLATE_GLOBS ...]] + python_interface: { import: python_interfaces.yml, key: python_interfaces.build } + + list: + description: Used to list all recognized documents which can be generated from a given selection. + usage: metadock [-p PROJECT_DIR] list [-s SCHEMATIC_GLOBS [SCHEMATIC_GLOBS ...]] [-t TEMPLATE_GLOBS [TEMPLATE_GLOBS ...]] + python_interface: { import: python_interfaces.yml, key: python_interfaces.list } + + clean: + description: Used to clean the generated_documents directory for the Metadock project. + usage: metadock [-p PROJECT_DIR] clean + python_interface: { import: python_interfaces.yml, key: python_interfaces.clean } \ No newline at end of file diff --git a/.metadock/content_schematics/example_project.yml b/.metadock/content_schematics/example_project.yml new file mode 100644 index 0000000..9bc7d3b --- /dev/null +++ b/.metadock/content_schematics/example_project.yml @@ -0,0 +1,115 @@ +example_project: + + structure: | + MyProject/ + - ... + - + - ... + - .metadock/ + - templated_documents/ + - gitlab_mr_template.md + - content_schematics/ + - gitlab_mr__feature1.yml + - gitlab_mr__otherfeature.yml + - generated_documents/ + - gitlab_mr__feature1.md + - gitlab_mr__feature1.html + - gitlab_mr__otherfeature.md + - gitlab_mr__otherfeature.html + + templated_documents: + gitlab_mr_template.md: | + {%- set jira_project_name = jira.get('project_name') -%} + {%- set jira_project_id = jira.get('project_id') -%} + {%- set jira_ticket_num = jira.get('ticket_num') -%} + {%- set jira_ticket_id = jira_project_name ~ "-" ~ jira_ticket_num -%} + {%- set mr_summary = merge_request.get('summary') -%} + # [{{ jira_ticket_id }}] {{ mr_summary }} + + Welcome to my MR. Some of the changes are listed below: + + {% for change in merge_request.get('changes', []) -%} + {{ loop.index }}. {{ change }}{{ "\n" if not loop.last else "" }} + {%- endfor %} + + {% if merge_request.get('breaking_changes') -%} + In addition to the changes above, there are also a few breaking changes introduced in this MR: + + {% for breaking_change in merge_request.get('breaking_changes') -%} + - {{ breaking_change.get('summary') }} + - **Affected downstream stakeholders**: {{ breaking_change.get('affected_downstream', [{'id': 'None'}]) | map(attribute='id') | join(", ") }}. + - **Suggested remedy**: {{ breaking_change.get('suggested_remedy', 'None') }}{{ "\n" if not loop.last else "" }} + {%- endfor -%} + {%- endif %} + + For more information, please check out the Jira ticket associated with this MR, {{ jira_ticket_id }}. + + content_schematics: + gitlab_mr__feature1.yml: | + #... + # yaml anchor definitions + #... + + content_schematics: + + - name: gitlab_mr__feature1 + template: gitlab_mr_template.md + target_formats: [ md+html, md ] + + context: + + jira: + <<: *JiraProject-IGDP + ticket_num: "13" + + merge_request: + summary: Adding software version as hard requirement for staging + changes: + - "Added software version to staging model." + - "Added unit tests for valid software version, invalid software version, missing software version." + breaking_changes: + - summary: "Dropping all records which are missing software version." + affected_downstream: + - *Stakeholder-Service + - *Stakeholder-Analytics + suggested_remedy: | + - Drop all records which are missing software version. + - Add software version as a hard requirement for staging. + + generated_documents: + gitlab_mr__feature1.md: | + # [IGDP-13] Adding software version as hard requirement for staging + + Welcome to my MR. Some of the changes are listed below: + + 1. Added software version to staging model. + 2. Added unit tests for valid software version, invalid software version, missing software version. + + In addition to the changes above, there are also a few breaking changes introduced in this MR: + + - Dropping all records which are missing software version. + - **Affected downstream stakeholders**: Service, Analytics. + - **Suggested remedy**: + - Drop all records which are missing software version. + - Add software version as a hard requirement for staging. + + For more information, please check out the Jira ticket associated with this MR, IGDP-13. + + gitlab_mr__feature1.html: | +

[IGDP-13] Adding software version as hard requirement for staging

+

Welcome to my MR. Some of the changes are listed below:

+
    +
  1. Added software version to staging model.
  2. +
  3. Added unit tests for valid software version, invalid software version, missing software version.
  4. +
+

In addition to the changes above, there are also a few breaking changes introduced in this MR:

+ +

For more information, please check out the Jira ticket associated with this MR, IGDP-13.

\ No newline at end of file diff --git a/.metadock/content_schematics/python_interfaces.yml b/.metadock/content_schematics/python_interfaces.yml new file mode 100644 index 0000000..01971cc --- /dev/null +++ b/.metadock/content_schematics/python_interfaces.yml @@ -0,0 +1,26 @@ +python_interfaces: + + init: + source_file: metadock/__init__.py + method_name: metadock.Metadock.init + signature: (Path | str) -> metadock.Metadock + + validate: + source_file: metadock/__init__.py + method_name: metadock.Metadock.validate + signature: () -> metadock.engine.MetadockProjectValidationResult + + build: + source_file: metadock/__init__.py + method_name: metadock.Metadock.build + signature: (list[str], list[str]) -> metadock.engine.MetadockProjectBuildResult + + list: + source_file: metadock/__init__.py + method_name: metadock.Metadock.list + signature: (list[str], list[str]) -> list[str] + + clean: + source_file: metadock/__init__.py + method_name: metadock.Metadock.clean + signature: () -> None \ No newline at end of file diff --git a/.metadock/content_schematics/repo_readme.yml b/.metadock/content_schematics/repo_readme.yml index 2a8ab0d..4a00dfd 100644 --- a/.metadock/content_schematics/repo_readme.yml +++ b/.metadock/content_schematics/repo_readme.yml @@ -1,158 +1,3 @@ -.example_project_structure: &example_project_structure | - MyProject/ - - ... - - - - ... - - .metadock/ - - templated_documents/ - - gitlab_mr_template.md - - content_schematics/ - - gitlab_mr__feature1.yml - - gitlab_mr__otherfeature.yml - - generated_documents/ - - gitlab_mr__feature1.md - - gitlab_mr__feature1.html - - gitlab_mr__otherfeature.md - - gitlab_mr__otherfeature.html - -.example_project_templated_documents_gitlab_mr_template_md: &example_project_templated_documents_gitlab_mr_template_md | - {%- set jira_project_name = jira.get('project_name') -%} - {%- set jira_project_id = jira.get('project_id') -%} - {%- set jira_ticket_num = jira.get('ticket_num') -%} - {%- set jira_ticket_id = jira_project_name ~ "-" ~ jira_ticket_num -%} - {%- set mr_summary = merge_request.get('summary') -%} - # [{{ jira_ticket_id }}] {{ mr_summary }} - - Welcome to my MR. Some of the changes are listed below: - - {% for change in merge_request.get('changes', []) -%} - {{ loop.index }}. {{ change }}{{ "\n" if not loop.last else "" }} - {%- endfor %} - - {% if merge_request.get('breaking_changes') -%} - In addition to the changes above, there are also a few breaking changes introduced in this MR: - - {% for breaking_change in merge_request.get('breaking_changes') -%} - - {{ breaking_change.get('summary') }} - - **Affected downstream stakeholders**: {{ breaking_change.get('affected_downstream', [{'id': 'None'}]) | map(attribute='id') | join(", ") }}. - - **Suggested remedy**: {{ breaking_change.get('suggested_remedy', 'None') }}{{ "\n" if not loop.last else "" }} - {%- endfor -%} - {%- endif %} - - For more information, please check out the Jira ticket associated with this MR, {{ jira_ticket_id }}. - -.example_project_content_schematics_gitlab_mr__feature1_yml: &example_project_content_schematics_gitlab_mr__feature1_yml | - #... - # yaml anchor definitions - #... - - content_schematics: - - - name: gitlab_mr__feature1 - template: gitlab_mr_template.md - target_formats: [ md+html, md ] - - context: - - jira: - <<: *JiraProject-IGDP - ticket_num: "13" - - merge_request: - summary: Adding software version as hard requirement for staging - changes: - - "Added software version to staging model." - - "Added unit tests for valid software version, invalid software version, missing software version." - breaking_changes: - - summary: "Dropping all records which are missing software version." - affected_downstream: - - *Stakeholder-Service - - *Stakeholder-Analytics - suggested_remedy: | - - Drop all records which are missing software version. - - Add software version as a hard requirement for staging. - -.example_project_generated_documents_gitlab_mr__feature1_md: &example_project_generated_documents_gitlab_mr__feature1_md | - # [IGDP-13] Adding software version as hard requirement for staging - - Welcome to my MR. Some of the changes are listed below: - - 1. Added software version to staging model. - 2. Added unit tests for valid software version, invalid software version, missing software version. - - In addition to the changes above, there are also a few breaking changes introduced in this MR: - - - Dropping all records which are missing software version. - - **Affected downstream stakeholders**: Service, Analytics. - - **Suggested remedy**: - - Drop all records which are missing software version. - - Add software version as a hard requirement for staging. - - For more information, please check out the Jira ticket associated with this MR, IGDP-13. - -.example_project_generated_documents_gitlab_mr__feature1_html: &example_project_generated_documents_gitlab_mr__feature1_html | -

[IGDP-13] Adding software version as hard requirement for staging

-

Welcome to my MR. Some of the changes are listed below:

-
    -
  1. Added software version to staging model.
  2. -
  3. Added unit tests for valid software version, invalid software version, missing software version.
  4. -
-

In addition to the changes above, there are also a few breaking changes introduced in this MR:

-
    -
  • - Dropping all records which are missing software version.
      -
    • Affected downstream stakeholders: Service, Analytics.
    • -
    • Suggested remedy: Handle deletions manualy, using the software version column in the exposures to identify source records - which will be dropped, and drop them in the target environment after our change is deployed.
    • -
    -
  • -
-

For more information, please check out the Jira ticket associated with this MR, IGDP-13.

- -.cli_usage_string: &cli_usage_string | - usage: metadock [-h] [-p PROJECT_DIR] {init,validate,build,list,clean} ... - - Generates and formats Jinja documentation templates from yaml sources. - - positional arguments: - {init,validate,build,list,clean} - Metadock command - init Initialize a new Metadock project in a folder which does not currently have one. - validate Validate the structure of an existing Metadock project. - build Build a Metadock project, rendering some or all documents. - list List all recognized documents which can be generated from a given selection. - clean Cleans the generated_documents directory for the Metadock project. - - options: - -h, --help show this help message and exit - -p PROJECT_DIR, --project-dir PROJECT_DIR - Project directory containing a .metadock directory. - -.python_interface_init: &python_interface_init - source_file: metadock/__init__.py - method_name: metadock.Metadock.init - signature: (Path | str) -> metadock.Metadock - -.python_interface_validate: &python_interface_validate - source_file: metadock/__init__.py - method_name: metadock.Metadock.validate - signature: () -> metadock.engine.MetadockProjectValidationResult - -.python_interface_build: &python_interface_build - source_file: metadock/__init__.py - method_name: metadock.Metadock.build - signature: (list[str], list[str]) -> metadock.engine.MetadockProjectBuildResult - -.python_interface_list: &python_interface_list - source_file: metadock/__init__.py - method_name: metadock.Metadock.list - signature: (list[str], list[str]) -> metadock.engine.MetadockProjectListResult - -.python_interface_clean: &python_interface_clean - source_file: metadock/__init__.py - method_name: metadock.Metadock.clean - signature: () -> None - content_schematics: - name: README @@ -166,45 +11,10 @@ content_schematics: marko: "[marko](https://github.com/frostming/marko)" # Example project metadata - example_project: - structure: *example_project_structure - templated_documents: - gitlab_mr_template.md: *example_project_templated_documents_gitlab_mr_template_md - content_schematics: - gitlab_mr__feature1.yml: *example_project_content_schematics_gitlab_mr__feature1_yml - generated_documents: - gitlab_mr__feature1.md: *example_project_generated_documents_gitlab_mr__feature1_md - gitlab_mr__feature1.html: *example_project_generated_documents_gitlab_mr__feature1_html + example_project: { import: example_project.yml, key: example_project } # CLI information - cli: - usage_string: *cli_usage_string - commands: - - init: - description: Used to initialize a fresh Metadock project in a folder which does not currently have one. - usage: metadock [-p PROJECT_DIR] init - python_interface: *python_interface_init - - validate: - description: Used to validate the structure of an existing Metadock project. - usage: metadock [-p PROJECT_DIR] validate - python_interface: *python_interface_validate - - build: - description: Used to build a Metadock project, rendering some or all documents. - usage: metadock [-p PROJECT_DIR] build [-s SCHEMATIC_GLOBS [SCHEMATIC_GLOBS ...]] [-t TEMPLATE_GLOBS [TEMPLATE_GLOBS ...]] - python_interface: *python_interface_build - - list: - description: Used to list all recognized documents which can be generated from a given selection. - usage: metadock [-p PROJECT_DIR] list [-s SCHEMATIC_GLOBS [SCHEMATIC_GLOBS ...]] [-t TEMPLATE_GLOBS [TEMPLATE_GLOBS ...]] - python_interface: *python_interface_list - - clean: - description: Used to clean the generated_documents directory for the Metadock project. - usage: metadock [-p PROJECT_DIR] clean - python_interface: *python_interface_clean + cli: { import: cli.yml, key: cli } # Target formats target_formats: diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 80c1957..b247756 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -25,7 +25,8 @@

Quick Intro

The root of your project is expected to have a .metadock folder, which can be generated from the CLI using metadock init.

Basic CLI Usage

-

The metadock CLI, installed using pip install metadock, has 5 basic commands, spelled out in the help message:

+

The metadock CLI, installed using pip install metadock, has 5 basic commands, +spelled out in the help message:

usage: metadock [-h] [-p PROJECT_DIR] {init,validate,build,list,clean} ...
 
 Generates and formats Jinja documentation templates from yaml sources.
@@ -100,7 +101,7 @@ 

Basic CLI Usage

  • Python interface:
    • Name: metadock.Metadock.list
    • -
    • Signature: (list[str], list[str]) -> metadock.engine.MetadockProjectListResult
    • +
    • Signature: (list[str], list[str]) -> list[str]
  • @@ -205,8 +206,8 @@

    [IGDP-13] Adding software version as hard requirement for staging

    For more information, please check out the Jira ticket associated with this MR, IGDP-13.

    -

    Because the target_formats we chose included md+html and md, we also get an HTML rendering of the document for free, -located at generated_documents/gitlab_mr__feature_1.html:

    +

    Because the target_formats we chose included md+html and md, we also get an HTML rendering of the document for +free, located at generated_documents/gitlab_mr__feature_1.html:

    <h1>[IGDP-13] Adding software version as hard requirement for staging</h1>
     <p>Welcome to my MR. Some of the changes are listed below:</p>
     <ol>
    @@ -237,9 +238,12 @@ 

    [IGDP-13] Adding software version as hard requirement for staging

  • Generates the given template, parses it into a markdown document, and then generates HTML from it.
  • -
  • Anything else, e.g. txt, sql or py
  • -
  • Generates the given template as plaintext, and adds the given string as a file extension, e.g. .txt, .sql or -.py.
  • +
  • +Anything else, e.g. txt, sql or py:
      +
    • Generates the given template as plaintext, and adds the given string as a file extension, e.g. +.txt, .sql or .py.
    • +
    +
  • Acknowledgements

    Author:

    diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 1bf7f9b..1f14080 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -34,7 +34,8 @@ The root of your project is expected to have a `.metadock` folder, which can be ## Basic CLI Usage -The `metadock` CLI, installed using `pip install metadock`, has 5 basic commands, spelled out in the help message: +The `metadock` CLI, installed using `pip install metadock`, has 5 basic commands, +spelled out in the help message: ```sh usage: metadock [-h] [-p PROJECT_DIR] {init,validate,build,list,clean} ... @@ -120,7 +121,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.list
    • -
    • Signature: (list[str], list[str]) -> metadock.engine.MetadockProjectListResult
    • +
    • Signature: (list[str], list[str]) -> list[str]
  • @@ -179,7 +180,6 @@ For more information, please check out the Jira ticket associated with this MR, This is a very simple MR format which can easily be generalized to allow for quickly generating large sets of docs which meet the same format and style requirements. An example *content schematic* which could service this template could be in `gitlab_mr__feature1.yml`: - ```yml #... # yaml anchor definitions @@ -232,8 +232,8 @@ called `generated_documents/gitlab_mr__feature1.md`: > > For more information, please check out the Jira ticket associated with this MR, IGDP-13. -Because the `target_formats` we chose included `md+html` _and_ `md`, we also get an HTML rendering of the document for free, -located at `generated_documents/gitlab_mr__feature_1.html`: +Because the `target_formats` we chose included `md+html` _and_ `md`, we also get an HTML rendering of the document for +free, located at `generated_documents/gitlab_mr__feature_1.html`: ```html

    [IGDP-13] Adding software version as hard requirement for staging

    @@ -266,9 +266,9 @@ The natively supported values for `target_formats` are: - `md+html`: - Generates the given template, parses it into a markdown document, and then generates HTML from it. -- Anything else, e.g. `txt`, `sql` or `py` -- Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or - `.py`. +- Anything else, e.g. `txt`, `sql` or `py`: + - Generates the given template as plaintext, and adds the given string as a file extension, e.g. + `.txt`, `.sql` or `.py`. ## Acknowledgements diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index a632d22..8c1bebf 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -18,7 +18,8 @@ The root of your project is expected to have a `.metadock` folder, which can be ## Basic CLI Usage -The `metadock` CLI, installed using `pip install metadock`, has {{ cli.get("commands") | length }} basic commands, spelled out in the help message: +The `metadock` CLI, installed using `pip install metadock`, has {{ cli.get("commands") | length }} basic commands, +spelled out in the help message: {{ md.codeblock(cli.get("usage_string"), language="sh") }} @@ -50,7 +51,6 @@ In the example above, we can imagine the content of our template, `gitlab_mr_tem This is a very simple MR format which can easily be generalized to allow for quickly generating large sets of docs which meet the same format and style requirements. An example *content schematic* which could service this template could be in `gitlab_mr__feature1.yml`: - {{ md.codeblock( example_project.get("content_schematics").get("gitlab_mr__feature1.yml"), @@ -63,8 +63,8 @@ called `generated_documents/gitlab_mr__feature1.md`: {{ md.blockquote(example_project.get("generated_documents").get("gitlab_mr__feature1.md")) }} -Because the `target_formats` we chose included `md+html` _and_ `md`, we also get an HTML rendering of the document for free, -located at `generated_documents/gitlab_mr__feature_1.html`: +Because the `target_formats` we chose included `md+html` _and_ `md`, we also get an HTML rendering of the document for +free, located at `generated_documents/gitlab_mr__feature_1.html`: {{ md.codeblock( @@ -84,16 +84,12 @@ The natively supported values for `target_formats` are: {% for target_format, data in target_formats.items() %} {{ md.list(md.code(target_format) ~ ":", md.list(data.get("description"))) }} {% endfor -%} -{{ - md.list( - "Anything else, e.g. `txt`, `sql` or `py`", - "Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or - `.py`." - ) -}} +- Anything else, e.g. `txt`, `sql` or `py`: + - Generates the given template as plaintext, and adds the given string as a file extension, e.g. + `.txt`, `.sql` or `.py`. ## Acknowledgements Author{% if (authors | length) > 1 %}s{% endif %}: -{{ md.list(*authors) }} \ No newline at end of file +{{ authors | md.list }} \ No newline at end of file diff --git a/README.md b/README.md index 1bf7f9b..1f14080 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ The root of your project is expected to have a `.metadock` folder, which can be ## Basic CLI Usage -The `metadock` CLI, installed using `pip install metadock`, has 5 basic commands, spelled out in the help message: +The `metadock` CLI, installed using `pip install metadock`, has 5 basic commands, +spelled out in the help message: ```sh usage: metadock [-h] [-p PROJECT_DIR] {init,validate,build,list,clean} ... @@ -120,7 +121,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.list
    • -
    • Signature: (list[str], list[str]) -> metadock.engine.MetadockProjectListResult
    • +
    • Signature: (list[str], list[str]) -> list[str]
  • @@ -179,7 +180,6 @@ For more information, please check out the Jira ticket associated with this MR, This is a very simple MR format which can easily be generalized to allow for quickly generating large sets of docs which meet the same format and style requirements. An example *content schematic* which could service this template could be in `gitlab_mr__feature1.yml`: - ```yml #... # yaml anchor definitions @@ -232,8 +232,8 @@ called `generated_documents/gitlab_mr__feature1.md`: > > For more information, please check out the Jira ticket associated with this MR, IGDP-13. -Because the `target_formats` we chose included `md+html` _and_ `md`, we also get an HTML rendering of the document for free, -located at `generated_documents/gitlab_mr__feature_1.html`: +Because the `target_formats` we chose included `md+html` _and_ `md`, we also get an HTML rendering of the document for +free, located at `generated_documents/gitlab_mr__feature_1.html`: ```html

    [IGDP-13] Adding software version as hard requirement for staging

    @@ -266,9 +266,9 @@ The natively supported values for `target_formats` are: - `md+html`: - Generates the given template, parses it into a markdown document, and then generates HTML from it. -- Anything else, e.g. `txt`, `sql` or `py` -- Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or - `.py`. +- Anything else, e.g. `txt`, `sql` or `py`: + - Generates the given template as plaintext, and adds the given string as a file extension, e.g. + `.txt`, `.sql` or `.py`. ## Acknowledgements diff --git a/metadock/engine.py b/metadock/engine.py index 707bb30..16ef5e4 100644 --- a/metadock/engine.py +++ b/metadock/engine.py @@ -483,12 +483,17 @@ def collect_from_file(cls, yaml_path: Path | str) -> "list[MetadockContentSchema raise exceptions.MetadockContentSchematicParsingException( "Missing required key for content schematic in %s: '%s'" % (yaml_path, req_key) ) + + context = yaml_utils.flatten_merge_keys(def_schematic.get("context", {})) + context = yaml_utils.resolve_all_imports( + Path(str(yaml_path).split("/content_schematics/")[0]) / "content_schematics", context + ) content_schematics.append( cls( name=def_schematic["name"], template=def_schematic["template"], target_formats=def_schematic["target_formats"], - context=yaml_utils.flatten_merge_keys(def_schematic.get("context", {})), + context=context, ) ) diff --git a/metadock/exceptions.py b/metadock/exceptions.py index 4f0fe78..7561597 100644 --- a/metadock/exceptions.py +++ b/metadock/exceptions.py @@ -12,3 +12,7 @@ class MetadockTemplateParsingException(MetadockException): class MetadockContentSchematicParsingException(MetadockException): pass + + +class MetadockYamlImportError(MetadockException): + pass diff --git a/metadock/yaml_utils.py b/metadock/yaml_utils.py index 9c853eb..948d70c 100644 --- a/metadock/yaml_utils.py +++ b/metadock/yaml_utils.py @@ -1,6 +1,11 @@ import operator from functools import reduce -from typing import Any +from pathlib import Path +from typing import Any, Optional + +import yaml + +from metadock import exceptions def flatten_merge_keys(yaml_dict: Any) -> dict: @@ -28,3 +33,57 @@ def flatten_merge_keys(yaml_dict: Any) -> dict: flattened_yaml_dict[key] = flat_yaml_value return flattened_yaml_dict + + +def import_key(root_path: Path, relative_path: Path, key: Optional[str] = None) -> Any: + """Try to import an alias from the root path with the given name. + + Args: + root_path (Path): Absolute path to the Metadock project's content_schematics directory + relative_path (Path): Relative path to the external file + key (Optional[str]): Key path to resolve, or None to return the entire file + + Raises: + exceptions.MetadockYamlImportError: Imported key / file could not be resolved + + Returns: + dict: Fully resolved yaml source from the external file + """ + + if not (root_path / relative_path).exists(): + raise exceptions.MetadockYamlImportError(f"Could not find import path '{root_path}'") + + if not (root_path / relative_path).is_file(): + raise exceptions.MetadockYamlImportError(f"Import path '{root_path}' is not a file") + + contents: dict[str, Any] = yaml.load((root_path / relative_path).read_text(), yaml.BaseLoader) + if key is not None: + contents = reduce(lambda acc, el: acc[el], key.split("."), contents) + return resolve_all_imports(root_path, contents) + + +def resolve_all_imports(root_path: Path, yaml_dict: dict[str, Any]) -> dict[str, Any]: + """Recursively resolve all imports in a yaml dictionary object. + + Args: + root_path (Path): Root path to resolve the imports + yaml_dict (dict[str, Any]): Dictionary object with imports to resolve + + Raises: + exceptions.MetadockYamlImportError: One or more import could not be resolved + + Returns: + dict[str, Any]: Dictionary object with imports resolved + """ + if not isinstance(yaml_dict, dict): + return yaml_dict # type: ignore + + if set(yaml_dict.keys()) in ({"import"}, {"import", "key"}): + return import_key(root_path, yaml_dict["import"], yaml_dict.get("key", None)) + + resolved_subdict: dict[str, Any] = {} + + for key in yaml_dict.keys(): + resolved_subdict[key] = resolve_all_imports(root_path, yaml_dict[key]) + + return resolved_subdict diff --git a/tests/test_engine.py b/tests/test_engine.py index d1fdd05..10db69c 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -11,6 +11,17 @@ def metadock_project(empty_metadock_project_dir): # Create some dummy files within the directories (project_dir / "templated_documents" / "template1.md").write_text("Simple plaintext document.") (project_dir / "templated_documents" / "template2.md").write_text("{{ var1 }} is {{ var2 }}.") + (project_dir / "templated_documents" / "imported.md").write_text( + """**Imported identity**: {{ name }} ({{ sem_version }})""" + ) + (project_dir / "content_schematics" / "lib.yml").write_text( + """ + identity: + name: lib + sem_version: 3.0.1 + fix_version: 2023.04.11 + """ + ) (project_dir / "content_schematics" / "schematic1.yml").write_text( """ content_schematics: @@ -45,6 +56,16 @@ def metadock_project(empty_metadock_project_dir): var2: a test """ ) + (project_dir / "content_schematics" / "imported.yml").write_text( + """ + content_schematics: + + - name: schematic_import + template: imported.md + target_formats: [ md ] + context: { import: lib.yml, key: identity } + """ + ) return MetadockProject(project_dir) @@ -54,7 +75,7 @@ def test_metadock_project_templated_documents_directory(metadock_project): def test_metadock_project_templated_documents(metadock_project): - assert len(metadock_project.templated_documents) == 2 + assert len(metadock_project.templated_documents) == 3 def test_metadock_project_content_schematics_directory(metadock_project): @@ -62,7 +83,7 @@ def test_metadock_project_content_schematics_directory(metadock_project): def test_metadock_project_content_schematics(metadock_project): - assert len(metadock_project.content_schematics) == 4 + assert len(metadock_project.content_schematics) == 5 def test_metadock_project_generated_documents_directory(metadock_project): @@ -73,8 +94,8 @@ def test_metadock_project_build(metadock_project): # Test building all schematics build_result = metadock_project.build() - assert len(list(metadock_project.generated_documents_directory.glob("*"))) == 4 - assert len(build_result.generated_documents) == 4 + assert len(list(metadock_project.generated_documents_directory.glob("*"))) == 5 + assert len(build_result.generated_documents) == 5 assert all(gd.status == "new" for gd in build_result.generated_documents) metadock_project.clean() @@ -149,3 +170,19 @@ def test_metadock_content_schematic(metadock_project): assert content_schem_2a.to_compiled_targets(metadock_project) == {"md": " is ."} assert content_schem_2b.to_compiled_targets(metadock_project) == {"md": "This is a test."} + + +def test_metadock_content_schematic__import_key(metadock_project): + content_schem_imported = metadock_project.content_schematics["schematic_import"] + assert content_schem_imported.context + assert content_schem_imported.context == { + "name": "lib", + "sem_version": "3.0.1", + "fix_version": "2023.04.11", + } + + metadock_project.build(["schematic_import"]) + + gen_doc = metadock_project.generated_documents_directory / "schematic_import.md" + assert gen_doc.exists() + assert gen_doc.read_text() == "**Imported identity**: lib (3.0.1)" diff --git a/tests/test_yaml_utils.py b/tests/test_yaml_utils.py index 963302b..054d9c9 100644 --- a/tests/test_yaml_utils.py +++ b/tests/test_yaml_utils.py @@ -1,4 +1,8 @@ +import string +from pathlib import Path + import pytest +import yaml from metadock import yaml_utils @@ -50,3 +54,60 @@ ) def test_yaml_utils__flatten_merge_keys(yml_dict, flat_dict): assert yaml_utils.flatten_merge_keys(yml_dict) == flat_dict + + +@pytest.mark.parametrize( + "contents,key,value", + [ + pytest.param( + "name: foo", + "name", + "foo", + id="simple single-key dict", + ), + pytest.param( + "name: foo\nvalue: bar", + "value", + "bar", + id="simple 2-key dict", + ), + pytest.param( + "name: \n x: 32\n y: 64", + "name", + {"x": "32", "y": "64"}, + id="simple full dict query", + ), + pytest.param( + "name: \n x: 32\n y: 64", + "name.x", + "32", + id="simple dict key query", + ), + ], +) +def test_yaml_utils__import_key(tmp_path, contents, key, value): + (tmp_path / "test.yml").write_text(contents) + assert yaml_utils.import_key(tmp_path, Path("test.yml"), key) == value + + +def test_yaml_utils__resolve_all_imports(tmp_path): + (tmp_path / "misc.yml").write_text("et_cetera:\n first_value: David\n second_value: Excelsior") + + (tmp_path / "test1.yml").write_text("test:\n <<: { import: misc.yml, key: et_cetera.second_value }") + test_1_contents = yaml_utils.flatten_merge_keys(yaml.safe_load((tmp_path / "test1.yml").read_text())) + + assert yaml_utils.resolve_all_imports(tmp_path, test_1_contents) == {"test": "Excelsior"} + + (tmp_path / "test2.yml").write_text("test:\n <<: { import: misc.yml, key: et_cetera }") + test_2_contents = yaml_utils.flatten_merge_keys(yaml.safe_load((tmp_path / "test2.yml").read_text())) + + assert yaml_utils.resolve_all_imports(tmp_path, test_2_contents) == { + "test": {"first_value": "David", "second_value": "Excelsior"} + } + + (tmp_path / "test3.yml").write_text("test:\n <<: { import: misc.yml }") + test_2_contents = yaml_utils.flatten_merge_keys(yaml.safe_load((tmp_path / "test3.yml").read_text())) + + assert yaml_utils.resolve_all_imports(tmp_path, test_2_contents) == { + "test": {"et_cetera": {"first_value": "David", "second_value": "Excelsior"}} + } From 8d688bd99366826f54fd2222f2df25e91c740406 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Fri, 24 Nov 2023 18:21:27 -0800 Subject: [PATCH 02/22] making `key` optional, fixing order of ops in yaml processing --- .metadock/content_schematics/repo_readme.yml | 10 +++---- metadock/engine.py | 18 +++++++++---- metadock/yaml_utils.py | 25 +++++++++-------- tests/test_engine.py | 28 +++++++++++++++++--- 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/.metadock/content_schematics/repo_readme.yml b/.metadock/content_schematics/repo_readme.yml index 4a00dfd..4199c04 100644 --- a/.metadock/content_schematics/repo_readme.yml +++ b/.metadock/content_schematics/repo_readme.yml @@ -10,11 +10,11 @@ content_schematics: Jinja2: "[Jinja2](https://github.com/pallets/jinja)" marko: "[marko](https://github.com/frostming/marko)" - # Example project metadata - example_project: { import: example_project.yml, key: example_project } - - # CLI information - cli: { import: cli.yml, key: cli } + <<: + # Import example project configuration + - import: example_project.yml + # Import CLI information + - import: cli.yml # Target formats target_formats: diff --git a/metadock/engine.py b/metadock/engine.py index 16ef5e4..e458821 100644 --- a/metadock/engine.py +++ b/metadock/engine.py @@ -439,9 +439,7 @@ def to_compiled_targets(self, project: MetadockProject) -> dict[str, str | bytes for target_format in self.target_formats: target_format = MetadockTargetFormatFactory.target_format(target_format) templated_document = project.templated_documents[self.template] - rendered_document = templated_document.jinja_template(project).render( - self.context - ) # | MetadockEnv().dict()) + rendered_document = templated_document.jinja_template(project).render(self.context) post_processed_document = target_format.handler(rendered_document) compiled_targets[target_format.identifier] = post_processed_document @@ -451,7 +449,8 @@ def to_compiled_targets(self, project: MetadockProject) -> dict[str, str | bytes @classmethod def collect_from_file(cls, yaml_path: Path | str) -> "list[MetadockContentSchematic]": """ - Collects content schematics from a YAML file. Flattens any merge keys in the YAML specification. + Collects content schematics from a YAML file. Flattens any merge keys in the YAML specification. Also resolves + any external YAML files imported in the context. Args: yaml_path (Path | str): The path to the YAML file. @@ -461,6 +460,7 @@ def collect_from_file(cls, yaml_path: Path | str) -> "list[MetadockContentSchema Raises: MetadockContentSchematicParsingException: If the YAML file is not found or if a required key is missing. + MetadockYamlImportError: If an imported YAML key or file is not found (or is not a file). """ yaml_path = Path(yaml_path) @@ -471,23 +471,31 @@ def collect_from_file(cls, yaml_path: Path | str) -> "list[MetadockContentSchema "Could not find content schematic file %s" % yaml_path ) + """ Read raw content schematics yaml file """ with yaml_path.open("r") as handle: yaml_contents: dict = yaml.load(handle, yaml.BaseLoader) + """ Determine if there are content schematics in the file """ defined_schematics = yaml_contents.get("content_schematics", []) required_keys = ["name", "target_formats", "template"] + """ For each schematic defined in the YAML file, """ for def_schematic in defined_schematics: + """validate that it has all of the required keys,""" for req_key in required_keys: if not def_schematic.get(req_key): raise exceptions.MetadockContentSchematicParsingException( "Missing required key for content schematic in %s: '%s'" % (yaml_path, req_key) ) - context = yaml_utils.flatten_merge_keys(def_schematic.get("context", {})) + context = def_schematic.get("context", {}) + """ resolve all imports in the context, including those nested in merge keys. """ context = yaml_utils.resolve_all_imports( Path(str(yaml_path).split("/content_schematics/")[0]) / "content_schematics", context ) + """ Then, flatten all of the merge keys. """ + context = yaml_utils.flatten_merge_keys(context) + """ Schematic is now fully determined. Put into pydantic model. """ content_schematics.append( cls( name=def_schematic["name"], diff --git a/metadock/yaml_utils.py b/metadock/yaml_utils.py index 948d70c..26637b7 100644 --- a/metadock/yaml_utils.py +++ b/metadock/yaml_utils.py @@ -47,7 +47,7 @@ def import_key(root_path: Path, relative_path: Path, key: Optional[str] = None) exceptions.MetadockYamlImportError: Imported key / file could not be resolved Returns: - dict: Fully resolved yaml source from the external file + Any: Fully resolved yaml source from the external file """ if not (root_path / relative_path).exists(): @@ -62,28 +62,31 @@ def import_key(root_path: Path, relative_path: Path, key: Optional[str] = None) return resolve_all_imports(root_path, contents) -def resolve_all_imports(root_path: Path, yaml_dict: dict[str, Any]) -> dict[str, Any]: - """Recursively resolve all imports in a yaml dictionary object. +def resolve_all_imports(root_path: Path, yaml_obj: Any) -> Any: + """Recursively resolve all imports in a yaml object. Args: root_path (Path): Root path to resolve the imports - yaml_dict (dict[str, Any]): Dictionary object with imports to resolve + yaml_obj (Any): Yaml object with imports to resolve Raises: exceptions.MetadockYamlImportError: One or more import could not be resolved Returns: - dict[str, Any]: Dictionary object with imports resolved + Any: Yaml object with imports resolved """ - if not isinstance(yaml_dict, dict): - return yaml_dict # type: ignore + if isinstance(yaml_obj, list): + return [resolve_all_imports(root_path, el) for el in yaml_obj] - if set(yaml_dict.keys()) in ({"import"}, {"import", "key"}): - return import_key(root_path, yaml_dict["import"], yaml_dict.get("key", None)) + if not isinstance(yaml_obj, dict): + return yaml_obj # type: ignore + + if set(yaml_obj.keys()) in ({"import"}, {"import", "key"}): + return import_key(root_path, yaml_obj["import"], yaml_obj.get("key", None)) resolved_subdict: dict[str, Any] = {} - for key in yaml_dict.keys(): - resolved_subdict[key] = resolve_all_imports(root_path, yaml_dict[key]) + for key in yaml_obj.keys(): + resolved_subdict[key] = resolve_all_imports(root_path, yaml_obj[key]) return resolved_subdict diff --git a/tests/test_engine.py b/tests/test_engine.py index 10db69c..645ef09 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -22,6 +22,13 @@ def metadock_project(empty_metadock_project_dir): fix_version: 2023.04.11 """ ) + (project_dir / "content_schematics" / "lib2.yml").write_text( + """ + name: lib + sem_version: 3.0.2 + fix_version: 2023.04.21 + """ + ) (project_dir / "content_schematics" / "schematic1.yml").write_text( """ content_schematics: @@ -64,6 +71,15 @@ def metadock_project(empty_metadock_project_dir): template: imported.md target_formats: [ md ] context: { import: lib.yml, key: identity } + + - name: schematic_import2 + template: imported.md + target_formats: [ md ] + context: + <<: + - import: lib.yml + key: identity + - import: lib2.yml """ ) @@ -83,7 +99,7 @@ def test_metadock_project_content_schematics_directory(metadock_project): def test_metadock_project_content_schematics(metadock_project): - assert len(metadock_project.content_schematics) == 5 + assert len(metadock_project.content_schematics) == 6 def test_metadock_project_generated_documents_directory(metadock_project): @@ -94,8 +110,8 @@ def test_metadock_project_build(metadock_project): # Test building all schematics build_result = metadock_project.build() - assert len(list(metadock_project.generated_documents_directory.glob("*"))) == 5 - assert len(build_result.generated_documents) == 5 + assert len(list(metadock_project.generated_documents_directory.glob("*"))) == 6 + assert len(build_result.generated_documents) == 6 assert all(gd.status == "new" for gd in build_result.generated_documents) metadock_project.clean() @@ -181,8 +197,12 @@ def test_metadock_content_schematic__import_key(metadock_project): "fix_version": "2023.04.11", } - metadock_project.build(["schematic_import"]) + metadock_project.build(["schematic_import", "schematic_import2"]) gen_doc = metadock_project.generated_documents_directory / "schematic_import.md" assert gen_doc.exists() assert gen_doc.read_text() == "**Imported identity**: lib (3.0.1)" + + gen_doc2 = metadock_project.generated_documents_directory / "schematic_import2.md" + assert gen_doc2.exists() + assert gen_doc2.read_text() == "**Imported identity**: lib (3.0.2)" From afa967a3a41de2bb2223ebb38aeea313b69f6c64 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Fri, 24 Nov 2023 20:01:21 -0800 Subject: [PATCH 03/22] doing some introspective metadocking on jinja helpers --- .../content_schematics/example_project.yml | 13 ++- .../content_schematics/jinja_helpers.yml | 85 +++++++++++++++++++ .../content_schematics/python_interfaces.yml | 11 +-- .metadock/generated_documents/README.html | 25 +++--- .metadock/generated_documents/README.md | 23 +++-- README.md | 23 +++-- metadock/env.py | 10 +-- 7 files changed, 136 insertions(+), 54 deletions(-) create mode 100644 .metadock/content_schematics/jinja_helpers.yml diff --git a/.metadock/content_schematics/example_project.yml b/.metadock/content_schematics/example_project.yml index 9bc7d3b..e11d35f 100644 --- a/.metadock/content_schematics/example_project.yml +++ b/.metadock/content_schematics/example_project.yml @@ -46,10 +46,6 @@ example_project: content_schematics: gitlab_mr__feature1.yml: | - #... - # yaml anchor definitions - #... - content_schematics: - name: gitlab_mr__feature1 @@ -59,7 +55,8 @@ example_project: context: jira: - <<: *JiraProject-IGDP + project_name: "IGDP" + project_id: "12001" ticket_num: "13" merge_request: @@ -70,8 +67,10 @@ example_project: breaking_changes: - summary: "Dropping all records which are missing software version." affected_downstream: - - *Stakeholder-Service - - *Stakeholder-Analytics + - id: Service + email: service@company.com + - id: Analytics + email: analytics-data@company.com suggested_remedy: | - Drop all records which are missing software version. - Add software version as a hard requirement for staging. diff --git a/.metadock/content_schematics/jinja_helpers.yml b/.metadock/content_schematics/jinja_helpers.yml new file mode 100644 index 0000000..27e7bb1 --- /dev/null +++ b/.metadock/content_schematics/jinja_helpers.yml @@ -0,0 +1,85 @@ +jinja: + + global: + + macros: + + debug: + docstring: Prints a debug message to stdout, and returns an empty string. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render() + This is a debug message. + 'No changes!' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.debug + signature: "(self, message: str) -> None" + + filters: + + chain: + docstring: | + Filter which flattens a sequence of iterables into a single iterable. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render() + 'first 1 second 2' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.chain_filter + signature: "(self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]" + + inline: + docstring: | + Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render() + 'This is a multi-line string. This is the second line. And the third.' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.inline_filter + signature: "(self, value: str) -> str" + + with_prefix: + docstring: | + Filter which prepends a prefix to a string, with an optional separator. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render() + 'PrefixThis is a string.' + >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render() + 'Prefix : This is a string.' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.with_prefix_filter + signature: "(self, value: str, prefix: str, sep: str = '') -> str" + + with_suffix: + docstring: | + Filter which appends a suffix to a string, with an optional separator. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render() + 'This is a stringSuffix' + >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render() + 'This is a string : Suffix' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.with_suffix_filter + signature: "(self, value: str, suffix: str, sep: str = '') -> str" + + zip: + docstring: | + Filter which zips an input iterable with one or more iterables. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render() + "[('a', 1), ('b', 2), ('c', 3)]" + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.zip_filter + signature: "(self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]" + + \ No newline at end of file diff --git a/.metadock/content_schematics/python_interfaces.yml b/.metadock/content_schematics/python_interfaces.yml index 01971cc..e366122 100644 --- a/.metadock/content_schematics/python_interfaces.yml +++ b/.metadock/content_schematics/python_interfaces.yml @@ -3,24 +3,25 @@ python_interfaces: init: source_file: metadock/__init__.py method_name: metadock.Metadock.init - signature: (Path | str) -> metadock.Metadock + signature: "(self, working_directory: Path | str = Path.cwd()) -> metadock.Metadock" validate: source_file: metadock/__init__.py method_name: metadock.Metadock.validate - signature: () -> metadock.engine.MetadockProjectValidationResult + signature: "(self) -> metadock.engine.MetadockProjectValidationResult" build: source_file: metadock/__init__.py method_name: metadock.Metadock.build - signature: (list[str], list[str]) -> metadock.engine.MetadockProjectBuildResult + signature: | + "(self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> metadock.engine.MetadockProjectBuildResult" list: source_file: metadock/__init__.py method_name: metadock.Metadock.list - signature: (list[str], list[str]) -> list[str] + signature: "(self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> list[str]" clean: source_file: metadock/__init__.py method_name: metadock.Metadock.clean - signature: () -> None \ No newline at end of file + signature: (self) -> None \ No newline at end of file diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index b247756..7359939 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -56,7 +56,7 @@

    Basic CLI Usage

  • Python interface:
    • Name: metadock.Metadock.init
    • -
    • Signature: (Path | str) -> metadock.Metadock
    • +
    • Signature: (self, working_directory: Path | str = Path.cwd()) -> metadock.Metadock
  • @@ -71,7 +71,7 @@

    Basic CLI Usage

  • Python interface:
    • Name: metadock.Metadock.validate
    • -
    • Signature: () -> metadock.engine.MetadockProjectValidationResult
    • +
    • Signature: (self) -> metadock.engine.MetadockProjectValidationResult
  • @@ -86,7 +86,7 @@

    Basic CLI Usage

  • Python interface:
    • Name: metadock.Metadock.build
    • -
    • Signature: (list[str], list[str]) -> metadock.engine.MetadockProjectBuildResult
    • +
    • Signature: "(self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> metadock.engine.MetadockProjectBuildResult"
  • @@ -101,7 +101,7 @@

    Basic CLI Usage

  • Python interface:
    • Name: metadock.Metadock.list
    • -
    • Signature: (list[str], list[str]) -> list[str]
    • +
    • Signature: (self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> list[str]
  • @@ -116,7 +116,7 @@

    Basic CLI Usage

  • Python interface:
    • Name: metadock.Metadock.clean
    • -
    • Signature: () -> None
    • +
    • Signature: (self) -> None
  • @@ -151,11 +151,7 @@

    Example Usage

    This is a very simple MR format which can easily be generalized to allow for quickly generating large sets of docs which meet the same format and style requirements. An example content schematic which could service this template could be in gitlab_mr__feature1.yml:

    -
    #...
    -# yaml anchor definitions
    -#...
    -
    -content_schematics:
    +
    content_schematics:
     
     - name: gitlab_mr__feature1
       template: gitlab_mr_template.md
    @@ -164,7 +160,8 @@ 

    Example Usage

    context: jira: - <<: *JiraProject-IGDP + project_name: "IGDP" + project_id: "12001" ticket_num: "13" merge_request: @@ -175,8 +172,10 @@

    Example Usage

    breaking_changes: - summary: "Dropping all records which are missing software version." affected_downstream: - - *Stakeholder-Service - - *Stakeholder-Analytics + - id: Service + email: service@company.com + - id: Analytics + email: analytics-data@company.com suggested_remedy: | - Drop all records which are missing software version. - Add software version as a hard requirement for staging. diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 1f14080..dca259b 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -70,7 +70,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.init
    • -
    • Signature: (Path | str) -> metadock.Metadock
    • +
    • Signature: (self, working_directory: Path | str = Path.cwd()) -> metadock.Metadock
  • @@ -87,7 +87,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.validate
    • -
    • Signature: () -> metadock.engine.MetadockProjectValidationResult
    • +
    • Signature: (self) -> metadock.engine.MetadockProjectValidationResult
  • @@ -104,7 +104,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.build
    • -
    • Signature: (list[str], list[str]) -> metadock.engine.MetadockProjectBuildResult
    • +
    • Signature: "(self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> metadock.engine.MetadockProjectBuildResult"
  • @@ -121,7 +121,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.list
    • -
    • Signature: (list[str], list[str]) -> list[str]
    • +
    • Signature: (self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> list[str]
  • @@ -138,7 +138,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.clean
    • -
    • Signature: () -> None
    • +
    • Signature: (self) -> None
  • @@ -181,10 +181,6 @@ This is a very simple MR format which can easily be generalized to allow for qui meet the same format and style requirements. An example *content schematic* which could service this template could be in `gitlab_mr__feature1.yml`: ```yml -#... -# yaml anchor definitions -#... - content_schematics: - name: gitlab_mr__feature1 @@ -194,7 +190,8 @@ content_schematics: context: jira: - <<: *JiraProject-IGDP + project_name: "IGDP" + project_id: "12001" ticket_num: "13" merge_request: @@ -205,8 +202,10 @@ content_schematics: breaking_changes: - summary: "Dropping all records which are missing software version." affected_downstream: - - *Stakeholder-Service - - *Stakeholder-Analytics + - id: Service + email: service@company.com + - id: Analytics + email: analytics-data@company.com suggested_remedy: | - Drop all records which are missing software version. - Add software version as a hard requirement for staging. diff --git a/README.md b/README.md index 1f14080..dca259b 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.init
    • -
    • Signature: (Path | str) -> metadock.Metadock
    • +
    • Signature: (self, working_directory: Path | str = Path.cwd()) -> metadock.Metadock
  • @@ -87,7 +87,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.validate
    • -
    • Signature: () -> metadock.engine.MetadockProjectValidationResult
    • +
    • Signature: (self) -> metadock.engine.MetadockProjectValidationResult
  • @@ -104,7 +104,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.build
    • -
    • Signature: (list[str], list[str]) -> metadock.engine.MetadockProjectBuildResult
    • +
    • Signature: "(self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> metadock.engine.MetadockProjectBuildResult"
  • @@ -121,7 +121,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.list
    • -
    • Signature: (list[str], list[str]) -> list[str]
    • +
    • Signature: (self, schematic_globs: list[str] = [], template_globs: list[str] = []) -> list[str]
  • @@ -138,7 +138,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad
  • Python interface:
    • Name: metadock.Metadock.clean
    • -
    • Signature: () -> None
    • +
    • Signature: (self) -> None
  • @@ -181,10 +181,6 @@ This is a very simple MR format which can easily be generalized to allow for qui meet the same format and style requirements. An example *content schematic* which could service this template could be in `gitlab_mr__feature1.yml`: ```yml -#... -# yaml anchor definitions -#... - content_schematics: - name: gitlab_mr__feature1 @@ -194,7 +190,8 @@ content_schematics: context: jira: - <<: *JiraProject-IGDP + project_name: "IGDP" + project_id: "12001" ticket_num: "13" merge_request: @@ -205,8 +202,10 @@ content_schematics: breaking_changes: - summary: "Dropping all records which are missing software version." affected_downstream: - - *Stakeholder-Service - - *Stakeholder-Analytics + - id: Service + email: service@company.com + - id: Analytics + email: analytics-data@company.com suggested_remedy: | - Drop all records which are missing software version. - Add software version as a hard requirement for staging. diff --git a/metadock/env.py b/metadock/env.py index dbdb0c5..70af74e 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -324,16 +324,16 @@ def debug(self, message: str) -> Literal[""]: print(message) return "" - def chain_filter(self, values: Sequence[Iterable[Any]]) -> Iterable[Any]: + def chain_filter(self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]: """Filter which flattens a sequence of iterables into a single iterable. Args: - values (Sequence[Iterable[Any]]): Piped input sequence of iterables to be flattened. + iterables (Sequence[Iterable[Any]]): Piped input sequence of iterables to be flattened. Returns: Iterable[Any]: The flattened iterable. """ - return itertools.chain.from_iterable(values) + return itertools.chain.from_iterable(iterables) def inline_filter(self, value: str) -> str: """Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single @@ -348,7 +348,7 @@ def inline_filter(self, value: str) -> str: return value.replace("\n", " ").replace(" ", " ") def with_prefix_filter(self, value: str, prefix: str, sep: str = "") -> str: - """Filter which concatenates a prefix to a string, with an optional separator. + """Filter which prepends a prefix to a string, with an optional separator. Args: value (str): Piped input string to be prefixed. @@ -361,7 +361,7 @@ def with_prefix_filter(self, value: str, prefix: str, sep: str = "") -> str: return sep.join((prefix, value)) def with_suffix_filter(self, value: str, suffix: str, sep: str = "") -> str: - """Filter which concatenates a suffix to a string, with an optional separator. + """Filter which appends a suffix to a string, with an optional separator. Args: value (str): Piped input string to be suffixed. From aa574acf311ff82c2ec02a6de79bee6f60a098c6 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Fri, 24 Nov 2023 20:43:53 -0800 Subject: [PATCH 04/22] some reorg, metadock-generation of snippets --- .gitignore | 2 +- .../{ => documents}/repo_readme.yml | 0 .../vscode_jinja_md_metadock_snippets.yml | 9 +++ .../content_schematics/jinja_helpers.yml | 28 ++++++- .../jinja-md.code-snippets | 79 +++++++++++++++++++ .../vscode_jinja_md_metadock.code-snippets | 31 ++++++++ .vscode/jinja-md.code-snippets | 79 +++++++++++++++++++ 7 files changed, 225 insertions(+), 3 deletions(-) rename .metadock/content_schematics/{ => documents}/repo_readme.yml (100%) create mode 100644 .metadock/content_schematics/documents/vscode_jinja_md_metadock_snippets.yml create mode 100644 .metadock/generated_documents/jinja-md.code-snippets create mode 100644 .metadock/templated_documents/vscode_jinja_md_metadock.code-snippets create mode 100644 .vscode/jinja-md.code-snippets diff --git a/.gitignore b/.gitignore index b408cf4..3c91cf1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ poetry.lock -.vscode/ +.vscode/settings.json **/__pycache__/ .pytest_cache/ .hypothesis/ diff --git a/.metadock/content_schematics/repo_readme.yml b/.metadock/content_schematics/documents/repo_readme.yml similarity index 100% rename from .metadock/content_schematics/repo_readme.yml rename to .metadock/content_schematics/documents/repo_readme.yml diff --git a/.metadock/content_schematics/documents/vscode_jinja_md_metadock_snippets.yml b/.metadock/content_schematics/documents/vscode_jinja_md_metadock_snippets.yml new file mode 100644 index 0000000..efa3795 --- /dev/null +++ b/.metadock/content_schematics/documents/vscode_jinja_md_metadock_snippets.yml @@ -0,0 +1,9 @@ +content_schematics: + + - name: jinja-md + template: vscode_jinja_md_metadock.code-snippets + target_formats: [ code-snippets ] + context: + + # Import jinja helpers context + <<: { import: jinja_helpers.yml } \ No newline at end of file diff --git a/.metadock/content_schematics/jinja_helpers.yml b/.metadock/content_schematics/jinja_helpers.yml index 27e7bb1..14e0a1e 100644 --- a/.metadock/content_schematics/jinja_helpers.yml +++ b/.metadock/content_schematics/jinja_helpers.yml @@ -1,7 +1,7 @@ -jinja: +jinja_helpers: global: - + macros: debug: @@ -15,6 +15,10 @@ jinja: source_file: metadock/env.py method_name: metadock.env.MetadockEnv.debug signature: "(self, message: str) -> None" + intellisense: + snippet_key: Debug message + snippet_body: + - debug($1) filters: @@ -29,6 +33,10 @@ jinja: source_file: metadock/env.py method_name: metadock.env.MetadockEnv.chain_filter signature: "(self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]" + intellisense: + snippet_key: Chain iterables + snippet_body: + - chain inline: docstring: | @@ -41,6 +49,10 @@ jinja: source_file: metadock/env.py method_name: metadock.env.MetadockEnv.inline_filter signature: "(self, value: str) -> str" + intellisense: + snippet_key: Inline text + snippet_body: + - inline with_prefix: docstring: | @@ -55,6 +67,10 @@ jinja: source_file: metadock/env.py method_name: metadock.env.MetadockEnv.with_prefix_filter signature: "(self, value: str, prefix: str, sep: str = '') -> str" + intellisense: + snippet_key: With prefix + snippet_body: + - with_prefix($1) with_suffix: docstring: | @@ -69,6 +85,10 @@ jinja: source_file: metadock/env.py method_name: metadock.env.MetadockEnv.with_suffix_filter signature: "(self, value: str, suffix: str, sep: str = '') -> str" + intellisense: + snippet_key: With suffix + snippet_body: + - with_suffix($1) zip: docstring: | @@ -81,5 +101,9 @@ jinja: source_file: metadock/env.py method_name: metadock.env.MetadockEnv.zip_filter signature: "(self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]" + intellisense: + snippet_key: Zip iterables + snippet_body: + - zip($1) \ No newline at end of file diff --git a/.metadock/generated_documents/jinja-md.code-snippets b/.metadock/generated_documents/jinja-md.code-snippets new file mode 100644 index 0000000..69d321c --- /dev/null +++ b/.metadock/generated_documents/jinja-md.code-snippets @@ -0,0 +1,79 @@ +{ + + // Metadock snippets for macros and filters in global namespace + + + + + "(macro) Debug message": { + "scope": "jinja-md,md", + "prefix": "debug", + "body": [ + "debug($1)" + ], + "description": "Debug message macro" + }, + + + + + + "(filter) Chain iterables": { + "scope": "jinja-md,md", + "prefix": "chain", + "body": [ + "chain" + ], + "description": "Chain iterables filter" + }, + + + + + "(filter) Inline text": { + "scope": "jinja-md,md", + "prefix": "inline", + "body": [ + "inline" + ], + "description": "Inline text filter" + }, + + + + + "(filter) With prefix": { + "scope": "jinja-md,md", + "prefix": "with_prefix", + "body": [ + "with_prefix($1)" + ], + "description": "With prefix filter" + }, + + + + + "(filter) With suffix": { + "scope": "jinja-md,md", + "prefix": "with_suffix", + "body": [ + "with_suffix($1)" + ], + "description": "With suffix filter" + }, + + + + + "(filter) Zip iterables": { + "scope": "jinja-md,md", + "prefix": "zip", + "body": [ + "zip($1)" + ], + "description": "Zip iterables filter" + }, + + +} \ No newline at end of file diff --git a/.metadock/templated_documents/vscode_jinja_md_metadock.code-snippets b/.metadock/templated_documents/vscode_jinja_md_metadock.code-snippets new file mode 100644 index 0000000..1310382 --- /dev/null +++ b/.metadock/templated_documents/vscode_jinja_md_metadock.code-snippets @@ -0,0 +1,31 @@ +{ + {% for ns in jinja_helpers.keys() %} + // Metadock snippets for macros and filters in {{ ns }} namespace + {% for macro_name, macro_spec in jinja_helpers[ns].get("macros", {}).items() %} + {% set macro_prefix_prefix = (ns ~ ".") if ns != "global" else "" %} + {% set intellisense_spec = macro_spec.get("intellisense") %} + {% set snippet_body_lines = intellisense_spec.get("snippet_body", []) | map("with_prefix", '"') | map("with_suffix", '"') %} + "(macro) {{ intellisense_spec.get("snippet_key") }}": { + "scope": "jinja-md,md", + "prefix": "{{ macro_prefix_prefix ~ macro_name }}", + "body": [ + {{ snippet_body_lines | join(",\n") | indent(12) }} + ], + "description": "{{ intellisense_spec.get("snippet_key") }} macro" + }, + {% endfor %} + {% for filter_name, filter_spec in jinja_helpers[ns].get("filters", {}).items() %} + {% set filter_prefix_prefix = (ns ~ ".") if ns != "global" else "" %} + {% set intellisense_spec = filter_spec.get("intellisense") %} + {% set snippet_body_lines = intellisense_spec.get("snippet_body", []) | map("with_prefix", '"') | map("with_suffix", '"') %} + "(filter) {{ intellisense_spec.get("snippet_key") }}": { + "scope": "jinja-md,md", + "prefix": "{{ filter_prefix_prefix ~ filter_name }}", + "body": [ + {{ snippet_body_lines | join(",\n") | indent(12) }} + ], + "description": "{{ intellisense_spec.get("snippet_key") }} filter" + }, + {% endfor %} + {% endfor %} +} \ No newline at end of file diff --git a/.vscode/jinja-md.code-snippets b/.vscode/jinja-md.code-snippets new file mode 100644 index 0000000..69d321c --- /dev/null +++ b/.vscode/jinja-md.code-snippets @@ -0,0 +1,79 @@ +{ + + // Metadock snippets for macros and filters in global namespace + + + + + "(macro) Debug message": { + "scope": "jinja-md,md", + "prefix": "debug", + "body": [ + "debug($1)" + ], + "description": "Debug message macro" + }, + + + + + + "(filter) Chain iterables": { + "scope": "jinja-md,md", + "prefix": "chain", + "body": [ + "chain" + ], + "description": "Chain iterables filter" + }, + + + + + "(filter) Inline text": { + "scope": "jinja-md,md", + "prefix": "inline", + "body": [ + "inline" + ], + "description": "Inline text filter" + }, + + + + + "(filter) With prefix": { + "scope": "jinja-md,md", + "prefix": "with_prefix", + "body": [ + "with_prefix($1)" + ], + "description": "With prefix filter" + }, + + + + + "(filter) With suffix": { + "scope": "jinja-md,md", + "prefix": "with_suffix", + "body": [ + "with_suffix($1)" + ], + "description": "With suffix filter" + }, + + + + + "(filter) Zip iterables": { + "scope": "jinja-md,md", + "prefix": "zip", + "body": [ + "zip($1)" + ], + "description": "Zip iterables filter" + }, + + +} \ No newline at end of file From 1e3a9d2313f49dd8f55ede5ad56e55f481482ae5 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Fri, 24 Nov 2023 22:42:50 -0800 Subject: [PATCH 05/22] fixing precommit --- .../content_schematics/jinja_helpers.yml | 111 +----------------- .../jinja_helpers/global.yml | 105 +++++++++++++++++ .../jinja-md.code-snippets | 25 ---- .metadock/metadock-build-docs.sh | 20 ++++ .../vscode_jinja_md_metadock.code-snippets | 22 ++-- .pre-commit-config.yaml | 4 +- .vscode/jinja-md.code-snippets | 25 ---- 7 files changed, 143 insertions(+), 169 deletions(-) create mode 100644 .metadock/content_schematics/jinja_helpers/global.yml create mode 100644 .metadock/metadock-build-docs.sh diff --git a/.metadock/content_schematics/jinja_helpers.yml b/.metadock/content_schematics/jinja_helpers.yml index 14e0a1e..30d1911 100644 --- a/.metadock/content_schematics/jinja_helpers.yml +++ b/.metadock/content_schematics/jinja_helpers.yml @@ -1,109 +1,8 @@ jinja_helpers: - global: - - macros: - - debug: - docstring: Prints a debug message to stdout, and returns an empty string. - example: | - >>> from metadock.env import MetadockEnv - >>> env = MetadockEnv().jinja_environment() - >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render() - This is a debug message. - 'No changes!' - source_file: metadock/env.py - method_name: metadock.env.MetadockEnv.debug - signature: "(self, message: str) -> None" - intellisense: - snippet_key: Debug message - snippet_body: - - debug($1) - - filters: - - chain: - docstring: | - Filter which flattens a sequence of iterables into a single iterable. - example: | - >>> from metadock.env import MetadockEnv - >>> env = MetadockEnv().jinja_environment() - >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render() - 'first 1 second 2' - source_file: metadock/env.py - method_name: metadock.env.MetadockEnv.chain_filter - signature: "(self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]" - intellisense: - snippet_key: Chain iterables - snippet_body: - - chain - - inline: - docstring: | - Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces. - example: | - >>> from metadock.env import MetadockEnv - >>> env = MetadockEnv().jinja_environment() - >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render() - 'This is a multi-line string. This is the second line. And the third.' - source_file: metadock/env.py - method_name: metadock.env.MetadockEnv.inline_filter - signature: "(self, value: str) -> str" - intellisense: - snippet_key: Inline text - snippet_body: - - inline - - with_prefix: - docstring: | - Filter which prepends a prefix to a string, with an optional separator. - example: | - >>> from metadock.env import MetadockEnv - >>> env = MetadockEnv().jinja_environment() - >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render() - 'PrefixThis is a string.' - >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render() - 'Prefix : This is a string.' - source_file: metadock/env.py - method_name: metadock.env.MetadockEnv.with_prefix_filter - signature: "(self, value: str, prefix: str, sep: str = '') -> str" - intellisense: - snippet_key: With prefix - snippet_body: - - with_prefix($1) - - with_suffix: - docstring: | - Filter which appends a suffix to a string, with an optional separator. - example: | - >>> from metadock.env import MetadockEnv - >>> env = MetadockEnv().jinja_environment() - >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render() - 'This is a stringSuffix' - >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render() - 'This is a string : Suffix' - source_file: metadock/env.py - method_name: metadock.env.MetadockEnv.with_suffix_filter - signature: "(self, value: str, suffix: str, sep: str = '') -> str" - intellisense: - snippet_key: With suffix - snippet_body: - - with_suffix($1) - - zip: - docstring: | - Filter which zips an input iterable with one or more iterables. - example: | - >>> from metadock.env import MetadockEnv - >>> env = MetadockEnv().jinja_environment() - >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render() - "[('a', 1), ('b', 2), ('c', 3)]" - source_file: metadock/env.py - method_name: metadock.env.MetadockEnv.zip_filter - signature: "(self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]" - intellisense: - snippet_key: Zip iterables - snippet_body: - - zip($1) - + <<: + # Import global macros, filters context + - import: jinja_helpers/global.yml + # TODO: import markdown macros, filters context + # TODO: import html macros, filters context \ No newline at end of file diff --git a/.metadock/content_schematics/jinja_helpers/global.yml b/.metadock/content_schematics/jinja_helpers/global.yml new file mode 100644 index 0000000..4af6e03 --- /dev/null +++ b/.metadock/content_schematics/jinja_helpers/global.yml @@ -0,0 +1,105 @@ +global: + + macros: + + debug: + docstring: Prints a debug message to stdout, and returns an empty string. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render() + This is a debug message. + 'No changes!' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.debug + signature: "(self, message: str) -> None" + intellisense: + snippet_key: Debug message + snippet_body: + - debug($1) + + filters: + + chain: + docstring: | + Filter which flattens a sequence of iterables into a single iterable. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render() + 'first 1 second 2' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.chain_filter + signature: "(self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]" + intellisense: + snippet_key: Chain iterables + snippet_body: + - chain + + inline: + docstring: | + Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render() + 'This is a multi-line string. This is the second line. And the third.' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.inline_filter + signature: "(self, value: str) -> str" + intellisense: + snippet_key: Inline text + snippet_body: + - inline + + with_prefix: + docstring: | + Filter which prepends a prefix to a string, with an optional separator. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render() + 'PrefixThis is a string.' + >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render() + 'Prefix : This is a string.' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.with_prefix_filter + signature: "(self, value: str, prefix: str, sep: str = '') -> str" + intellisense: + snippet_key: With prefix + snippet_body: + - with_prefix($1) + + with_suffix: + docstring: | + Filter which appends a suffix to a string, with an optional separator. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render() + 'This is a stringSuffix' + >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render() + 'This is a string : Suffix' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.with_suffix_filter + signature: "(self, value: str, suffix: str, sep: str = '') -> str" + intellisense: + snippet_key: With suffix + snippet_body: + - with_suffix($1) + + zip: + docstring: | + Filter which zips an input iterable with one or more iterables. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render() + "[('a', 1), ('b', 2), ('c', 3)]" + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.zip_filter + signature: "(self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]" + intellisense: + snippet_key: Zip iterables + snippet_body: + - zip($1) \ No newline at end of file diff --git a/.metadock/generated_documents/jinja-md.code-snippets b/.metadock/generated_documents/jinja-md.code-snippets index 69d321c..5898260 100644 --- a/.metadock/generated_documents/jinja-md.code-snippets +++ b/.metadock/generated_documents/jinja-md.code-snippets @@ -2,9 +2,6 @@ // Metadock snippets for macros and filters in global namespace - - - "(macro) Debug message": { "scope": "jinja-md,md", "prefix": "debug", @@ -13,11 +10,6 @@ ], "description": "Debug message macro" }, - - - - - "(filter) Chain iterables": { "scope": "jinja-md,md", "prefix": "chain", @@ -26,10 +18,6 @@ ], "description": "Chain iterables filter" }, - - - - "(filter) Inline text": { "scope": "jinja-md,md", "prefix": "inline", @@ -38,10 +26,6 @@ ], "description": "Inline text filter" }, - - - - "(filter) With prefix": { "scope": "jinja-md,md", "prefix": "with_prefix", @@ -50,10 +34,6 @@ ], "description": "With prefix filter" }, - - - - "(filter) With suffix": { "scope": "jinja-md,md", "prefix": "with_suffix", @@ -62,10 +42,6 @@ ], "description": "With suffix filter" }, - - - - "(filter) Zip iterables": { "scope": "jinja-md,md", "prefix": "zip", @@ -75,5 +51,4 @@ "description": "Zip iterables filter" }, - } \ No newline at end of file diff --git a/.metadock/metadock-build-docs.sh b/.metadock/metadock-build-docs.sh new file mode 100644 index 0000000..bf95620 --- /dev/null +++ b/.metadock/metadock-build-docs.sh @@ -0,0 +1,20 @@ +# install poetry project + +echo "Installing poetry project..." +poetry install + +# metadock build README + +echo "Metadock-building README.md..." +poetry run metadock build -s README +cp .metadock/generated_documents/README.md README.md + +# metadock build Intellisense snippets + +echo "Metadock-building Intellisense snippets..." +poetry run metadock build -s jinja-md +cp .metadock/generated_documents/jinja-md.code-snippets .vscode/jinja-md.code-snippets + +# capture all changes + +git add -A \ No newline at end of file diff --git a/.metadock/templated_documents/vscode_jinja_md_metadock.code-snippets b/.metadock/templated_documents/vscode_jinja_md_metadock.code-snippets index 1310382..1f06bb5 100644 --- a/.metadock/templated_documents/vscode_jinja_md_metadock.code-snippets +++ b/.metadock/templated_documents/vscode_jinja_md_metadock.code-snippets @@ -1,10 +1,10 @@ { {% for ns in jinja_helpers.keys() %} // Metadock snippets for macros and filters in {{ ns }} namespace - {% for macro_name, macro_spec in jinja_helpers[ns].get("macros", {}).items() %} - {% set macro_prefix_prefix = (ns ~ ".") if ns != "global" else "" %} - {% set intellisense_spec = macro_spec.get("intellisense") %} - {% set snippet_body_lines = intellisense_spec.get("snippet_body", []) | map("with_prefix", '"') | map("with_suffix", '"') %} + {% for macro_name, macro_spec in jinja_helpers[ns].get("macros", {}).items() -%} + {%- set macro_prefix_prefix = (ns ~ ".") if ns != "global" else "" -%} + {%- set intellisense_spec = macro_spec.get("intellisense") -%} + {%- set snippet_body_lines = intellisense_spec.get("snippet_body", []) | map("with_prefix", '"') | map("with_suffix", '"') %} "(macro) {{ intellisense_spec.get("snippet_key") }}": { "scope": "jinja-md,md", "prefix": "{{ macro_prefix_prefix ~ macro_name }}", @@ -13,11 +13,11 @@ ], "description": "{{ intellisense_spec.get("snippet_key") }} macro" }, - {% endfor %} - {% for filter_name, filter_spec in jinja_helpers[ns].get("filters", {}).items() %} - {% set filter_prefix_prefix = (ns ~ ".") if ns != "global" else "" %} - {% set intellisense_spec = filter_spec.get("intellisense") %} - {% set snippet_body_lines = intellisense_spec.get("snippet_body", []) | map("with_prefix", '"') | map("with_suffix", '"') %} + {% endfor -%} + {%- for filter_name, filter_spec in jinja_helpers[ns].get("filters", {}).items() -%} + {%- set filter_prefix_prefix = (ns ~ ".") if ns != "global" else "" -%} + {%- set intellisense_spec = filter_spec.get("intellisense") -%} + {%- set snippet_body_lines = intellisense_spec.get("snippet_body", []) | map("with_prefix", '"') | map("with_suffix", '"') -%} "(filter) {{ intellisense_spec.get("snippet_key") }}": { "scope": "jinja-md,md", "prefix": "{{ filter_prefix_prefix ~ filter_name }}", @@ -26,6 +26,6 @@ ], "description": "{{ intellisense_spec.get("snippet_key") }} filter" }, - {% endfor %} - {% endfor %} + {% endfor -%} + {%- endfor %} } \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 73dd116..0be73a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - repo: local hooks: - - id: metadock-build-README + - id: metadock-build name: Metadock-build README - entry: bash -c './.git/hooks/pre-commit || true' + entry: bash .metadock/metadock-build-docs.sh language: system \ No newline at end of file diff --git a/.vscode/jinja-md.code-snippets b/.vscode/jinja-md.code-snippets index 69d321c..5898260 100644 --- a/.vscode/jinja-md.code-snippets +++ b/.vscode/jinja-md.code-snippets @@ -2,9 +2,6 @@ // Metadock snippets for macros and filters in global namespace - - - "(macro) Debug message": { "scope": "jinja-md,md", "prefix": "debug", @@ -13,11 +10,6 @@ ], "description": "Debug message macro" }, - - - - - "(filter) Chain iterables": { "scope": "jinja-md,md", "prefix": "chain", @@ -26,10 +18,6 @@ ], "description": "Chain iterables filter" }, - - - - "(filter) Inline text": { "scope": "jinja-md,md", "prefix": "inline", @@ -38,10 +26,6 @@ ], "description": "Inline text filter" }, - - - - "(filter) With prefix": { "scope": "jinja-md,md", "prefix": "with_prefix", @@ -50,10 +34,6 @@ ], "description": "With prefix filter" }, - - - - "(filter) With suffix": { "scope": "jinja-md,md", "prefix": "with_suffix", @@ -62,10 +42,6 @@ ], "description": "With suffix filter" }, - - - - "(filter) Zip iterables": { "scope": "jinja-md,md", "prefix": "zip", @@ -75,5 +51,4 @@ "description": "Zip iterables filter" }, - } \ No newline at end of file From 181dcaf6d88d36882905713b30afe83bd0aa6ab4 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 10:03:57 -0800 Subject: [PATCH 06/22] starting the process of adding jinja docs to readme using metadock --- .../documents/repo_readme.yml | 10 +- .../content_schematics/jinja_helpers.yml | 2 + .../jinja_helpers/global.yml | 20 +-- .../content_schematics/jinja_helpers/html.yml | 92 +++++++++++ .../content_schematics/jinja_helpers/md.yml | 4 + .metadock/generated_documents/README.html | 145 ++++++++++++++++++ .metadock/generated_documents/README.md | 97 ++++++++++++ .../jinja-md.code-snippets | 49 ++++++ .../repo_readme_template.md | 48 ++++++ metadock/env.py | 56 +++++-- metadock/target_formats.py | 3 +- metadock/yaml_utils.py | 3 + 12 files changed, 498 insertions(+), 31 deletions(-) create mode 100644 .metadock/content_schematics/jinja_helpers/html.yml create mode 100644 .metadock/content_schematics/jinja_helpers/md.yml diff --git a/.metadock/content_schematics/documents/repo_readme.yml b/.metadock/content_schematics/documents/repo_readme.yml index 4199c04..d4fa749 100644 --- a/.metadock/content_schematics/documents/repo_readme.yml +++ b/.metadock/content_schematics/documents/repo_readme.yml @@ -1,20 +1,20 @@ content_schematics: - - name: README template: repo_readme_template.md - target_formats: [ md+html, md ] + target_formats: [md+html, md] context: - # Hyperlinks in readme links: Jinja2: "[Jinja2](https://github.com/pallets/jinja)" marko: "[marko](https://github.com/frostming/marko)" - <<: + <<: # Import example project configuration - import: example_project.yml # Import CLI information - import: cli.yml + # Import Jinja2 helpers + - import: jinja_helpers.yml # Target formats target_formats: @@ -23,4 +23,4 @@ content_schematics: # Project author(s) authors: - - David Sillman \ No newline at end of file + - David Sillman diff --git a/.metadock/content_schematics/jinja_helpers.yml b/.metadock/content_schematics/jinja_helpers.yml index 30d1911..4a73b86 100644 --- a/.metadock/content_schematics/jinja_helpers.yml +++ b/.metadock/content_schematics/jinja_helpers.yml @@ -4,5 +4,7 @@ jinja_helpers: # Import global macros, filters context - import: jinja_helpers/global.yml # TODO: import markdown macros, filters context + - import: jinja_helpers/md.yml # TODO: import html macros, filters context + - import: jinja_helpers/html.yml \ No newline at end of file diff --git a/.metadock/content_schematics/jinja_helpers/global.yml b/.metadock/content_schematics/jinja_helpers/global.yml index 4af6e03..dcf5aeb 100644 --- a/.metadock/content_schematics/jinja_helpers/global.yml +++ b/.metadock/content_schematics/jinja_helpers/global.yml @@ -1,7 +1,10 @@ global: + info: | + The global namespace contains helpful macros and filters for manipulating data in the Jinja + context. It also provides access to more specific namespaces through their respective identifiers, + such as `md` and `html`. macros: - debug: docstring: Prints a debug message to stdout, and returns an empty string. example: | @@ -15,11 +18,10 @@ global: signature: "(self, message: str) -> None" intellisense: snippet_key: Debug message - snippet_body: + snippet_body: - debug($1) filters: - chain: docstring: | Filter which flattens a sequence of iterables into a single iterable. @@ -33,7 +35,7 @@ global: signature: "(self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]" intellisense: snippet_key: Chain iterables - snippet_body: + snippet_body: - chain inline: @@ -49,7 +51,7 @@ global: signature: "(self, value: str) -> str" intellisense: snippet_key: Inline text - snippet_body: + snippet_body: - inline with_prefix: @@ -67,7 +69,7 @@ global: signature: "(self, value: str, prefix: str, sep: str = '') -> str" intellisense: snippet_key: With prefix - snippet_body: + snippet_body: - with_prefix($1) with_suffix: @@ -85,7 +87,7 @@ global: signature: "(self, value: str, suffix: str, sep: str = '') -> str" intellisense: snippet_key: With suffix - snippet_body: + snippet_body: - with_suffix($1) zip: @@ -101,5 +103,5 @@ global: signature: "(self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]" intellisense: snippet_key: Zip iterables - snippet_body: - - zip($1) \ No newline at end of file + snippet_body: + - zip($1) diff --git a/.metadock/content_schematics/jinja_helpers/html.yml b/.metadock/content_schematics/jinja_helpers/html.yml new file mode 100644 index 0000000..cccd219 --- /dev/null +++ b/.metadock/content_schematics/jinja_helpers/html.yml @@ -0,0 +1,92 @@ +html: + macros: + bold: + docstring: | + Wraps a string in HTML bold tags (). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ html.bold('This is bold text.') }}").render() + 'This is bold text.' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.bold + signature: "(self, content: str) -> str" + intellisense: + snippet_key: HTML bold + snippet_body: + - html.bold($1) + + code: + docstring: | + Wraps a string in HTML code tags (). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ html.code('This is code text.') }}").render() + 'This is code text.' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.code + signature: "(self, content: str) -> str" + intellisense: + snippet_key: HTML code + snippet_body: + - html.code($1) + + codeblock: + docstring: | + Wraps a string in preformatted HTML code tags (
    ), and indents the content by the + given amount. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render() + '
        This is code text.
    ' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.codeblock + signature: "(self, content: str, indent: int = 0) -> str" + intellisense: + snippet_key: HTML codeblock + snippet_body: + - html.codeblock($1) + + details: + docstring: | + Wraps a string in HTML details tags (
    ). Multiple arguments get separated by two line + breaks. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ html.details('This is details text.') }}").render() + '
    \nThis is details text.\n
    ' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.details + signature: "(self, *contents: str) -> str" + intellisense: + snippet_key: HTML details + snippet_body: + - html.details($1) + + italic: + docstring: | + Wraps a string in HTML italic tags (). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ html.italic('This is italic text.') }}").render() + 'This is italic text.' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.italic + signature: "(self, content: str) -> str" + intellisense: + snippet_key: HTML italic + snippet_body: + - html.italic($1) + + summary: + docstring: | + Wraps a string in HTML summary tags (). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ html.summary('This is summary text.') }}").render() + 'This is summary text.' diff --git a/.metadock/content_schematics/jinja_helpers/md.yml b/.metadock/content_schematics/jinja_helpers/md.yml new file mode 100644 index 0000000..16a0c7c --- /dev/null +++ b/.metadock/content_schematics/jinja_helpers/md.yml @@ -0,0 +1,4 @@ +md: + macros: {} + + filters: {} diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 7359939..4ef0179 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -244,6 +244,151 @@

    [IGDP-13] Adding software version as hard requirement for staging

    +

    Jinja Templating Helpers

    +

    In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros +and filters which can be used to make formatting content easier. The macros and filters are segregated into +3 namespaces, documented below:

    +

    Global namespace

    +

    The global namespace contains helpful macros and filters for manipulating data in the Jinja +context. It also provides access to more specific namespaces through their respective identifiers, +such as md and html.

    +
    + +Jinja macro reference + + + + + + + + + + + + + + + +
    MacroSignatureDoc
    debugmetadock.env.MetadockEnv.debug: (self, message: str) -> NonePrints a debug message to stdout, and returns an empty string.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
    This is a debug message.
    'No changes!'

    +
    + +Jinja filter reference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    FilterSignatureDoc
    chainmetadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]Filter which flattens a sequence of iterables into a single iterable.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
    'first 1 second 2'

    inlinemetadock.env.MetadockEnv.inline_filter: (self, value: str) -> strFilter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
    'This is a multi-line string. This is the second line. And the third.'

    with_prefixmetadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> strFilter which prepends a prefix to a string, with an optional separator.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
    'PrefixThis is a string.'
    >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
    'Prefix : This is a string.'

    with_suffixmetadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> strFilter which appends a suffix to a string, with an optional separator.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
    'This is a stringSuffix'
    >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
    'This is a string : Suffix'

    zipmetadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]Filter which zips an input iterable with one or more iterables.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
    "[('a', 1), ('b', 2), ('c', 3)]"

    +

    md namespace

    +

    None

    +
    + +Jinja macro reference + + + + + + + + +
    MacroSignatureDoc
    +
    + +Jinja filter reference + + + + + + + + +
    FilterSignatureDoc
    +

    html namespace

    +

    None

    +
    + +Jinja macro reference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    MacroSignatureDoc
    html.boldmetadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> strWraps a string in HTML bold tags (<b></b>).
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
    '<b>This is bold text.</b>'

    html.codemetadock.env.MetadockHtmlNamespace.code: (self, content: str) -> strWraps a string in HTML code tags (<code></code>).
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ html.code('This is code text.') }}").render()
    '<code>This is code text.</code>'

    html.codeblockmetadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> strWraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
    '<pre><code> This is code text.</code></pre>'

    html.detailsmetadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> strWraps a string in HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ html.details('This is details text.') }}").render()
    '<details>\nThis is details text.\n</details>'

    html.italicmetadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> strWraps a string in HTML italic tags (<i></i>).
    >>> from metadock.env import MetadockEnv
    >>> env = MetadockEnv().jinja_environment()
    >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
    '<i>This is italic text.</i>'

    +
    + +Jinja filter reference + + + + + + + + +
    FilterSignatureDoc

    Acknowledgements

    Author:

      diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index dca259b..7159b4e 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -269,6 +269,103 @@ The natively supported values for `target_formats` are: - Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or `.py`. +## Jinja Templating Helpers + +In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros +and filters which can be used to make formatting content easier. The macros and filters are segregated into +3 namespaces, documented below: + +### Global namespace + +The global namespace contains helpful macros and filters for manipulating data in the Jinja +context. It also provides access to more specific namespaces through their respective identifiers, +such as `md` and `html`. + + + +
      + +Jinja macro reference + + +| Macro | Signature | Doc | +| --- | --- | --- | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | + +
      + +
      + +Jinja filter reference + + +| Filter | Signature | Doc | +| --- | --- | --- | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | + +
      + +### `md` namespace + +None + + +
      + +Jinja macro reference + + +| Macro | Signature | Doc | +| --- | --- | --- | + +
      + +
      + +Jinja filter reference + + +| Filter | Signature | Doc | +| --- | --- | --- | + +
      + +### `html` namespace + +None + + +
      + +Jinja macro reference + + +| Macro | Signature | Doc | +| --- | --- | --- | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | + +
      + +
      + +Jinja filter reference + + +| Filter | Signature | Doc | +| --- | --- | --- | + +
      + + + ## Acknowledgements Author: diff --git a/.metadock/generated_documents/jinja-md.code-snippets b/.metadock/generated_documents/jinja-md.code-snippets index 5898260..7ee818d 100644 --- a/.metadock/generated_documents/jinja-md.code-snippets +++ b/.metadock/generated_documents/jinja-md.code-snippets @@ -51,4 +51,53 @@ "description": "Zip iterables filter" }, + // Metadock snippets for macros and filters in md namespace + + // Metadock snippets for macros and filters in html namespace + + "(macro) HTML bold": { + "scope": "jinja-md,md", + "prefix": "html.bold", + "body": [ + "html.bold($1)" + ], + "description": "HTML bold macro" + }, + + "(macro) HTML code": { + "scope": "jinja-md,md", + "prefix": "html.code", + "body": [ + "html.code($1)" + ], + "description": "HTML code macro" + }, + + "(macro) HTML codeblock": { + "scope": "jinja-md,md", + "prefix": "html.codeblock", + "body": [ + "html.codeblock($1)" + ], + "description": "HTML codeblock macro" + }, + + "(macro) HTML details": { + "scope": "jinja-md,md", + "prefix": "html.details", + "body": [ + "html.details($1)" + ], + "description": "HTML details macro" + }, + + "(macro) HTML italic": { + "scope": "jinja-md,md", + "prefix": "html.italic", + "body": [ + "html.italic($1)" + ], + "description": "HTML italic macro" + }, + } \ No newline at end of file diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index 8c1bebf..95f21b1 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -88,6 +88,54 @@ The natively supported values for `target_formats` are: - Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or `.py`. +## Jinja Templating Helpers + +In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros +and filters which can be used to make formatting content easier. The macros and filters are segregated into +{{ jinja_helpers.keys() | length }} namespaces, documented below: + +{% for namespace, namespace_spec in jinja_helpers.items() -%} +{%- set namespace_title_prefix = "Global" if namespace == "global" else md.code(namespace) -%} +{%- set ns_code_prefix = (namespace ~ ".") if namespace != "global" else "" -%} +{%- set namespace_intro -%} +### {{ namespace_title_prefix }} namespace + +{{ namespace_spec.get("info") }} +{% endset -%} +{%- set ns_macro_table -%} +{{ md.tablehead("Macro", "Signature", "Doc", bold=true) }} +{% for macro, macro_spec in namespace_spec.get("macros", {}).items() -%} +{{ + md.tablerow( + html.code(ns_code_prefix ~ macro), + html.code(macro_spec.get("method_name") ~ ": " ~ macro_spec.get("signature")), + (macro_spec.get("docstring") | inline | html.escape) ~ "
      " ~ (md.codeblock(macro_spec.get("example"), language="py") + | md.convert | html.inline), + ) +}} +{% endfor -%} +{%- endset -%} +{%- set ns_filter_table -%} +{{ md.tablehead("Filter", "Signature", "Doc", bold=true) }} +{% for filter, filter_spec in namespace_spec.get("filters", {}).items() -%} +{{ + md.tablerow( + html.code(ns_code_prefix ~ filter), + html.code(filter_spec.get("method_name") ~ ": " ~ filter_spec.get("signature")), + (filter_spec.get("docstring") | inline | html.escape) ~ "
      " ~ (md.codeblock(filter_spec.get("example"), language="py") + | md.convert | html.inline), + ) +}} +{% endfor -%} +{%- endset -%} +{{ namespace_intro }} + +{{ html.details(html.summary("Jinja macro reference"), ns_macro_table) }} + +{{ html.details(html.summary("Jinja filter reference"), ns_filter_table) }} + +{% endfor %} + ## Acknowledgements Author{% if (authors | length) > 1 %}s{% endif %}: diff --git a/metadock/env.py b/metadock/env.py index 70af74e..7d118a9 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -1,4 +1,5 @@ import abc +import html import itertools from typing import Annotated, Any, Iterable, Literal, Sequence @@ -129,7 +130,8 @@ def tablerow(self, *cells: str) -> str: Returns: str: The Markdown table row. """ - return "| " + " | ".join(cells) + " |" + _pipe_escaped_cells = tuple(map(lambda cell: cell.replace("|", "\\|"), cells)) + return "| " + " | ".join(_pipe_escaped_cells) + " |" def tablehead(self, *header_cells: str, bold: bool = False) -> str: """Produces a Markdown table header row from the given header cells. @@ -141,9 +143,10 @@ def tablehead(self, *header_cells: str, bold: bool = False) -> str: Returns: str: The Markdown table header row. """ + _pipe_escaped_cells = tuple(map(lambda cell: cell.replace("|", "\\|"), header_cells)) if bold: - header_cells = tuple(MetadockHtmlNamespace().bold(cell) for cell in header_cells) - return self.tablerow(*header_cells) + "\n" + self.tablerow(*(["---"] * len(header_cells))) + _pipe_escaped_cells = tuple(MetadockHtmlNamespace().bold(cell) for cell in _pipe_escaped_cells) + return self.tablerow(*_pipe_escaped_cells) + "\n" + self.tablerow(*(["---"] * len(_pipe_escaped_cells))) def list(self, *items: str) -> str: """Produces a Markdown list from the given items, even when those items themselves may be formatted as Markdown @@ -208,6 +211,7 @@ class MetadockHtmlNamespace(MetadockNamespace): """ exports = ["bold", "code", "codeblock", "details", "italic", "summary", "underline"] + filters = ["escape", "inline"] def bold(self, content: str) -> str: """Wraps a string in HTML bold tags (). @@ -232,8 +236,8 @@ def code(self, content: str) -> str: return f"{content}" def codeblock(self, content: str, indent: int = 0) -> str: - """Wraps a string in line-broken HTML code tags (\\n\\n), and indents the content by the given - amount. + """Wraps a string in preformatted HTML code tags (
      ), and indents the content by the + given amount. Args: content (str): The content to be formatted as code. @@ -242,21 +246,21 @@ def codeblock(self, content: str, indent: int = 0) -> str: Returns: str: The HTML code block content. """ - indented_content = content.replace("\n", "\n" + " " * indent) - return f"\n{indented_content}\n" + indented_content = " " * indent + content.replace("\n", "\n" + " " * indent) + return f"
      {indented_content}
      " - def details(self, *contents: str, indent: int = 0) -> str: - """Wraps a string in HTML details tags (
      ), and indents the content by the given amount. + def details(self, *contents: str) -> str: + """Wraps a string in HTML details tags (
      ). Multiple arguments get separated by two line + breaks. Args: *contents (str): The content to be wrapped in details tags. Multiple arguments get separated by two line breaks. - indent (int, optional): Number of spaces which should be used to indent the contents. Defaults to 0. Returns: str: The HTML details content. """ - indented_linesep_contents = "\n\n".join(contents).replace("\n", "\n" + " " * indent) + indented_linesep_contents = "\n\n".join(contents).replace("\n", "\n") return f"
      \n{indented_linesep_contents}\n
      " def italic(self, content: str) -> str: @@ -270,18 +274,16 @@ def italic(self, content: str) -> str: """ return f"{content}" - def summary(self, content: str, indent: int = 0) -> str: - """Wraps a string in HTML summary tags (), and indents the content by the given amount. + def summary(self, content: str) -> str: + """Wraps a string in HTML summary tags (). Args: content (str): The content to be wrapped in summary tags. - indent (int, optional): Number of spaces to use when indenting the content. Defaults to 0. Returns: str: The HTML summary content. """ - indented_content = content.replace("\n", "\n" + " " * indent) - return f"\n{indented_content}\n" + return f"\n{content}\n" def underline(self, content: str) -> str: """Wraps a string in HTML underline tags (). @@ -294,6 +296,28 @@ def underline(self, content: str) -> str: """ return f"{content}" + def escape_filter(self, content: str) -> str: + """Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents. + + Args: + content (str): Piped input string to be HTML-escaped. + + Returns: + str: The escaped string. + """ + return html.escape(content) + + def inline_filter(self, content: str) -> str: + """Filter which inlines a string by replacing all newlines with HTML line-break
      singleton tags. + + Args: + content (str): Piped input string to be HTML-inlined. + + Returns: + str: The HTML-inlined string. + """ + return content.replace("\n", "
      ") + class MetadockEnv(MetadockNamespace): """Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. diff --git a/metadock/target_formats.py b/metadock/target_formats.py index bcb9cbb..29d3996 100644 --- a/metadock/target_formats.py +++ b/metadock/target_formats.py @@ -2,6 +2,7 @@ from typing import MutableMapping, Protocol, Type import marko +from marko.ext.gfm import gfm from metadock import exceptions @@ -110,4 +111,4 @@ def handler(cls, rendered_document: str | bytes) -> str | bytes: Returns: str | bytes: HTML markup of the original Markdown document """ - return marko.convert(str(rendered_document)) + return gfm.convert(str(rendered_document)) diff --git a/metadock/yaml_utils.py b/metadock/yaml_utils.py index 26637b7..7bd4cdc 100644 --- a/metadock/yaml_utils.py +++ b/metadock/yaml_utils.py @@ -17,6 +17,9 @@ def flatten_merge_keys(yaml_dict: Any) -> dict: Returns: dict: Flattened representation of the nested dictionary object """ + if isinstance(yaml_dict, list): + return [flatten_merge_keys(el) for el in yaml_dict] + if not isinstance(yaml_dict, dict): return yaml_dict # type: ignore From e39ec8830a1178210f73ff8f0bfc130d108c28e1 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 10:06:24 -0800 Subject: [PATCH 07/22] completing html.summary jinja helper metadock --- .../content_schematics/jinja_helpers/html.yml | 15 +++++++++++---- .metadock/generated_documents/README.html | 7 ++++++- .metadock/generated_documents/README.md | 3 ++- .../generated_documents/jinja-md.code-snippets | 9 +++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/.metadock/content_schematics/jinja_helpers/html.yml b/.metadock/content_schematics/jinja_helpers/html.yml index cccd219..46ac1e4 100644 --- a/.metadock/content_schematics/jinja_helpers/html.yml +++ b/.metadock/content_schematics/jinja_helpers/html.yml @@ -51,8 +51,8 @@ html: details: docstring: | - Wraps a string in HTML details tags (
      ). Multiple arguments get separated by two line - breaks. + Wraps a string in line-broken HTML details tags (
      ). Multiple arguments get separated by two + line breaks. example: | >>> from metadock.env import MetadockEnv >>> env = MetadockEnv().jinja_environment() @@ -84,9 +84,16 @@ html: summary: docstring: | - Wraps a string in HTML summary tags (). + Wraps a string in line-broken HTML summary tags (\n\n). example: | >>> from metadock.env import MetadockEnv >>> env = MetadockEnv().jinja_environment() >>> env.from_string("{{ html.summary('This is summary text.') }}").render() - 'This is summary text.' + '\nThis is summary text.\n' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.summary + signature: "(self, content: str) -> str" + intellisense: + snippet_key: HTML summary + snippet_body: + - html.summary($1) diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 4ef0179..9213a91 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -369,13 +369,18 @@

      html namespace

      html.details metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str -Wraps a string in HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      +Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      html.italic metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str Wraps a string in HTML italic tags (<i></i>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      + +html.summary +metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str +Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      +
      diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 7159b4e..339741c 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -349,8 +349,9 @@ Jinja macro reference | html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | | html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | | html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | | html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      |
      diff --git a/.metadock/generated_documents/jinja-md.code-snippets b/.metadock/generated_documents/jinja-md.code-snippets index 7ee818d..1a30c26 100644 --- a/.metadock/generated_documents/jinja-md.code-snippets +++ b/.metadock/generated_documents/jinja-md.code-snippets @@ -100,4 +100,13 @@ "description": "HTML italic macro" }, + "(macro) HTML summary": { + "scope": "jinja-md,md", + "prefix": "html.summary", + "body": [ + "html.summary($1)" + ], + "description": "HTML summary macro" + }, + } \ No newline at end of file From 4519b03722c4a58e372609d57107e7944df3c282 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 10:07:56 -0800 Subject: [PATCH 08/22] fixing pre-commit install --- .vscode/jinja-md.code-snippets | 58 ++++++++++++++++++++ README.md | 98 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/.vscode/jinja-md.code-snippets b/.vscode/jinja-md.code-snippets index 5898260..1a30c26 100644 --- a/.vscode/jinja-md.code-snippets +++ b/.vscode/jinja-md.code-snippets @@ -51,4 +51,62 @@ "description": "Zip iterables filter" }, + // Metadock snippets for macros and filters in md namespace + + // Metadock snippets for macros and filters in html namespace + + "(macro) HTML bold": { + "scope": "jinja-md,md", + "prefix": "html.bold", + "body": [ + "html.bold($1)" + ], + "description": "HTML bold macro" + }, + + "(macro) HTML code": { + "scope": "jinja-md,md", + "prefix": "html.code", + "body": [ + "html.code($1)" + ], + "description": "HTML code macro" + }, + + "(macro) HTML codeblock": { + "scope": "jinja-md,md", + "prefix": "html.codeblock", + "body": [ + "html.codeblock($1)" + ], + "description": "HTML codeblock macro" + }, + + "(macro) HTML details": { + "scope": "jinja-md,md", + "prefix": "html.details", + "body": [ + "html.details($1)" + ], + "description": "HTML details macro" + }, + + "(macro) HTML italic": { + "scope": "jinja-md,md", + "prefix": "html.italic", + "body": [ + "html.italic($1)" + ], + "description": "HTML italic macro" + }, + + "(macro) HTML summary": { + "scope": "jinja-md,md", + "prefix": "html.summary", + "body": [ + "html.summary($1)" + ], + "description": "HTML summary macro" + }, + } \ No newline at end of file diff --git a/README.md b/README.md index dca259b..339741c 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,104 @@ The natively supported values for `target_formats` are: - Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or `.py`. +## Jinja Templating Helpers + +In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros +and filters which can be used to make formatting content easier. The macros and filters are segregated into +3 namespaces, documented below: + +### Global namespace + +The global namespace contains helpful macros and filters for manipulating data in the Jinja +context. It also provides access to more specific namespaces through their respective identifiers, +such as `md` and `html`. + + + +
      + +Jinja macro reference + + +| Macro | Signature | Doc | +| --- | --- | --- | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | + +
      + +
      + +Jinja filter reference + + +| Filter | Signature | Doc | +| --- | --- | --- | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | + +
      + +### `md` namespace + +None + + +
      + +Jinja macro reference + + +| Macro | Signature | Doc | +| --- | --- | --- | + +
      + +
      + +Jinja filter reference + + +| Filter | Signature | Doc | +| --- | --- | --- | + +
      + +### `html` namespace + +None + + +
      + +Jinja macro reference + + +| Macro | Signature | Doc | +| --- | --- | --- | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | + +
      + +
      + +Jinja filter reference + + +| Filter | Signature | Doc | +| --- | --- | --- | + +
      + + + ## Acknowledgements Author: From a901c6fded28c1e4bb651c444d7edeaeecfb5452 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 10:11:39 -0800 Subject: [PATCH 09/22] trying double linebreaking code blocks --- .metadock/generated_documents/README.html | 24 +++++++++---------- .metadock/generated_documents/README.md | 24 +++++++++---------- .../repo_readme_template.md | 4 ++-- README.md | 24 +++++++++---------- metadock/env.py | 2 +- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 9213a91..a5e4754 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -268,7 +268,7 @@

      Global namespace

      debug metadock.env.MetadockEnv.debug: (self, message: str) -> None -Prints a debug message to stdout, and returns an empty string.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      +Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()

      This is a debug message.

      'No changes!'



      @@ -287,27 +287,27 @@

      Global namespace

      chain metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] -Filter which flattens a sequence of iterables into a single iterable.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
      'first 1 second 2'

      +Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()

      'first 1 second 2'



      inline metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str -Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      +Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()

      'This is a multi-line string. This is the second line. And the third.'



      with_prefix metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str -Filter which prepends a prefix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      +Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()

      'PrefixThis is a string.'

      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()

      'Prefix : This is a string.'



      with_suffix metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str -Filter which appends a suffix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      +Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()

      'This is a stringSuffix'

      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()

      'This is a string : Suffix'



      zip metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] -Filter which zips an input iterable with one or more iterables.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      +Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()

      "[('a', 1), ('b', 2), ('c', 3)]"



      md namespace

      @@ -354,32 +354,32 @@

      html namespace

      html.bold metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str -Wraps a string in HTML bold tags (<b></b>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      +Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()

      '<b>This is bold text.</b>'



      html.code metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str -Wraps a string in HTML code tags (<code></code>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      +Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.code('This is code text.') }}").render()

      '<code>This is code text.</code>'



      html.codeblock metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str -Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      +Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()

      '<pre><code> This is code text.</code></pre>'



      html.details metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str -Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      +Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.details('This is details text.') }}").render()

      '<details>\nThis is details text.\n</details>'



      html.italic metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str -Wraps a string in HTML italic tags (<i></i>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      +Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()

      '<i>This is italic text.</i>'



      html.summary metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str -Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      +Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()

      '<summary>\nThis is summary text.\n</summary>'



      diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 339741c..7744be5 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()

      This is a debug message.

      'No changes!'



      |
      @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()

      'first 1 second 2'



      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()

      'This is a multi-line string. This is the second line. And the third.'



      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()

      'PrefixThis is a string.'

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()

      'Prefix : This is a string.'



      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()

      'This is a stringSuffix'

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()

      'This is a string : Suffix'



      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()

      "[('a', 1), ('b', 2), ('c', 3)]"



      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()

      '<b>This is bold text.</b>'



      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.code('This is code text.') }}").render()

      '<code>This is code text.</code>'



      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()

      '<pre><code> This is code text.</code></pre>'



      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.details('This is details text.') }}").render()

      '<details>\nThis is details text.\n</details>'



      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()

      '<i>This is italic text.</i>'



      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()

      '<summary>\nThis is summary text.\n</summary>'



      | diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index 95f21b1..d56ac29 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -109,7 +109,7 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ macro), html.code(macro_spec.get("method_name") ~ ": " ~ macro_spec.get("signature")), - (macro_spec.get("docstring") | inline | html.escape) ~ "
      " ~ (md.codeblock(macro_spec.get("example"), language="py") + (macro_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (md.codeblock(macro_spec.get("example"), language="py") | md.convert | html.inline), ) }} @@ -122,7 +122,7 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ filter), html.code(filter_spec.get("method_name") ~ ": " ~ filter_spec.get("signature")), - (filter_spec.get("docstring") | inline | html.escape) ~ "
      " ~ (md.codeblock(filter_spec.get("example"), language="py") + (filter_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (md.codeblock(filter_spec.get("example"), language="py") | md.convert | html.inline), ) }} diff --git a/README.md b/README.md index 339741c..7744be5 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()

      This is a debug message.

      'No changes!'



      | @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()

      'first 1 second 2'



      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()

      'This is a multi-line string. This is the second line. And the third.'



      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()

      'PrefixThis is a string.'

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()

      'Prefix : This is a string.'



      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()

      'This is a stringSuffix'

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()

      'This is a string : Suffix'



      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()

      "[('a', 1), ('b', 2), ('c', 3)]"



      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).
      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()

      '<b>This is bold text.</b>'



      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.code('This is code text.') }}").render()

      '<code>This is code text.</code>'



      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()

      '<pre><code> This is code text.</code></pre>'



      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.details('This is details text.') }}").render()

      '<details>\nThis is details text.\n</details>'



      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()

      '<i>This is italic text.</i>'



      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()

      '<summary>\nThis is summary text.\n</summary>'



      | diff --git a/metadock/env.py b/metadock/env.py index 7d118a9..64aee91 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -316,7 +316,7 @@ def inline_filter(self, content: str) -> str: Returns: str: The HTML-inlined string. """ - return content.replace("\n", "
      ") + return content.replace("\n", "

      ") class MetadockEnv(MetadockNamespace): From 50c986c64c0689d079a9deac68e67b3130e6c826 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 10:15:28 -0800 Subject: [PATCH 10/22] linebreaking code blocks in readme --- .metadock/generated_documents/README.html | 24 +++++++++---------- .metadock/generated_documents/README.md | 24 +++++++++---------- .../repo_readme_template.md | 8 +++---- README.md | 24 +++++++++---------- metadock/env.py | 2 +- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index a5e4754..e504ca9 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -268,7 +268,7 @@

      Global namespace

      debug metadock.env.MetadockEnv.debug: (self, message: str) -> None -Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()

      This is a debug message.

      'No changes!'



      +Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'
      @@ -287,27 +287,27 @@

      Global namespace

      chain metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] -Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()

      'first 1 second 2'



      +Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
      'first 1 second 2'
      inline metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str -Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()

      'This is a multi-line string. This is the second line. And the third.'



      +Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'
      with_prefix metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str -Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()

      'PrefixThis is a string.'

      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()

      'Prefix : This is a string.'



      +Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'
      with_suffix metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str -Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()

      'This is a stringSuffix'

      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()

      'This is a string : Suffix'



      +Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'
      zip metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] -Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()

      "[('a', 1), ('b', 2), ('c', 3)]"



      +Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      md namespace

      @@ -354,32 +354,32 @@

      html namespace

      html.bold metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str -Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()

      '<b>This is bold text.</b>'



      +Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      'This is bold text.'
      html.code metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str -Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.code('This is code text.') }}").render()

      '<code>This is code text.</code>'



      +Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      'This is code text.'
      html.codeblock metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str -Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()

      '<pre><code> This is code text.</code></pre>'



      +Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '
          This is code text.
      '
      html.details metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str -Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.details('This is details text.') }}").render()

      '<details>\nThis is details text.\n</details>'



      +Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '
      \nThis is details text.\n
      '
      html.italic metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str -Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()

      '<i>This is italic text.</i>'



      +Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      'This is italic text.'
      html.summary metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str -Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()

      '<summary>\nThis is summary text.\n</summary>'



      +Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '\nThis is summary text.\n'
      diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 7744be5..3d558ed 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()

      This is a debug message.

      'No changes!'



      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'
      |
      @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()

      'first 1 second 2'



      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()

      'This is a multi-line string. This is the second line. And the third.'



      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()

      'PrefixThis is a string.'

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()

      'Prefix : This is a string.'



      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()

      'This is a stringSuffix'

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()

      'This is a string : Suffix'



      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()

      "[('a', 1), ('b', 2), ('c', 3)]"



      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'
      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'
      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'
      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'
      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"
      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()

      '<b>This is bold text.</b>'



      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.code('This is code text.') }}").render()

      '<code>This is code text.</code>'



      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()

      '<pre><code> This is code text.</code></pre>'



      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.details('This is details text.') }}").render()

      '<details>\nThis is details text.\n</details>'



      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()

      '<i>This is italic text.</i>'



      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()

      '<summary>\nThis is summary text.\n</summary>'



      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      'This is bold text.'
      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      'This is code text.'
      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '
          This is code text.
      '
      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '
      \nThis is details text.\n
      '
      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      'This is italic text.'
      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '\nThis is summary text.\n'
      | diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index d56ac29..e8c28e1 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -109,8 +109,8 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ macro), html.code(macro_spec.get("method_name") ~ ": " ~ macro_spec.get("signature")), - (macro_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (md.codeblock(macro_spec.get("example"), language="py") - | md.convert | html.inline), + (macro_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (html.codeblock(macro_spec.get("example")) + | html.inline), ) }} {% endfor -%} @@ -122,8 +122,8 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ filter), html.code(filter_spec.get("method_name") ~ ": " ~ filter_spec.get("signature")), - (filter_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (md.codeblock(filter_spec.get("example"), language="py") - | md.convert | html.inline), + (filter_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (html.codeblock(filter_spec.get("example")) + | html.inline), ) }} {% endfor -%} diff --git a/README.md b/README.md index 7744be5..3d558ed 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()

      This is a debug message.

      'No changes!'



      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'
      | @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()

      'first 1 second 2'



      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()

      'This is a multi-line string. This is the second line. And the third.'



      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()

      'PrefixThis is a string.'

      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()

      'Prefix : This is a string.'



      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()

      'This is a stringSuffix'

      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()

      'This is a string : Suffix'



      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()

      "[('a', 1), ('b', 2), ('c', 3)]"



      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'
      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'
      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'
      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'
      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"
      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()

      '<b>This is bold text.</b>'



      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.code('This is code text.') }}").render()

      '<code>This is code text.</code>'



      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()

      '<pre><code> This is code text.</code></pre>'



      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.details('This is details text.') }}").render()

      '<details>\nThis is details text.\n</details>'



      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()

      '<i>This is italic text.</i>'



      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv

      >>> env = MetadockEnv().jinja_environment()

      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()

      '<summary>\nThis is summary text.\n</summary>'



      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      'This is bold text.'
      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      'This is code text.'
      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '
          This is code text.
      '
      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '
      \nThis is details text.\n
      '
      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      'This is italic text.'
      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '\nThis is summary text.\n'
      | diff --git a/metadock/env.py b/metadock/env.py index 64aee91..463e9a7 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -316,7 +316,7 @@ def inline_filter(self, content: str) -> str: Returns: str: The HTML-inlined string. """ - return content.replace("\n", "

      ") + return content.replace("\n", "
      ") class MetadockEnv(MetadockNamespace): From 8f515d20ec35ddb6d7f9f0b2d957b7092153da17 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 10:18:43 -0800 Subject: [PATCH 11/22] reverting to md.converted code blocks --- .metadock/generated_documents/README.html | 24 +++++++++---------- .metadock/generated_documents/README.md | 24 +++++++++---------- .../repo_readme_template.md | 8 +++---- README.md | 24 +++++++++---------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index e504ca9..2c34be9 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -268,7 +268,7 @@

      Global namespace

      debug metadock.env.MetadockEnv.debug: (self, message: str) -> None -Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'
      +Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      @@ -287,27 +287,27 @@

      Global namespace

      chain metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] -Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
      'first 1 second 2'
      +Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
      'first 1 second 2'

      inline metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str -Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'
      +Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      with_prefix metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str -Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'
      +Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      with_suffix metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str -Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'
      +Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      zip metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] -Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"
      +Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      md namespace

      @@ -354,32 +354,32 @@

      html namespace

      html.bold metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str -Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      'This is bold text.'
      +Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      html.code metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str -Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      'This is code text.'
      +Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      html.codeblock metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str -Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '
          This is code text.
      '
      +Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      html.details metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str -Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '
      \nThis is details text.\n
      '
      +Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      html.italic metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str -Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      'This is italic text.'
      +Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      html.summary metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str -Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '\nThis is summary text.\n'
      +Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 3d558ed..35b3e87 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'
      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      |
      @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'
      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'
      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'
      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'
      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"
      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      'This is bold text.'
      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      'This is code text.'
      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '
          This is code text.
      '
      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '
      \nThis is details text.\n
      '
      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      'This is italic text.'
      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '\nThis is summary text.\n'
      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index e8c28e1..6970428 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -109,8 +109,8 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ macro), html.code(macro_spec.get("method_name") ~ ": " ~ macro_spec.get("signature")), - (macro_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (html.codeblock(macro_spec.get("example")) - | html.inline), + (macro_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (md.codeblock(macro_spec.get("example")) + | md.convert | html.inline), ) }} {% endfor -%} @@ -122,8 +122,8 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ filter), html.code(filter_spec.get("method_name") ~ ": " ~ filter_spec.get("signature")), - (filter_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (html.codeblock(filter_spec.get("example")) - | html.inline), + (filter_spec.get("docstring") | inline | html.escape) ~ "

      " ~ (md.codeblock(filter_spec.get("example")) + | md.convert | html.inline), ) }} {% endfor -%} diff --git a/README.md b/README.md index 3d558ed..35b3e87 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'
      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'
      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'
      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'
      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'
      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"
      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      'This is bold text.'
      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      'This is code text.'
      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '
          This is code text.
      '
      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '
      \nThis is details text.\n
      '
      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      'This is italic text.'
      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '\nThis is summary text.\n'
      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | From c1ef9771d9e32564a55f08310683e02a23be19bf Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 10:33:00 -0800 Subject: [PATCH 12/22] reverting to html.inlined code blocks in tables --- .metadock/generated_documents/README.html | 24 +++++++++++------------ .metadock/generated_documents/README.md | 24 +++++++++++------------ README.md | 24 +++++++++++------------ metadock/env.py | 2 +- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 2c34be9..be69dc9 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -268,7 +268,7 @@

      Global namespace

      debug metadock.env.MetadockEnv.debug: (self, message: str) -> None -Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      +Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      @@ -287,27 +287,27 @@

      Global namespace

      chain metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] -Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
      'first 1 second 2'

      +Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
      'first 1 second 2'

      inline metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str -Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      +Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      with_prefix metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str -Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      +Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      with_suffix metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str -Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      +Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      zip metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] -Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      +Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      md namespace

      @@ -354,32 +354,32 @@

      html namespace

      html.bold metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str -Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      +Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      html.code metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str -Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      +Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      html.codeblock metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str -Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      +Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      html.details metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str -Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      +Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      html.italic metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str -Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      +Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      html.summary metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str -Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      +Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 35b3e87..eb965fe 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      |
      @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | diff --git a/README.md b/README.md index 35b3e87..eb965fe 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
      This is a debug message.
      'No changes!'

      | @@ -301,11 +301,11 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
      'first 1 second 2'

      | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
      'This is a multi-line string. This is the second line. And the third.'

      | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
      'PrefixThis is a string.'
      >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
      'Prefix : This is a string.'

      | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
      'This is a stringSuffix'
      >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
      'This is a string : Suffix'

      | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
      "[('a', 1), ('b', 2), ('c', 3)]"

      | @@ -346,12 +346,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
      '<b>This is bold text.</b>'

      | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.code('This is code text.') }}").render()
      '<code>This is code text.</code>'

      | +| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
      '<pre><code> This is code text.</code></pre>'

      | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.details('This is details text.') }}").render()
      '<details>\nThis is details text.\n</details>'

      | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
      '<i>This is italic text.</i>'

      | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      | diff --git a/metadock/env.py b/metadock/env.py index 463e9a7..5267f93 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -316,7 +316,7 @@ def inline_filter(self, content: str) -> str: Returns: str: The HTML-inlined string. """ - return content.replace("\n", "
      ") + return content.replace("\n", "
      ") class MetadockEnv(MetadockNamespace): From 95288686e33a82a61f83732687054e3d7bce7748 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 11:34:06 -0800 Subject: [PATCH 13/22] fleshing out jinja helper metadocks --- .../jinja_helpers/global.yml | 23 ++- .../content_schematics/jinja_helpers/html.yml | 67 ++++++++ .../content_schematics/jinja_helpers/md.yml | 162 +++++++++++++++++- .metadock/generated_documents/README.html | 114 +++++++++++- .metadock/generated_documents/README.md | 67 +++++++- .../jinja-md.code-snippets | 95 ++++++++++ .metadock/metadock-build-docs.sh | 6 +- .../repo_readme_template.md | 2 +- .pre-commit-config.yaml | 22 +-- .vscode/jinja-md.code-snippets | 95 ++++++++++ README.md | 67 +++++++- metadock/env.py | 93 +++++----- 12 files changed, 734 insertions(+), 79 deletions(-) diff --git a/.metadock/content_schematics/jinja_helpers/global.yml b/.metadock/content_schematics/jinja_helpers/global.yml index dcf5aeb..06bf6a6 100644 --- a/.metadock/content_schematics/jinja_helpers/global.yml +++ b/.metadock/content_schematics/jinja_helpers/global.yml @@ -1,8 +1,23 @@ global: - info: | - The global namespace contains helpful macros and filters for manipulating data in the Jinja - context. It also provides access to more specific namespaces through their respective identifiers, - such as `md` and `html`. + docstring: | + Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. + + **Macros**: + + debug + + **Namespaces**: + + html + md + + **Filters**: + + chain + inline + with_prefix + with_suffix + zip macros: debug: diff --git a/.metadock/content_schematics/jinja_helpers/html.yml b/.metadock/content_schematics/jinja_helpers/html.yml index 46ac1e4..2c9131c 100644 --- a/.metadock/content_schematics/jinja_helpers/html.yml +++ b/.metadock/content_schematics/jinja_helpers/html.yml @@ -1,4 +1,22 @@ html: + docstring: | + Jinja namespace which owns HTML-related functions and filters. + + **Macros**: + + bold + code + codeblock + details + italic + summary + underline + + **Filters**: + + escape + inline + macros: bold: docstring: | @@ -97,3 +115,52 @@ html: snippet_key: HTML summary snippet_body: - html.summary($1) + + underline: + docstring: | + Wraps a string in HTML underline tags (). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ html.underline('This is underlined text.') }}").render() + 'This is underlined text.' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.underline + signature: "(self, content: str) -> str" + intellisense: + snippet_key: HTML underline + snippet_body: + - html.underline($1) + + filters: + escape: + docstring: | + Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ '

      This is a paragraph.

      ' | html.escape }}").render() + '<p>This is a paragraph.</p>' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.escape_filter + signature: "(self, content: str) -> str" + intellisense: + snippet_key: HTML escape + snippet_body: + - html.escape + + inline: + docstring: | + Filter which inlines a string by replacing all newlines with HTML line-breaks
      singleton tags. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render() + 'This is a multi-line string.
      This is the second line.
      And the third.' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.inline_filter + signature: "(self, content: str) -> str" + intellisense: + snippet_key: HTML inline + snippet_body: + - html.inline diff --git a/.metadock/content_schematics/jinja_helpers/md.yml b/.metadock/content_schematics/jinja_helpers/md.yml index 16a0c7c..b3f3f12 100644 --- a/.metadock/content_schematics/jinja_helpers/md.yml +++ b/.metadock/content_schematics/jinja_helpers/md.yml @@ -1,4 +1,162 @@ md: - macros: {} + docstring: | + Jinja Namespace for Markdown-related functions and filters. - filters: {} + **Macros**: + + blockquote + code + codeblock + list + tablehead + tablerow + + **Filters**: + + convert + list + + macros: + blockquote: + docstring: | + Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> "). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render() + '> This is a blockquote.' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.blockquote + signature: "(self, content: str) -> str" + intellisense: + snippet_key: Markdown blockquote + snippet_body: + - md.blockquote($1) + + code: + docstring: | + Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`"). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ md.code('This is an inline code block.') }}").render() + '`This is an inline code block.`' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.code + signature: "(self, content: str) -> str" + intellisense: + snippet_key: Markdown inline code + snippet_body: + - md.code($1) + + codeblock: + docstring: | + Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), + and optionally specifies a language. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render() + '```sh\nThis is a codeblock.\n```' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.codeblock + signature: "(self, content: str, language: str = '') -> str" + intellisense: + snippet_key: Markdown codeblock + snippet_body: + - md.codeblock($1) + + list: + docstring: | + Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its + arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string( + ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}" + ... ).render() + '- This is a list.\n - This is a sublist,\n - in two pieces.' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.list + signature: "(self, *items: str) -> str" + intellisense: + snippet_key: Markdown list + snippet_body: + - md.list($1) + + tablehead: + docstring: | + Produces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the + result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash + ("\\"). To bold the header cell contents, supply `bold = true`. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string( + ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}" + ... ).render() + '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.tablehead + signature: "(self, *header_cells: str, bold: bool = False) -> str" + intellisense: + snippet_key: Markdown table head + snippet_body: + - md.tablehead($1) + + tablerow: + docstring: | + Produces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the + result in pipes. Cell contents have their pipes escaped with a backslash ("\\"). + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string( + ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n" + ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}" + ... ).render() + '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.tablerow + signature: "(self, *row_cells: str) -> str" + intellisense: + snippet_key: Markdown table row + snippet_body: + - md.tablerow($1) + + filters: + convert: + docstring: | + Filter which converts Markdown content to HTML, by invoking `marko.convert`. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render() + '

      This is a heading

      \n
      \n

      And a block quote.

      \n
      \n' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.convert_filter + signature: "(self, md_content: str) -> str" + intellisense: + snippet_key: Markdown convert + snippet_body: + - md.convert($1) + + list: + docstring: | + Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list + element. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> env.from_string( + ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n" + ... ).render() + '- This is a list.\n- This is a second element\n' + source_file: metadock/env.py + method_name: metadock.env.MetadockMdNamespace.list_filter + signature: "(self, values: str | Iterable[str]) -> str" + intellisense: + snippet_key: Markdown list + snippet_body: + - md.list diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index be69dc9..bc6ba97 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -249,9 +249,21 @@

      Jinja Templating Helpers

      and filters which can be used to make formatting content easier. The macros and filters are segregated into 3 namespaces, documented below:

      Global namespace

      -

      The global namespace contains helpful macros and filters for manipulating data in the Jinja -context. It also provides access to more specific namespaces through their respective identifiers, -such as md and html.

      +

      Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces.

      +

      Macros:

      +
      debug
      +
      +

      Namespaces:

      +
      html
      +md
      +
      +

      Filters:

      +
      chain
      +inline
      +with_prefix
      +with_suffix
      +zip
      +
      Jinja macro reference @@ -311,7 +323,19 @@

      Global namespace

      md namespace

      -

      None

      +

      Jinja Namespace for Markdown-related functions and filters.

      +

      Macros:

      +
      blockquote
      +code
      +codeblock
      +list
      +tablehead
      +tablerow
      +
      +

      Filters:

      +
      convert
      +list
      +
      Jinja macro reference @@ -323,7 +347,39 @@

      md namespace

      Signature Doc -
      + + + +md.blockquote +metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str +Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
      '> This is a blockquote.'

      + + +md.code +metadock.env.MetadockMdNamespace.code: (self, content: str) -> str +Produces a Markdown inline code block from the given content by wrapping the string in graves ("`").

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
      '`This is an inline code block.`'

      + + +md.codeblock +metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str +Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
      'sh\nThis is a codeblock.\n'

      + + +md.list +metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str +Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string(
      ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
      ... ).render()
      '- This is a list.\n - This is a sublist,\n - in two pieces.'

      + + +md.tablehead +metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str +Produces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string(
      ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
      ... ).render()
      '| <b>Column 1</b> | <b>Column 2</b> | <b>Column 3</b> |\n| --- | --- | --- |'

      + + +md.tablerow +metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str +Produces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string(
      ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
      ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
      ... ).render()
      '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'

      + +
      Jinja filter reference @@ -335,9 +391,34 @@

      md namespace

      Signature Doc -
      + + + +md.convert +metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str +Filter which converts Markdown content to HTML, by invoking marko.convert.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
      '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

      + + +md.list +metadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> str +Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string(
      ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
      ... ).render()
      '- This is a list.\n- This is a second element\n'

      + +

      html namespace

      -

      None

      +

      Jinja namespace which owns HTML-related functions and filters.

      +

      Macros:

      +
      bold
      +code
      +codeblock
      +details
      +italic
      +summary
      +underline
      +
      +

      Filters:

      +
      escape
      +inline
      +
      Jinja macro reference @@ -381,6 +462,11 @@

      html namespace

      metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
      '<summary>\nThis is summary text.\n</summary>'

      + +html.underline +metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str +Wraps a string in HTML underline tags (<u></u>).

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
      '<u>This is underlined text.</u>'

      +
      @@ -393,7 +479,19 @@

      html namespace

      Signature Doc -
      + + + +html.escape +metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str +Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ '<p>This is a paragraph.</p>' | html.escape }}").render()
      '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

      + + +html.inline +metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str +Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

      >>> from metadock.env import MetadockEnv
      >>> env = MetadockEnv().jinja_environment()
      >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
      'This is a multi-line string.<br>This is the second line.<br>And the third.'

      + +

      Acknowledgements

      Author:

        diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index eb965fe..5ad7a7a 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -277,9 +277,24 @@ and filters which can be used to make formatting content easier. The macros and ### Global namespace -The global namespace contains helpful macros and filters for manipulating data in the Jinja -context. It also provides access to more specific namespaces through their respective identifiers, -such as `md` and `html`. +Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. + +**Macros**: + + debug + +**Namespaces**: + + html + md + +**Filters**: + + chain + inline + with_prefix + with_suffix + zip @@ -311,7 +326,22 @@ Jinja filter reference ### `md` namespace -None +Jinja Namespace for Markdown-related functions and filters. + +**Macros**: + + blockquote + code + codeblock + list + tablehead + tablerow + +**Filters**: + + convert + list +
        @@ -321,6 +351,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | +| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
        '> This is a blockquote.'

        | +| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
        '`This is an inline code block.`'

        | +| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
        '```sh\nThis is a codeblock.\n```'

        | +| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
        ... ).render()
        '- This is a list.\n - This is a sublist,\n - in two pieces.'

        | +| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
        ... ).render()
        '\| <b>Column 1</b> \| <b>Column 2</b> \| <b>Column 3</b> \|\n\| --- \| --- \| --- \|'

        | +| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
        ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
        ... ).render()
        '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'

        |
        @@ -331,12 +367,30 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | +| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert`.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
        '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

        | +| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
        ... ).render()
        '- This is a list.\n- This is a second element\n'

        | ### `html` namespace -None +Jinja namespace which owns HTML-related functions and filters. + +**Macros**: + + bold + code + codeblock + details + italic + summary + underline + +**Filters**: + + escape + inline +
        @@ -352,6 +406,7 @@ Jinja macro reference | html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.details('This is details text.') }}").render()
        '<details>\nThis is details text.\n</details>'

        | | html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
        '<i>This is italic text.</i>'

        | | html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
        '<summary>\nThis is summary text.\n</summary>'

        | +| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
        '<u>This is underlined text.</u>'

        |
        @@ -362,6 +417,8 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | +| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ '<p>This is a paragraph.</p>' \| html.escape }}").render()
        '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

        | +| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
        'This is a multi-line string.<br>This is the second line.<br>And the third.'

        | diff --git a/.metadock/generated_documents/jinja-md.code-snippets b/.metadock/generated_documents/jinja-md.code-snippets index 1a30c26..6c9e6e2 100644 --- a/.metadock/generated_documents/jinja-md.code-snippets +++ b/.metadock/generated_documents/jinja-md.code-snippets @@ -53,6 +53,76 @@ // Metadock snippets for macros and filters in md namespace + "(macro) Markdown blockquote": { + "scope": "jinja-md,md", + "prefix": "md.blockquote", + "body": [ + "md.blockquote($1)" + ], + "description": "Markdown blockquote macro" + }, + + "(macro) Markdown inline code": { + "scope": "jinja-md,md", + "prefix": "md.code", + "body": [ + "md.code($1)" + ], + "description": "Markdown inline code macro" + }, + + "(macro) Markdown codeblock": { + "scope": "jinja-md,md", + "prefix": "md.codeblock", + "body": [ + "md.codeblock($1)" + ], + "description": "Markdown codeblock macro" + }, + + "(macro) Markdown list": { + "scope": "jinja-md,md", + "prefix": "md.list", + "body": [ + "md.list($1)" + ], + "description": "Markdown list macro" + }, + + "(macro) Markdown table head": { + "scope": "jinja-md,md", + "prefix": "md.tablehead", + "body": [ + "md.tablehead($1)" + ], + "description": "Markdown table head macro" + }, + + "(macro) Markdown table row": { + "scope": "jinja-md,md", + "prefix": "md.tablerow", + "body": [ + "md.tablerow($1)" + ], + "description": "Markdown table row macro" + }, + "(filter) Markdown convert": { + "scope": "jinja-md,md", + "prefix": "md.convert", + "body": [ + "md.convert($1)" + ], + "description": "Markdown convert filter" + }, + "(filter) Markdown list": { + "scope": "jinja-md,md", + "prefix": "md.list", + "body": [ + "md.list" + ], + "description": "Markdown list filter" + }, + // Metadock snippets for macros and filters in html namespace "(macro) HTML bold": { @@ -109,4 +179,29 @@ "description": "HTML summary macro" }, + "(macro) HTML underline": { + "scope": "jinja-md,md", + "prefix": "html.underline", + "body": [ + "html.underline($1)" + ], + "description": "HTML underline macro" + }, + "(filter) HTML escape": { + "scope": "jinja-md,md", + "prefix": "html.escape", + "body": [ + "html.escape" + ], + "description": "HTML escape filter" + }, + "(filter) HTML inline": { + "scope": "jinja-md,md", + "prefix": "html.inline", + "body": [ + "html.inline" + ], + "description": "HTML inline filter" + }, + } \ No newline at end of file diff --git a/.metadock/metadock-build-docs.sh b/.metadock/metadock-build-docs.sh index bf95620..bece6e4 100644 --- a/.metadock/metadock-build-docs.sh +++ b/.metadock/metadock-build-docs.sh @@ -8,13 +8,11 @@ poetry install echo "Metadock-building README.md..." poetry run metadock build -s README cp .metadock/generated_documents/README.md README.md +git add README.md # metadock build Intellisense snippets echo "Metadock-building Intellisense snippets..." poetry run metadock build -s jinja-md cp .metadock/generated_documents/jinja-md.code-snippets .vscode/jinja-md.code-snippets - -# capture all changes - -git add -A \ No newline at end of file +git add .vscode/jinja-md.code-snippets \ No newline at end of file diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index 6970428..503a4d9 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -100,7 +100,7 @@ and filters which can be used to make formatting content easier. The macros and {%- set namespace_intro -%} ### {{ namespace_title_prefix }} namespace -{{ namespace_spec.get("info") }} +{{ namespace_spec.get("docstring") }} {% endset -%} {%- set ns_macro_table -%} {{ md.tablehead("Macro", "Signature", "Doc", bold=true) }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0be73a1..9f75820 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ repos: -- repo: https://github.com/psf/black - rev: 22.10.0 - hooks: - - id: black - args: [--line-length=120] + - repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black + args: [--line-length=120] -- repo: local - hooks: - - id: metadock-build - name: Metadock-build README - entry: bash .metadock/metadock-build-docs.sh - language: system \ No newline at end of file + - repo: local + hooks: + - id: metadock-build + name: Metadock-build documents + entry: bash -c "bash .metadock/metadock-build-docs.sh" -- + language: system diff --git a/.vscode/jinja-md.code-snippets b/.vscode/jinja-md.code-snippets index 1a30c26..6c9e6e2 100644 --- a/.vscode/jinja-md.code-snippets +++ b/.vscode/jinja-md.code-snippets @@ -53,6 +53,76 @@ // Metadock snippets for macros and filters in md namespace + "(macro) Markdown blockquote": { + "scope": "jinja-md,md", + "prefix": "md.blockquote", + "body": [ + "md.blockquote($1)" + ], + "description": "Markdown blockquote macro" + }, + + "(macro) Markdown inline code": { + "scope": "jinja-md,md", + "prefix": "md.code", + "body": [ + "md.code($1)" + ], + "description": "Markdown inline code macro" + }, + + "(macro) Markdown codeblock": { + "scope": "jinja-md,md", + "prefix": "md.codeblock", + "body": [ + "md.codeblock($1)" + ], + "description": "Markdown codeblock macro" + }, + + "(macro) Markdown list": { + "scope": "jinja-md,md", + "prefix": "md.list", + "body": [ + "md.list($1)" + ], + "description": "Markdown list macro" + }, + + "(macro) Markdown table head": { + "scope": "jinja-md,md", + "prefix": "md.tablehead", + "body": [ + "md.tablehead($1)" + ], + "description": "Markdown table head macro" + }, + + "(macro) Markdown table row": { + "scope": "jinja-md,md", + "prefix": "md.tablerow", + "body": [ + "md.tablerow($1)" + ], + "description": "Markdown table row macro" + }, + "(filter) Markdown convert": { + "scope": "jinja-md,md", + "prefix": "md.convert", + "body": [ + "md.convert($1)" + ], + "description": "Markdown convert filter" + }, + "(filter) Markdown list": { + "scope": "jinja-md,md", + "prefix": "md.list", + "body": [ + "md.list" + ], + "description": "Markdown list filter" + }, + // Metadock snippets for macros and filters in html namespace "(macro) HTML bold": { @@ -109,4 +179,29 @@ "description": "HTML summary macro" }, + "(macro) HTML underline": { + "scope": "jinja-md,md", + "prefix": "html.underline", + "body": [ + "html.underline($1)" + ], + "description": "HTML underline macro" + }, + "(filter) HTML escape": { + "scope": "jinja-md,md", + "prefix": "html.escape", + "body": [ + "html.escape" + ], + "description": "HTML escape filter" + }, + "(filter) HTML inline": { + "scope": "jinja-md,md", + "prefix": "html.inline", + "body": [ + "html.inline" + ], + "description": "HTML inline filter" + }, + } \ No newline at end of file diff --git a/README.md b/README.md index eb965fe..5ad7a7a 100644 --- a/README.md +++ b/README.md @@ -277,9 +277,24 @@ and filters which can be used to make formatting content easier. The macros and ### Global namespace -The global namespace contains helpful macros and filters for manipulating data in the Jinja -context. It also provides access to more specific namespaces through their respective identifiers, -such as `md` and `html`. +Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. + +**Macros**: + + debug + +**Namespaces**: + + html + md + +**Filters**: + + chain + inline + with_prefix + with_suffix + zip @@ -311,7 +326,22 @@ Jinja filter reference ### `md` namespace -None +Jinja Namespace for Markdown-related functions and filters. + +**Macros**: + + blockquote + code + codeblock + list + tablehead + tablerow + +**Filters**: + + convert + list +
        @@ -321,6 +351,12 @@ Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | +| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
        '> This is a blockquote.'

        | +| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
        '`This is an inline code block.`'

        | +| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
        '```sh\nThis is a codeblock.\n```'

        | +| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
        ... ).render()
        '- This is a list.\n - This is a sublist,\n - in two pieces.'

        | +| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
        ... ).render()
        '\| <b>Column 1</b> \| <b>Column 2</b> \| <b>Column 3</b> \|\n\| --- \| --- \| --- \|'

        | +| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
        ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
        ... ).render()
        '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'

        |
        @@ -331,12 +367,30 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | +| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert`.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
        '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

        | +| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
        ... ).render()
        '- This is a list.\n- This is a second element\n'

        | ### `html` namespace -None +Jinja namespace which owns HTML-related functions and filters. + +**Macros**: + + bold + code + codeblock + details + italic + summary + underline + +**Filters**: + + escape + inline +
        @@ -352,6 +406,7 @@ Jinja macro reference | html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.details('This is details text.') }}").render()
        '<details>\nThis is details text.\n</details>'

        | | html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
        '<i>This is italic text.</i>'

        | | html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
        '<summary>\nThis is summary text.\n</summary>'

        | +| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
        '<u>This is underlined text.</u>'

        |
        @@ -362,6 +417,8 @@ Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | +| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ '<p>This is a paragraph.</p>' \| html.escape }}").render()
        '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

        | +| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
        'This is a multi-line string.<br>This is the second line.<br>And the third.'

        | diff --git a/metadock/env.py b/metadock/env.py index 5267f93..97892aa 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -70,7 +70,8 @@ def jinja_environment(self) -> jinja2.Environment: class MetadockMdNamespace(MetadockNamespace): """Jinja Namespace for Markdown-related functions and filters. - Exports: + **Macros**: + blockquote code codeblock @@ -78,7 +79,8 @@ class MetadockMdNamespace(MetadockNamespace): tablehead tablerow - Filters: + **Filters**: + convert list """ @@ -87,7 +89,7 @@ class MetadockMdNamespace(MetadockNamespace): filters = ["convert", "list"] def blockquote(self, content: str) -> str: - """Produces a Markdown blockquote from the given content. + """Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> "). Args: content (str): The content of the blockquote. @@ -98,8 +100,20 @@ def blockquote(self, content: str) -> str: _blockquoted = content.strip().replace("\n", "\n> ") return f"> {_blockquoted}" + def code(self, content: str) -> str: + """Produces a Markdown inline code block from the given content by wrapping the string in graves ("`"). + + Args: + content (str): The content of the inline code block. + + Returns: + str: The Markdown inline code block. + """ + return f"`{content.strip()}`" + def codeblock(self, content: str, language: str = "") -> str: - """Produces a Markdown codeblock from the given content. + """Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), + and optionally specifies a language. Args: content (str): The content of the codeblock. @@ -110,19 +124,32 @@ def codeblock(self, content: str, language: str = "") -> str: """ return f"```{language}\n{content.strip()}\n```" - def code(self, content: str) -> str: - """Produces a Markdown inline code block from the given content. + def list(self, *items: str) -> str: + """Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its + arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists. Args: - content (str): The content of the inline code block. + *items (str): The individual items and/or sub-lists which compose the list. Returns: - str: The Markdown inline code block. + str: The composite Markdown list. """ - return f"`{content.strip()}`" + _list_prefixes = ("-", "*", "+") + + def _is_md_list(item: str): + return item.lstrip().startswith(_list_prefixes) + + listed_items = [list(map(str, item)) if _is_nonstr_iter(item) else [str(item)] for item in items] + flat_items = list(itertools.chain.from_iterable(listed_items)) + indented_items = [item.replace("\n", "\n ") for item in flat_items if isinstance(item, str)] + return "\n".join( + (f"- {flat_item}" if not _is_md_list(flat_item) else f" {indented_item}") + for flat_item, indented_item in zip(flat_items, indented_items) + ) def tablerow(self, *cells: str) -> str: - """Produces a Markdown table row from the given cells. + """Produces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the + result in pipes. Cell contents have their pipes escaped with a backslash ("\\"). Args: *cells (str): The cells of the table row. @@ -134,7 +161,9 @@ def tablerow(self, *cells: str) -> str: return "| " + " | ".join(_pipe_escaped_cells) + " |" def tablehead(self, *header_cells: str, bold: bool = False) -> str: - """Produces a Markdown table header row from the given header cells. + """Produces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the + result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash + ("\\"). To bold the header cell contents, supply `bold = true`. Args: *header_cells (str): The header cells of the table header row. @@ -148,29 +177,6 @@ def tablehead(self, *header_cells: str, bold: bool = False) -> str: _pipe_escaped_cells = tuple(MetadockHtmlNamespace().bold(cell) for cell in _pipe_escaped_cells) return self.tablerow(*_pipe_escaped_cells) + "\n" + self.tablerow(*(["---"] * len(_pipe_escaped_cells))) - def list(self, *items: str) -> str: - """Produces a Markdown list from the given items, even when those items themselves may be formatted as Markdown - lists. - - Args: - *items (str): The individual items and/or sub-lists which compose the list. - - Returns: - str: The composite Markdown list. - """ - _list_prefixes = ("-", "*", "+") - - def _is_md_list(item: str): - return item.lstrip().startswith(_list_prefixes) - - listed_items = [list(map(str, item)) if _is_nonstr_iter(item) else [str(item)] for item in items] - flat_items = list(itertools.chain.from_iterable(listed_items)) - indented_items = [item.replace("\n", "\n ") for item in flat_items if isinstance(item, str)] - return "\n".join( - (f"- {flat_item}" if not _is_md_list(flat_item) else f" {indented_item}") - for flat_item, indented_item in zip(flat_items, indented_items) - ) - def convert_filter(self, md_content: str) -> str: """Filter which converts Markdown content to HTML, by invoking `marko.convert`. @@ -200,7 +206,8 @@ def list_filter(self, values: str | Iterable[str]) -> str: class MetadockHtmlNamespace(MetadockNamespace): """Jinja namespace which owns HTML-related functions and filters. - Exports: + **Macros**: + bold code codeblock @@ -208,6 +215,11 @@ class MetadockHtmlNamespace(MetadockNamespace): italic summary underline + + **Filters**: + + escape + inline """ exports = ["bold", "code", "codeblock", "details", "italic", "summary", "underline"] @@ -308,7 +320,7 @@ def escape_filter(self, content: str) -> str: return html.escape(content) def inline_filter(self, content: str) -> str: - """Filter which inlines a string by replacing all newlines with HTML line-break
        singleton tags. + """Filter which inlines a string by replacing all newlines with HTML line-break
        singleton tags. Args: content (str): Piped input string to be HTML-inlined. @@ -322,14 +334,17 @@ def inline_filter(self, content: str) -> str: class MetadockEnv(MetadockNamespace): """Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. - Exports: + **Macros**: + debug - Namespaces: + **Namespaces**: + html md - Filters: + **Filters**: + chain inline with_prefix From 2cfaf143696135a4eeeb8688ab285de1e28af60f Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 11:36:39 -0800 Subject: [PATCH 14/22] minor metadock correction in jinja helper section --- .metadock/content_schematics/jinja_helpers/global.yml | 2 +- .metadock/generated_documents/README.html | 2 +- .metadock/generated_documents/README.md | 2 +- README.md | 2 +- metadock/env.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.metadock/content_schematics/jinja_helpers/global.yml b/.metadock/content_schematics/jinja_helpers/global.yml index 06bf6a6..fd52898 100644 --- a/.metadock/content_schematics/jinja_helpers/global.yml +++ b/.metadock/content_schematics/jinja_helpers/global.yml @@ -1,6 +1,6 @@ global: docstring: | - Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. + Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces. **Macros**: diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index bc6ba97..4df08f7 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -249,7 +249,7 @@

        Jinja Templating Helpers

        and filters which can be used to make formatting content easier. The macros and filters are segregated into 3 namespaces, documented below:

        Global namespace

        -

        Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces.

        +

        Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces.

        Macros:

        debug
         
        diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 5ad7a7a..5b7486e 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -277,7 +277,7 @@ and filters which can be used to make formatting content easier. The macros and ### Global namespace -Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. +Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces. **Macros**: diff --git a/README.md b/README.md index 5ad7a7a..5b7486e 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,7 @@ and filters which can be used to make formatting content easier. The macros and ### Global namespace -Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. +Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces. **Macros**: diff --git a/metadock/env.py b/metadock/env.py index 97892aa..69f0bfc 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -332,7 +332,7 @@ def inline_filter(self, content: str) -> str: class MetadockEnv(MetadockNamespace): - """Jinja namespace for the global Metadock environment, including all global exports, filters, and namespaces. + """Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces. **Macros**: From fad782fe445d1d1547fbc620738d5140bdd73ab8 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 11:41:25 -0800 Subject: [PATCH 15/22] trying converting the tables --- .../content_schematics/jinja_helpers/md.yml | 2 +- .metadock/generated_documents/README.html | 20 +- .metadock/generated_documents/README.md | 216 ++++++++++++++---- .../repo_readme_template.md | 4 +- README.md | 216 ++++++++++++++---- metadock/env.py | 6 +- 6 files changed, 369 insertions(+), 95 deletions(-) diff --git a/.metadock/content_schematics/jinja_helpers/md.yml b/.metadock/content_schematics/jinja_helpers/md.yml index b3f3f12..2268a03 100644 --- a/.metadock/content_schematics/jinja_helpers/md.yml +++ b/.metadock/content_schematics/jinja_helpers/md.yml @@ -128,7 +128,7 @@ md: filters: convert: docstring: | - Filter which converts Markdown content to HTML, by invoking `marko.convert`. + Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md). example: | >>> from metadock.env import MetadockEnv >>> env = MetadockEnv().jinja_environment() diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 4df08f7..2a87279 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -282,7 +282,8 @@

        Global namespace

        metadock.env.MetadockEnv.debug: (self, message: str) -> None Prints a debug message to stdout, and returns an empty string.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
        This is a debug message.
        'No changes!'

        - + +
        Jinja filter reference @@ -321,7 +322,8 @@

        Global namespace

        metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] Filter which zips an input iterable with one or more iterables.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
        "[('a', 1), ('b', 2), ('c', 3)]"

        -
        + +

        md namespace

        Jinja Namespace for Markdown-related functions and filters.

        Macros:

        @@ -379,7 +381,8 @@

        md namespace

        metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str Produces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
        ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
        ... ).render()
        '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'

        - + +
        Jinja filter reference @@ -396,14 +399,15 @@

        md namespace

        md.convert metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str -Filter which converts Markdown content to HTML, by invoking marko.convert.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
        '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

        +Filter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
        '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

        md.list metadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> str Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string(
        ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
        ... ).render()
        '- This is a list.\n- This is a second element\n'

        -
        + +

        html namespace

        Jinja namespace which owns HTML-related functions and filters.

        Macros:

        @@ -467,7 +471,8 @@

        html namespace

        metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str Wraps a string in HTML underline tags (<u></u>).

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
        '<u>This is underlined text.</u>'

        - + +
        Jinja filter reference @@ -491,7 +496,8 @@

        html namespace

        metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

        >>> from metadock.env import MetadockEnv
        >>> env = MetadockEnv().jinja_environment()
        >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
        'This is a multi-line string.<br>This is the second line.<br>And the third.'

        -
        + +

        Acknowledgements

        Author:

          diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 5b7486e..f396cf7 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -303,10 +303,21 @@ Jinja namespace for the global Metadock environment, including all global macros Jinja macro reference -| Macro | Signature | Doc | -| --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
          This is a debug message.
          'No changes!'

          | - + + + + + + + + + + + + + + +
          MacroSignatureDoc
          debugmetadock.env.MetadockEnv.debug: (self, message: str) -> NonePrints a debug message to stdout, and returns an empty string.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
          This is a debug message.
          'No changes!'

          @@ -314,14 +325,41 @@ Jinja macro reference Jinja filter reference -| Filter | Signature | Doc | -| --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
          'first 1 second 2'

          | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
          'This is a multi-line string. This is the second line. And the third.'

          | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
          'PrefixThis is a string.'
          >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
          'Prefix : This is a string.'

          | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
          'This is a stringSuffix'
          >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
          'This is a string : Suffix'

          | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
          "[('a', 1), ('b', 2), ('c', 3)]"

          | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          FilterSignatureDoc
          chainmetadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]Filter which flattens a sequence of iterables into a single iterable.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
          'first 1 second 2'

          inlinemetadock.env.MetadockEnv.inline_filter: (self, value: str) -> strFilter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
          'This is a multi-line string. This is the second line. And the third.'

          with_prefixmetadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> strFilter which prepends a prefix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
          'PrefixThis is a string.'
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
          'Prefix : This is a string.'

          with_suffixmetadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> strFilter which appends a suffix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
          'This is a stringSuffix'
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
          'This is a string : Suffix'

          zipmetadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]Filter which zips an input iterable with one or more iterables.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
          "[('a', 1), ('b', 2), ('c', 3)]"

          ### `md` namespace @@ -349,15 +387,46 @@ Jinja Namespace for Markdown-related functions and filters. Jinja macro reference -| Macro | Signature | Doc | -| --- | --- | --- | -| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
          '> This is a blockquote.'

          | -| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
          '`This is an inline code block.`'

          | -| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
          '```sh\nThis is a codeblock.\n```'

          | -| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
          ... ).render()
          '- This is a list.\n - This is a sublist,\n - in two pieces.'

          | -| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
          ... ).render()
          '\| <b>Column 1</b> \| <b>Column 2</b> \| <b>Column 3</b> \|\n\| --- \| --- \| --- \|'

          | -| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
          ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
          ... ).render()
          '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'

          | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          MacroSignatureDoc
          md.blockquotemetadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> strProduces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
          '> This is a blockquote.'

          md.codemetadock.env.MetadockMdNamespace.code: (self, content: str) -> strProduces a Markdown inline code block from the given content by wrapping the string in graves ("`").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
          '`This is an inline code block.`'

          md.codeblockmetadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> strProduces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
          'sh\nThis is a codeblock.\n'

          md.listmetadock.env.MetadockMdNamespace.list: (self, *items: str) -> strProduces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
          ... ).render()
          '- This is a list.\n - This is a sublist,\n - in two pieces.'

          md.tableheadmetadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> strProduces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
          ... ).render()
          '| <b>Column 1</b> | <b>Column 2</b> | <b>Column 3</b> |\n| --- | --- | --- |'

          md.tablerowmetadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> strProduces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
          ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
          ... ).render()
          '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'

          @@ -365,11 +434,26 @@ Jinja macro reference Jinja filter reference -| Filter | Signature | Doc | -| --- | --- | --- | -| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert`.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
          '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

          | -| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
          ... ).render()
          '- This is a list.\n- This is a second element\n'

          | - + + + + + + + + + + + + + + + + + + + +
          FilterSignatureDoc
          md.convertmetadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> strFilter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
          '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

          md.listmetadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> strFilter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
          ... ).render()
          '- This is a list.\n- This is a second element\n'

          ### `html` namespace @@ -398,16 +482,51 @@ Jinja namespace which owns HTML-related functions and filters. Jinja macro reference -| Macro | Signature | Doc | -| --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
          '<b>This is bold text.</b>'

          | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.code('This is code text.') }}").render()
          '<code>This is code text.</code>'

          | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
          '<pre><code> This is code text.</code></pre>'

          | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.details('This is details text.') }}").render()
          '<details>\nThis is details text.\n</details>'

          | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
          '<i>This is italic text.</i>'

          | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
          '<summary>\nThis is summary text.\n</summary>'

          | -| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
          '<u>This is underlined text.</u>'

          | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          MacroSignatureDoc
          html.boldmetadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> strWraps a string in HTML bold tags (<b></b>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
          '<b>This is bold text.</b>'

          html.codemetadock.env.MetadockHtmlNamespace.code: (self, content: str) -> strWraps a string in HTML code tags (<code></code>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.code('This is code text.') }}").render()
          '<code>This is code text.</code>'

          html.codeblockmetadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> strWraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
          '<pre><code> This is code text.</code></pre>'

          html.detailsmetadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> strWraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.details('This is details text.') }}").render()
          '<details>\nThis is details text.\n</details>'

          html.italicmetadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> strWraps a string in HTML italic tags (<i></i>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
          '<i>This is italic text.</i>'

          html.summarymetadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> strWraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
          '<summary>\nThis is summary text.\n</summary>'

          html.underlinemetadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> strWraps a string in HTML underline tags (<u></u>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
          '<u>This is underlined text.</u>'

          @@ -415,11 +534,26 @@ Jinja macro reference Jinja filter reference -| Filter | Signature | Doc | -| --- | --- | --- | -| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '<p>This is a paragraph.</p>' \| html.escape }}").render()
          '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

          | -| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
          'This is a multi-line string.<br>This is the second line.<br>And the third.'

          | - + + + + + + + + + + + + + + + + + + + +
          FilterSignatureDoc
          html.escapemetadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> strFilter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '<p>This is a paragraph.</p>' | html.escape }}").render()
          '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

          html.inlinemetadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> strFilter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
          'This is a multi-line string.<br>This is the second line.<br>And the third.'

          diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index 503a4d9..9c0ffd1 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -130,9 +130,9 @@ and filters which can be used to make formatting content easier. The macros and {%- endset -%} {{ namespace_intro }} -{{ html.details(html.summary("Jinja macro reference"), ns_macro_table) }} +{{ html.details(html.summary("Jinja macro reference"), ns_macro_table | md.convert) }} -{{ html.details(html.summary("Jinja filter reference"), ns_filter_table) }} +{{ html.details(html.summary("Jinja filter reference"), ns_filter_table | md.convert) }} {% endfor %} diff --git a/README.md b/README.md index 5b7486e..f396cf7 100644 --- a/README.md +++ b/README.md @@ -303,10 +303,21 @@ Jinja namespace for the global Metadock environment, including all global macros Jinja macro reference -| Macro | Signature | Doc | -| --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
          This is a debug message.
          'No changes!'

          | - + + + + + + + + + + + + + + +
          MacroSignatureDoc
          debugmetadock.env.MetadockEnv.debug: (self, message: str) -> NonePrints a debug message to stdout, and returns an empty string.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
          This is a debug message.
          'No changes!'

          @@ -314,14 +325,41 @@ Jinja macro reference Jinja filter reference -| Filter | Signature | Doc | -| --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
          'first 1 second 2'

          | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
          'This is a multi-line string. This is the second line. And the third.'

          | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
          'PrefixThis is a string.'
          >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
          'Prefix : This is a string.'

          | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
          'This is a stringSuffix'
          >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
          'This is a string : Suffix'

          | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
          "[('a', 1), ('b', 2), ('c', 3)]"

          | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          FilterSignatureDoc
          chainmetadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]Filter which flattens a sequence of iterables into a single iterable.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
          'first 1 second 2'

          inlinemetadock.env.MetadockEnv.inline_filter: (self, value: str) -> strFilter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
          'This is a multi-line string. This is the second line. And the third.'

          with_prefixmetadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> strFilter which prepends a prefix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
          'PrefixThis is a string.'
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
          'Prefix : This is a string.'

          with_suffixmetadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> strFilter which appends a suffix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
          'This is a stringSuffix'
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
          'This is a string : Suffix'

          zipmetadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]Filter which zips an input iterable with one or more iterables.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
          "[('a', 1), ('b', 2), ('c', 3)]"

          ### `md` namespace @@ -349,15 +387,46 @@ Jinja Namespace for Markdown-related functions and filters. Jinja macro reference -| Macro | Signature | Doc | -| --- | --- | --- | -| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
          '> This is a blockquote.'

          | -| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
          '`This is an inline code block.`'

          | -| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
          '```sh\nThis is a codeblock.\n```'

          | -| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
          ... ).render()
          '- This is a list.\n - This is a sublist,\n - in two pieces.'

          | -| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
          ... ).render()
          '\| <b>Column 1</b> \| <b>Column 2</b> \| <b>Column 3</b> \|\n\| --- \| --- \| --- \|'

          | -| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
          ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
          ... ).render()
          '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'

          | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          MacroSignatureDoc
          md.blockquotemetadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> strProduces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
          '> This is a blockquote.'

          md.codemetadock.env.MetadockMdNamespace.code: (self, content: str) -> strProduces a Markdown inline code block from the given content by wrapping the string in graves ("`").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
          '`This is an inline code block.`'

          md.codeblockmetadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> strProduces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
          'sh\nThis is a codeblock.\n'

          md.listmetadock.env.MetadockMdNamespace.list: (self, *items: str) -> strProduces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
          ... ).render()
          '- This is a list.\n - This is a sublist,\n - in two pieces.'

          md.tableheadmetadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> strProduces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
          ... ).render()
          '| <b>Column 1</b> | <b>Column 2</b> | <b>Column 3</b> |\n| --- | --- | --- |'

          md.tablerowmetadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> strProduces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
          ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
          ... ).render()
          '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'

          @@ -365,11 +434,26 @@ Jinja macro reference Jinja filter reference -| Filter | Signature | Doc | -| --- | --- | --- | -| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert`.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
          '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

          | -| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
          ... ).render()
          '- This is a list.\n- This is a second element\n'

          | - + + + + + + + + + + + + + + + + + + + +
          FilterSignatureDoc
          md.convertmetadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> strFilter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
          '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

          md.listmetadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> strFilter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
          ... ).render()
          '- This is a list.\n- This is a second element\n'

          ### `html` namespace @@ -398,16 +482,51 @@ Jinja namespace which owns HTML-related functions and filters. Jinja macro reference -| Macro | Signature | Doc | -| --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
          '<b>This is bold text.</b>'

          | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.code('This is code text.') }}").render()
          '<code>This is code text.</code>'

          | -| html.codeblock | metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
          '<pre><code> This is code text.</code></pre>'

          | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.details('This is details text.') }}").render()
          '<details>\nThis is details text.\n</details>'

          | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
          '<i>This is italic text.</i>'

          | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
          '<summary>\nThis is summary text.\n</summary>'

          | -| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
          '<u>This is underlined text.</u>'

          | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          MacroSignatureDoc
          html.boldmetadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> strWraps a string in HTML bold tags (<b></b>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
          '<b>This is bold text.</b>'

          html.codemetadock.env.MetadockHtmlNamespace.code: (self, content: str) -> strWraps a string in HTML code tags (<code></code>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.code('This is code text.') }}").render()
          '<code>This is code text.</code>'

          html.codeblockmetadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> strWraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
          '<pre><code> This is code text.</code></pre>'

          html.detailsmetadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> strWraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.details('This is details text.') }}").render()
          '<details>\nThis is details text.\n</details>'

          html.italicmetadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> strWraps a string in HTML italic tags (<i></i>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
          '<i>This is italic text.</i>'

          html.summarymetadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> strWraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
          '<summary>\nThis is summary text.\n</summary>'

          html.underlinemetadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> strWraps a string in HTML underline tags (<u></u>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
          '<u>This is underlined text.</u>'

          @@ -415,11 +534,26 @@ Jinja macro reference Jinja filter reference -| Filter | Signature | Doc | -| --- | --- | --- | -| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '<p>This is a paragraph.</p>' \| html.escape }}").render()
          '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

          | -| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
          'This is a multi-line string.<br>This is the second line.<br>And the third.'

          | - + + + + + + + + + + + + + + + + + + + +
          FilterSignatureDoc
          html.escapemetadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> strFilter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '<p>This is a paragraph.</p>' | html.escape }}").render()
          '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

          html.inlinemetadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> strFilter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
          'This is a multi-line string.<br>This is the second line.<br>And the third.'

          diff --git a/metadock/env.py b/metadock/env.py index 69f0bfc..5d7b58c 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -4,7 +4,7 @@ from typing import Annotated, Any, Iterable, Literal, Sequence import jinja2 -import marko +from marko.ext.gfm import gfm def _is_nonstr_iter(item: Any) -> bool: @@ -178,7 +178,7 @@ def tablehead(self, *header_cells: str, bold: bool = False) -> str: return self.tablerow(*_pipe_escaped_cells) + "\n" + self.tablerow(*(["---"] * len(_pipe_escaped_cells))) def convert_filter(self, md_content: str) -> str: - """Filter which converts Markdown content to HTML, by invoking `marko.convert`. + """Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md). Args: md_content (str): The Markdown content to be converted to HTML. @@ -186,7 +186,7 @@ def convert_filter(self, md_content: str) -> str: Returns: str: The HTML content. """ - return marko.convert(md_content) + return gfm.convert(md_content) def list_filter(self, values: str | Iterable[str]) -> str: """Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list From 86d6ec95a42aa23396727112e4351176d1be2350 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 11:55:15 -0800 Subject: [PATCH 16/22] committing test --- test.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test.md diff --git a/test.md b/test.md new file mode 100644 index 0000000..ae48cb8 --- /dev/null +++ b/test.md @@ -0,0 +1,5 @@ +Table: + +| Col 1 | Col 2 | +| --- | --- | +| Item | Item explanation

          This is one line,
          This is another.
          | \ No newline at end of file From 3aa4ef1e7ee3365f4b9bd5a9930a57d1fec89f53 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 13:42:42 -0800 Subject: [PATCH 17/22] committing pre_test --- pre_test.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 pre_test.md diff --git a/pre_test.md b/pre_test.md new file mode 100644 index 0000000..4133e6b --- /dev/null +++ b/pre_test.md @@ -0,0 +1,5 @@ +Table: + +| Col 1 | Col 2 | +| --- | --- | +| Item | Item explanation

          This is one line,
          This is another.
          | \ No newline at end of file From ea1291fa06906dfd56c9ee520cb49ff4599a3da0 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 13:52:14 -0800 Subject: [PATCH 18/22] using html.pre for multiline code blocks --- .../content_schematics/jinja_helpers/html.yml | 14 +- .metadock/generated_documents/README.html | 68 +++--- .metadock/generated_documents/README.md | 216 ++++-------------- .../jinja-md.code-snippets | 8 +- .../repo_readme_template.md | 12 +- .vscode/jinja-md.code-snippets | 8 +- README.md | 216 ++++-------------- metadock/env.py | 32 +-- 8 files changed, 150 insertions(+), 424 deletions(-) diff --git a/.metadock/content_schematics/jinja_helpers/html.yml b/.metadock/content_schematics/jinja_helpers/html.yml index 2c9131c..e47437a 100644 --- a/.metadock/content_schematics/jinja_helpers/html.yml +++ b/.metadock/content_schematics/jinja_helpers/html.yml @@ -50,22 +50,22 @@ html: snippet_body: - html.code($1) - codeblock: + pre: docstring: | - Wraps a string in preformatted HTML code tags (
          ), and indents the content by the + Wraps a string in preformatted HTML pre tags (
          ), and indents the content by the
                   given amount.
                 example: |
                   >>> from metadock.env import MetadockEnv
                   >>> env = MetadockEnv().jinja_environment()
          -        >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
          -        '
              This is code text.
          ' + >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render() + '
              This is code text.
          ' source_file: metadock/env.py - method_name: metadock.env.MetadockHtmlNamespace.codeblock + method_name: metadock.env.MetadockHtmlNamespace.pre signature: "(self, content: str, indent: int = 0) -> str" intellisense: - snippet_key: HTML codeblock + snippet_key: HTML pre snippet_body: - - html.codeblock($1) + - html.pre($1) details: docstring: | diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 2a87279..6e99d80 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -280,10 +280,9 @@

          Global namespace

          debug metadock.env.MetadockEnv.debug: (self, message: str) -> None -Prints a debug message to stdout, and returns an empty string.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
          This is a debug message.
          'No changes!'

          +Prints a debug message to stdout, and returns an empty string.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
          This is a debug message.
          'No changes!'
          - - +
          Jinja filter reference @@ -300,30 +299,29 @@

          Global namespace

          chain metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] -Filter which flattens a sequence of iterables into a single iterable.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
          'first 1 second 2'

          +Filter which flattens a sequence of iterables into a single iterable.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
          'first 1 second 2'
          inline metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str -Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
          'This is a multi-line string. This is the second line. And the third.'

          +Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
          'This is a multi-line string. This is the second line. And the third.'
          with_prefix metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str -Filter which prepends a prefix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
          'PrefixThis is a string.'
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
          'Prefix : This is a string.'

          +Filter which prepends a prefix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
          'PrefixThis is a string.'
          >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
          'Prefix : This is a string.'
          with_suffix metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str -Filter which appends a suffix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
          'This is a stringSuffix'
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
          'This is a string : Suffix'

          +Filter which appends a suffix to a string, with an optional separator.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
          'This is a stringSuffix'
          >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
          'This is a string : Suffix'
          zip metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] -Filter which zips an input iterable with one or more iterables.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
          "[('a', 1), ('b', 2), ('c', 3)]"

          +Filter which zips an input iterable with one or more iterables.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
          "[('a', 1), ('b', 2), ('c', 3)]"
          - -
          +

          md namespace

          Jinja Namespace for Markdown-related functions and filters.

          Macros:

          @@ -354,35 +352,34 @@

          md namespace

          md.blockquote metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str -Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
          '> This is a blockquote.'

          +Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
          '> This is a blockquote.'
          md.code metadock.env.MetadockMdNamespace.code: (self, content: str) -> str -Produces a Markdown inline code block from the given content by wrapping the string in graves ("`").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
          '`This is an inline code block.`'

          +Produces a Markdown inline code block from the given content by wrapping the string in graves ("`").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
          '`This is an inline code block.`'
          md.codeblock metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str -Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
          'sh\nThis is a codeblock.\n'

          +Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
          'sh\nThis is a codeblock.\n'
          md.list metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str -Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
          ... ).render()
          '- This is a list.\n - This is a sublist,\n - in two pieces.'

          +Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
          ... ).render()
          '- This is a list.\n - This is a sublist,\n - in two pieces.'
          md.tablehead metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str -Produces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
          ... ).render()
          '| <b>Column 1</b> | <b>Column 2</b> | <b>Column 3</b> |\n| --- | --- | --- |'

          +Produces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
          ... ).render()
          '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |'
          md.tablerow metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str -Produces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
          ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
          ... ).render()
          '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'

          +Produces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
          ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
          ... ).render()
          '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'
          - - +
          Jinja filter reference @@ -399,15 +396,14 @@

          md namespace

          md.convert metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str -Filter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
          '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

          +Filter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
          '

          This is a heading

          \n
          \n

          And a block quote.

          \n
          \n'
          md.list metadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> str -Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
          ... ).render()
          '- This is a list.\n- This is a second element\n'

          +Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string(
          ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
          ... ).render()
          '- This is a list.\n- This is a second element\n'
          - -
          +

          html namespace

          Jinja namespace which owns HTML-related functions and filters.

          Macros:

          @@ -439,40 +435,39 @@

          html namespace

          html.bold metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str -Wraps a string in HTML bold tags (<b></b>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
          '<b>This is bold text.</b>'

          +Wraps a string in HTML bold tags (<b></b>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
          'This is bold text.'
          html.code metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str -Wraps a string in HTML code tags (<code></code>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.code('This is code text.') }}").render()
          '<code>This is code text.</code>'

          +Wraps a string in HTML code tags (<code></code>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.code('This is code text.') }}").render()
          'This is code text.'
          -html.codeblock -metadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> str -Wraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
          '<pre><code> This is code text.</code></pre>'

          +html.pre +metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str +Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
          '
              This is code text.
          '
          html.details metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str -Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.details('This is details text.') }}").render()
          '<details>\nThis is details text.\n</details>'

          +Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.details('This is details text.') }}").render()
          '
          \nThis is details text.\n
          '
          html.italic metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str -Wraps a string in HTML italic tags (<i></i>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
          '<i>This is italic text.</i>'

          +Wraps a string in HTML italic tags (<i></i>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
          'This is italic text.'
          html.summary metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str -Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
          '<summary>\nThis is summary text.\n</summary>'

          +Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
          '\nThis is summary text.\n'
          html.underline metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str -Wraps a string in HTML underline tags (<u></u>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
          '<u>This is underlined text.</u>'

          +Wraps a string in HTML underline tags (<u></u>).

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
          'This is underlined text.'
          - - +
          Jinja filter reference @@ -489,15 +484,14 @@

          html namespace

          html.escape metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str -Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '<p>This is a paragraph.</p>' | html.escape }}").render()
          '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

          +Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ '

          This is a paragraph.

          ' | html.escape }}").render()
          '<p>This is a paragraph.</p>'
          html.inline metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str -Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
          'This is a multi-line string.<br>This is the second line.<br>And the third.'

          +Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

          >>> from metadock.env import MetadockEnv
          >>> env = MetadockEnv().jinja_environment()
          >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
          'This is a multi-line string.
          This is the second line.
          And the third.'
          - -
          +

          Acknowledgements

          Author:

            diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index f396cf7..f0d27b1 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -303,21 +303,10 @@ Jinja namespace for the global Metadock environment, including all global macros Jinja macro reference - - - - - - - - - - - - - - -
            MacroSignatureDoc
            debugmetadock.env.MetadockEnv.debug: (self, message: str) -> NonePrints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'

            +| Macro | Signature | Doc | +| --- | --- | --- | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'
            | +
            @@ -325,41 +314,14 @@ Jinja macro reference Jinja filter reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            FilterSignatureDoc
            chainmetadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
            'first 1 second 2'

            inlinemetadock.env.MetadockEnv.inline_filter: (self, value: str) -> strFilter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'

            with_prefixmetadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> strFilter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'

            with_suffixmetadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> strFilter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'

            zipmetadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"

            +| Filter | Signature | Doc | +| --- | --- | --- | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
            'first 1 second 2'
            | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            | +
            ### `md` namespace @@ -387,46 +349,15 @@ Jinja Namespace for Markdown-related functions and filters. Jinja macro reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            MacroSignatureDoc
            md.blockquotemetadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> strProduces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'

            md.codemetadock.env.MetadockMdNamespace.code: (self, content: str) -> strProduces a Markdown inline code block from the given content by wrapping the string in graves ("`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'

            md.codeblockmetadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> strProduces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            'sh\nThis is a codeblock.\n'

            md.listmetadock.env.MetadockMdNamespace.list: (self, *items: str) -> strProduces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'

            md.tableheadmetadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> strProduces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '| <b>Column 1</b> | <b>Column 2</b> | <b>Column 3</b> |\n| --- | --- | --- |'

            md.tablerowmetadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> strProduces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'

            +| Macro | Signature | Doc | +| --- | --- | --- | +| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'
            | +| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'
            | +| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            '```sh\nThis is a codeblock.\n```'
            | +| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'
            | +| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|'
            | +| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'
            | +
            @@ -434,26 +365,11 @@ Jinja macro reference Jinja filter reference - - - - - - - - - - - - - - - - - - - -
            FilterSignatureDoc
            md.convertmetadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> strFilter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
            '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

            md.listmetadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> strFilter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'

            +| Filter | Signature | Doc | +| --- | --- | --- | +| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
            '

            This is a heading

            \n
            \n

            And a block quote.

            \n
            \n'
            | +| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'
            | +
            ### `html` namespace @@ -482,51 +398,16 @@ Jinja namespace which owns HTML-related functions and filters. Jinja macro reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            MacroSignatureDoc
            html.boldmetadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> strWraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            '<b>This is bold text.</b>'

            html.codemetadock.env.MetadockHtmlNamespace.code: (self, content: str) -> strWraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            '<code>This is code text.</code>'

            html.codeblockmetadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> strWraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
            '<pre><code> This is code text.</code></pre>'

            html.detailsmetadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> strWraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '<details>\nThis is details text.\n</details>'

            html.italicmetadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> strWraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            '<i>This is italic text.</i>'

            html.summarymetadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> strWraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '<summary>\nThis is summary text.\n</summary>'

            html.underlinemetadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> strWraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            '<u>This is underlined text.</u>'

            +| Macro | Signature | Doc | +| --- | --- | --- | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            'This is bold text.'
            | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            'This is code text.'
            | +| html.pre | metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '
            \nThis is details text.\n
            '
            | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            'This is italic text.'
            | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '\nThis is summary text.\n'
            | +| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            'This is underlined text.'
            | +
            @@ -534,26 +415,11 @@ Jinja macro reference Jinja filter reference - - - - - - - - - - - - - - - - - - - -
            FilterSignatureDoc
            html.escapemetadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> strFilter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '<p>This is a paragraph.</p>' | html.escape }}").render()
            '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

            html.inlinemetadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> strFilter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
            'This is a multi-line string.<br>This is the second line.<br>And the third.'

            +| Filter | Signature | Doc | +| --- | --- | --- | +| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '

            This is a paragraph.

            ' \| html.escape }}").render()
            '<p>This is a paragraph.</p>'
            | +| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
            'This is a multi-line string.
            This is the second line.
            And the third.'
            | +
            diff --git a/.metadock/generated_documents/jinja-md.code-snippets b/.metadock/generated_documents/jinja-md.code-snippets index 6c9e6e2..56d51e8 100644 --- a/.metadock/generated_documents/jinja-md.code-snippets +++ b/.metadock/generated_documents/jinja-md.code-snippets @@ -143,13 +143,13 @@ "description": "HTML code macro" }, - "(macro) HTML codeblock": { + "(macro) HTML pre": { "scope": "jinja-md,md", - "prefix": "html.codeblock", + "prefix": "html.pre", "body": [ - "html.codeblock($1)" + "html.pre($1)" ], - "description": "HTML codeblock macro" + "description": "HTML pre macro" }, "(macro) HTML details": { diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index 9c0ffd1..6bc7d13 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -109,8 +109,8 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ macro), html.code(macro_spec.get("method_name") ~ ": " ~ macro_spec.get("signature")), - (macro_spec.get("docstring") | inline | html.escape) ~ "

            " ~ (md.codeblock(macro_spec.get("example")) - | md.convert | html.inline), + (macro_spec.get("docstring") | inline | html.escape) ~ "

            " ~ (html.pre(macro_spec.get("example")) + | html.inline), ) }} {% endfor -%} @@ -122,17 +122,17 @@ and filters which can be used to make formatting content easier. The macros and md.tablerow( html.code(ns_code_prefix ~ filter), html.code(filter_spec.get("method_name") ~ ": " ~ filter_spec.get("signature")), - (filter_spec.get("docstring") | inline | html.escape) ~ "

            " ~ (md.codeblock(filter_spec.get("example")) - | md.convert | html.inline), + (filter_spec.get("docstring") | inline | html.escape) ~ "

            " ~ (html.pre(filter_spec.get("example")) + | html.inline), ) }} {% endfor -%} {%- endset -%} {{ namespace_intro }} -{{ html.details(html.summary("Jinja macro reference"), ns_macro_table | md.convert) }} +{{ html.details(html.summary("Jinja macro reference"), ns_macro_table) }} -{{ html.details(html.summary("Jinja filter reference"), ns_filter_table | md.convert) }} +{{ html.details(html.summary("Jinja filter reference"), ns_filter_table) }} {% endfor %} diff --git a/.vscode/jinja-md.code-snippets b/.vscode/jinja-md.code-snippets index 6c9e6e2..56d51e8 100644 --- a/.vscode/jinja-md.code-snippets +++ b/.vscode/jinja-md.code-snippets @@ -143,13 +143,13 @@ "description": "HTML code macro" }, - "(macro) HTML codeblock": { + "(macro) HTML pre": { "scope": "jinja-md,md", - "prefix": "html.codeblock", + "prefix": "html.pre", "body": [ - "html.codeblock($1)" + "html.pre($1)" ], - "description": "HTML codeblock macro" + "description": "HTML pre macro" }, "(macro) HTML details": { diff --git a/README.md b/README.md index f396cf7..f0d27b1 100644 --- a/README.md +++ b/README.md @@ -303,21 +303,10 @@ Jinja namespace for the global Metadock environment, including all global macros Jinja macro reference - - - - - - - - - - - - - - -
            MacroSignatureDoc
            debugmetadock.env.MetadockEnv.debug: (self, message: str) -> NonePrints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'

            +| Macro | Signature | Doc | +| --- | --- | --- | +| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'
            | +
            @@ -325,41 +314,14 @@ Jinja macro reference Jinja filter reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            FilterSignatureDoc
            chainmetadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
            'first 1 second 2'

            inlinemetadock.env.MetadockEnv.inline_filter: (self, value: str) -> strFilter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'

            with_prefixmetadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> strFilter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'

            with_suffixmetadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> strFilter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'

            zipmetadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"

            +| Filter | Signature | Doc | +| --- | --- | --- | +| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
            'first 1 second 2'
            | +| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | +| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | +| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | +| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            | +
            ### `md` namespace @@ -387,46 +349,15 @@ Jinja Namespace for Markdown-related functions and filters. Jinja macro reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            MacroSignatureDoc
            md.blockquotemetadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> strProduces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'

            md.codemetadock.env.MetadockMdNamespace.code: (self, content: str) -> strProduces a Markdown inline code block from the given content by wrapping the string in graves ("`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'

            md.codeblockmetadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> strProduces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            'sh\nThis is a codeblock.\n'

            md.listmetadock.env.MetadockMdNamespace.list: (self, *items: str) -> strProduces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'

            md.tableheadmetadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> strProduces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '| <b>Column 1</b> | <b>Column 2</b> | <b>Column 3</b> |\n| --- | --- | --- |'

            md.tablerowmetadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> strProduces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'

            +| Macro | Signature | Doc | +| --- | --- | --- | +| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'
            | +| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'
            | +| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            '```sh\nThis is a codeblock.\n```'
            | +| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'
            | +| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|'
            | +| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'
            | +
            @@ -434,26 +365,11 @@ Jinja macro reference Jinja filter reference - - - - - - - - - - - - - - - - - - - -
            FilterSignatureDoc
            md.convertmetadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> strFilter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
            '<h1>This is a heading</h1>\n<blockquote>\n<p>And a block quote.</p>\n</blockquote>\n'

            md.listmetadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> strFilter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'

            +| Filter | Signature | Doc | +| --- | --- | --- | +| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
            '

            This is a heading

            \n
            \n

            And a block quote.

            \n
            \n'
            | +| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'
            | +
            ### `html` namespace @@ -482,51 +398,16 @@ Jinja namespace which owns HTML-related functions and filters. Jinja macro reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            MacroSignatureDoc
            html.boldmetadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> strWraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            '<b>This is bold text.</b>'

            html.codemetadock.env.MetadockHtmlNamespace.code: (self, content: str) -> strWraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            '<code>This is code text.</code>'

            html.codeblockmetadock.env.MetadockHtmlNamespace.codeblock: (self, content: str, indent: int = 0) -> strWraps a string in preformatted HTML code tags (<pre><code></code></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.codeblock('This is code text.', indent = 4) }}").render()
            '<pre><code> This is code text.</code></pre>'

            html.detailsmetadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> strWraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '<details>\nThis is details text.\n</details>'

            html.italicmetadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> strWraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            '<i>This is italic text.</i>'

            html.summarymetadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> strWraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '<summary>\nThis is summary text.\n</summary>'

            html.underlinemetadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> strWraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            '<u>This is underlined text.</u>'

            +| Macro | Signature | Doc | +| --- | --- | --- | +| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            'This is bold text.'
            | +| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            'This is code text.'
            | +| html.pre | metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            | +| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '
            \nThis is details text.\n
            '
            | +| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            'This is italic text.'
            | +| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '\nThis is summary text.\n'
            | +| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            'This is underlined text.'
            | +
            @@ -534,26 +415,11 @@ Jinja macro reference Jinja filter reference - - - - - - - - - - - - - - - - - - - -
            FilterSignatureDoc
            html.escapemetadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> strFilter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '<p>This is a paragraph.</p>' | html.escape }}").render()
            '&lt;p&gt;This is a paragraph.&lt;/p&gt;'

            html.inlinemetadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> strFilter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
            'This is a multi-line string.<br>This is the second line.<br>And the third.'

            +| Filter | Signature | Doc | +| --- | --- | --- | +| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '

            This is a paragraph.

            ' \| html.escape }}").render()
            '<p>This is a paragraph.</p>'
            | +| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
            'This is a multi-line string.
            This is the second line.
            And the third.'
            | +
            diff --git a/metadock/env.py b/metadock/env.py index 5d7b58c..7b5bcbb 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -210,9 +210,9 @@ class MetadockHtmlNamespace(MetadockNamespace): bold code - codeblock details italic + pre summary underline @@ -222,7 +222,7 @@ class MetadockHtmlNamespace(MetadockNamespace): inline """ - exports = ["bold", "code", "codeblock", "details", "italic", "summary", "underline"] + exports = ["bold", "code", "details", "italic", "pre", "summary", "underline"] filters = ["escape", "inline"] def bold(self, content: str) -> str: @@ -247,20 +247,6 @@ def code(self, content: str) -> str: """ return f"{content}" - def codeblock(self, content: str, indent: int = 0) -> str: - """Wraps a string in preformatted HTML code tags (
            ), and indents the content by the - given amount. - - Args: - content (str): The content to be formatted as code. - indent (int, optional): Number of spaces which should be used to indent the contents. Defaults to 0. - - Returns: - str: The HTML code block content. - """ - indented_content = " " * indent + content.replace("\n", "\n" + " " * indent) - return f"
            {indented_content}
            " - def details(self, *contents: str) -> str: """Wraps a string in HTML details tags (
            ). Multiple arguments get separated by two line breaks. @@ -286,6 +272,20 @@ def italic(self, content: str) -> str: """ return f"{content}" + def pre(self, content: str, indent: int = 0) -> str: + """Wraps a string in preformatted HTML pre tags (
            ), and indents the content by the
            +        given amount.
            +
            +        Args:
            +            content (str): The content to be formatted as pre-formatted code.
            +            indent (int, optional): Number of spaces which should be used to indent the contents. Defaults to 0.
            +
            +        Returns:
            +            str: The HTML code block content.
            +        """
            +        indented_content = " " * indent + content.replace("\n", "\n" + " " * indent)
            +        return f"
            {indented_content}
            " + def summary(self, content: str) -> str: """Wraps a string in HTML summary tags (). From d14970f6241152764272aca2643a9c21872ec8eb Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 14:32:52 -0800 Subject: [PATCH 19/22] fixing readme multiline code blocks --- .../jinja_helpers/global.yml | 34 ++-- .../content_schematics/jinja_helpers/html.yml | 49 ++--- .metadock/generated_documents/README.html | 190 ++++++++++-------- .metadock/generated_documents/README.md | 133 +++++++----- .../jinja-md.code-snippets | 26 ++- .../repo_readme_template.md | 61 +++++- .vscode/jinja-md.code-snippets | 26 ++- README.md | 133 +++++++----- metadock/env.py | 15 +- tests/test_env.py | 23 +++ 10 files changed, 421 insertions(+), 269 deletions(-) diff --git a/.metadock/content_schematics/jinja_helpers/global.yml b/.metadock/content_schematics/jinja_helpers/global.yml index fd52898..4532314 100644 --- a/.metadock/content_schematics/jinja_helpers/global.yml +++ b/.metadock/content_schematics/jinja_helpers/global.yml @@ -2,23 +2,6 @@ global: docstring: | Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces. - **Macros**: - - debug - - **Namespaces**: - - html - md - - **Filters**: - - chain - inline - with_prefix - with_suffix - zip - macros: debug: docstring: Prints a debug message to stdout, and returns an empty string. @@ -105,6 +88,23 @@ global: snippet_body: - with_suffix($1) + wrap: + docstring: | + Filter which wraps an inner string with a given outer string. + example: | + >>> from metadock.env import MetadockEnv + >>> env = MetadockEnv().jinja_environment() + >>> # Wrap with graves, like md.code(...) + >>> env.from_string("{{ 'This is a string.' | wrap('`') }}").render() + '`This is a string.`' + source_file: metadock/env.py + method_name: metadock.env.MetadockEnv.wrap_filter + signature: "(self, value: str, wrap: str) -> str" + intellisense: + snippet_key: Wrap text + snippet_body: + - wrap($1) + zip: docstring: | Filter which zips an input iterable with one or more iterables. diff --git a/.metadock/content_schematics/jinja_helpers/html.yml b/.metadock/content_schematics/jinja_helpers/html.yml index e47437a..b35e2aa 100644 --- a/.metadock/content_schematics/jinja_helpers/html.yml +++ b/.metadock/content_schematics/jinja_helpers/html.yml @@ -2,21 +2,6 @@ html: docstring: | Jinja namespace which owns HTML-related functions and filters. - **Macros**: - - bold - code - codeblock - details - italic - summary - underline - - **Filters**: - - escape - inline - macros: bold: docstring: | @@ -50,23 +35,6 @@ html: snippet_body: - html.code($1) - pre: - docstring: | - Wraps a string in preformatted HTML pre tags (
            ), and indents the content by the
            -        given amount.
            -      example: |
            -        >>> from metadock.env import MetadockEnv
            -        >>> env = MetadockEnv().jinja_environment()
            -        >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            -        '
                This is code text.
            ' - source_file: metadock/env.py - method_name: metadock.env.MetadockHtmlNamespace.pre - signature: "(self, content: str, indent: int = 0) -> str" - intellisense: - snippet_key: HTML pre - snippet_body: - - html.pre($1) - details: docstring: | Wraps a string in line-broken HTML details tags (
            ). Multiple arguments get separated by two @@ -100,6 +68,23 @@ html: snippet_body: - html.italic($1) + pre: + docstring: | + Wraps a string in preformatted HTML pre tags (
            ), and indents the content by the
            +        given amount.
            +      example: |
            +        >>> from metadock.env import MetadockEnv
            +        >>> env = MetadockEnv().jinja_environment()
            +        >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            +        '
                This is code text.
            ' + source_file: metadock/env.py + method_name: metadock.env.MetadockHtmlNamespace.pre + signature: "(self, content: str, indent: int = 0) -> str" + intellisense: + snippet_key: HTML pre + snippet_body: + - html.pre($1) + summary: docstring: | Wraps a string in line-broken HTML summary tags (\n\n). diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 6e99d80..9480caa 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -250,23 +250,14 @@

            Jinja Templating Helpers

            3 namespaces, documented below:

            Global namespace

            Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces.

            -

            Macros:

            -
            debug
            -
            -

            Namespaces:

            -
            html
            -md
            -
            -

            Filters:

            -
            chain
            -inline
            -with_prefix
            -with_suffix
            -zip
            -
            +

            Jinja macros

            +

            The following macros are available in the global namespace:

            +
              +
            • debug
            • +
            -Jinja macro reference +Jinja macro reference @@ -278,14 +269,24 @@

            Global namespace

            - - + +
            debugmetadock.env.MetadockEnv.debug: (self, message: str) -> None
            debug
            metadock.env.MetadockEnv.debug: (self, message: str) -> None
            Prints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'
            +

            Jinja filters

            +

            The following filters are available in the global namespace:

            +
              +
            • chain
            • +
            • inline
            • +
            • with_prefix
            • +
            • with_suffix
            • +
            • wrap
            • +
            • zip
            • +
            -Jinja filter reference +Jinja filter reference @@ -297,28 +298,33 @@

            Global namespace

            - - + + - - + + - - + + - - + + - - + + + + + + +
            chainmetadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]
            chain
            metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]
            Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() | chain | join(" ") }}').render()
            'first 1 second 2'
            inlinemetadock.env.MetadockEnv.inline_filter: (self, value: str) -> str
            inline
            metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str
            Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            with_prefixmetadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str
            with_prefix
            metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str
            Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' | with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            with_suffixmetadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str
            with_suffix
            metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str
            Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' | with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            zipmetadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]
            wrap
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' | wrap('') }}").render()<br>'This is a string.`'
            zip
            metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]
            Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] | zip([1, 2, 3]) | list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            @@ -336,9 +342,19 @@

            md namespace

            convert
             list
             
            +

            Jinja macros

            +

            The following macros are available in the md namespace:

            +
              +
            • md.blockquote
            • +
            • md.code
            • +
            • md.codeblock
            • +
            • md.list
            • +
            • md.tablehead
            • +
            • md.tablerow
            • +
            -Jinja macro reference +Jinja macro reference @@ -350,39 +366,45 @@

            md namespace

            - - + + - - + + - - + + - - + + - - + + - - + +
            md.blockquotemetadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str
            md.blockquote
            metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str
            Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'
            md.codemetadock.env.MetadockMdNamespace.code: (self, content: str) -> str
            md.code
            metadock.env.MetadockMdNamespace.code: (self, content: str) -> str
            Produces a Markdown inline code block from the given content by wrapping the string in graves ("`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'
            md.codeblockmetadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str
            md.codeblock
            metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str
            Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("```"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            'sh\nThis is a codeblock.\n'
            md.listmetadock.env.MetadockMdNamespace.list: (self, *items: str) -> str
            md.list
            metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str
            Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'
            md.tableheadmetadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str
            md.tablehead
            metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str
            Produces a Markdown table header from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\"). To bold the header cell contents, supply bold = true.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |'
            md.tablerowmetadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str
            md.tablerow
            metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str
            Produces a Markdown table row from the given cells by joining each cell with pipes ("|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '| Column 1 | Column 2 | Column 3 |\n| --- | --- | --- |\n| Value 1 | Value 2 | Value 3 |'
            +

            Jinja filters

            +

            The following filters are available in the md namespace:

            +
              +
            • md.convert
            • +
            • md.list
            • +
            -Jinja filter reference +Jinja filter reference @@ -394,34 +416,32 @@

            md namespace

            - - + + - - + +
            md.convertmetadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str
            md.convert
            metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str
            Filter which converts Markdown content to HTML, by invoking marko.convert (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' | md.convert }}").render()
            '

            This is a heading

            \n
            \n

            And a block quote.

            \n
            \n'
            md.listmetadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> str
            md.list
            metadock.env.MetadockMdNamespace.list_filter: (self, values: str | Iterable[str]) -> str
            Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] | md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'

            html namespace

            Jinja namespace which owns HTML-related functions and filters.

            -

            Macros:

            -
            bold
            -code
            -codeblock
            -details
            -italic
            -summary
            -underline
            -
            -

            Filters:

            -
            escape
            -inline
            -
            +

            Jinja macros

            +

            The following macros are available in the html namespace:

            +
              +
            • html.bold
            • +
            • html.code
            • +
            • html.details
            • +
            • html.italic
            • +
            • html.pre
            • +
            • html.summary
            • +
            • html.underline
            • +
            -Jinja macro reference +Jinja macro reference @@ -433,44 +453,50 @@

            html namespace

            - - + + - - + + - - - - - - - + + - - + + - - + + + + + + + - - + +
            html.boldmetadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str
            html.bold
            metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str
            Wraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            'This is bold text.'
            html.codemetadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str
            html.code
            metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str
            Wraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            'This is code text.'
            html.premetadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> strWraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            html.detailsmetadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str
            html.details
            metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str
            Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '
            \nThis is details text.\n
            '
            html.italicmetadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str
            html.italic
            metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str
            Wraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            'This is italic text.'
            html.summarymetadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str
            html.pre
            metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str
            Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            html.summary
            metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str
            Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '\nThis is summary text.\n'
            html.underlinemetadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str
            html.underline
            metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str
            Wraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            'This is underlined text.'
            +

            Jinja filters

            +

            The following filters are available in the html namespace:

            +
              +
            • html.escape
            • +
            • html.inline
            • +
            -Jinja filter reference +Jinja filter reference @@ -482,13 +508,13 @@

            html namespace

            - - + + - - + +
            html.escapemetadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str
            html.escape
            metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str
            Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '

            This is a paragraph.

            ' | html.escape }}").render()
            '<p>This is a paragraph.</p>'
            html.inlinemetadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str
            html.inline
            metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str
            Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' | html.inline }}").render()
            'This is a multi-line string.
            This is the second line.
            And the third.'
            diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index f0d27b1..201b193 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -279,48 +279,49 @@ and filters which can be used to make formatting content easier. The macros and Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces. -**Macros**: - - debug - -**Namespaces**: - html - md -**Filters**: - - chain - inline - with_prefix - with_suffix - zip +#### Jinja macros +The following macros are available in the global namespace: +- `debug`
            -Jinja macro reference +Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'
            | +|
            debug
            |
            metadock.env.MetadockEnv.debug: (self, message: str) -> None
            | Prints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'
            |
            +#### Jinja filters + +The following filters are available in the global namespace: + +- `chain` +- `inline` +- `with_prefix` +- `with_suffix` +- `wrap` +- `zip` +
            -Jinja filter reference +Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
            'first 1 second 2'
            | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            | +|
            chain
            |
            metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]
            | Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
            'first 1 second 2'
            | +|
            inline
            |
            metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str
            | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | +|
            with_prefix
            |
            metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str
            | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | +|
            with_suffix
            |
            metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str
            | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | +|
            wrap
            |
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            | Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' \| wrap('`') }}").render()
            '`This is a string.`'
            | +|
            zip
            |
            metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]
            | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            |
            @@ -344,31 +345,49 @@ Jinja Namespace for Markdown-related functions and filters. +#### Jinja macros + +The following macros are available in the md namespace: + +- `md.blockquote` +- `md.code` +- `md.codeblock` +- `md.list` +- `md.tablehead` +- `md.tablerow` +
            -Jinja macro reference +Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'
            | -| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'
            | -| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            '```sh\nThis is a codeblock.\n```'
            | -| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'
            | -| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|'
            | -| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'
            | +|
            md.blockquote
            |
            metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str
            | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'
            | +|
            md.code
            |
            metadock.env.MetadockMdNamespace.code: (self, content: str) -> str
            | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'
            | +|
            md.codeblock
            |
            metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str
            | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            '```sh\nThis is a codeblock.\n```'
            | +|
            md.list
            |
            metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str
            | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'
            | +|
            md.tablehead
            |
            metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str
            | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|'
            | +|
            md.tablerow
            |
            metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str
            | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'
            |
            +#### Jinja filters + +The following filters are available in the md namespace: + +- `md.convert` +- `md.list` +
            -Jinja filter reference +Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
            '

            This is a heading

            \n
            \n

            And a block quote.

            \n
            \n'
            | -| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'
            | +|
            md.convert
            |
            metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str
            | Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
            '

            This is a heading

            \n
            \n

            And a block quote.

            \n
            \n'
            | +|
            md.list
            |
            metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str
            | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'
            |
            @@ -376,49 +395,53 @@ Jinja filter reference Jinja namespace which owns HTML-related functions and filters. -**Macros**: - bold - code - codeblock - details - italic - summary - underline -**Filters**: - - escape - inline +#### Jinja macros +The following macros are available in the html namespace: +- `html.bold` +- `html.code` +- `html.details` +- `html.italic` +- `html.pre` +- `html.summary` +- `html.underline`
            -Jinja macro reference +Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            'This is bold text.'
            | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            'This is code text.'
            | -| html.pre | metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '
            \nThis is details text.\n
            '
            | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            'This is italic text.'
            | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '\nThis is summary text.\n'
            | -| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            'This is underlined text.'
            | +|
            html.bold
            |
            metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str
            | Wraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            'This is bold text.'
            | +|
            html.code
            |
            metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str
            | Wraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            'This is code text.'
            | +|
            html.details
            |
            metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str
            | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '
            \nThis is details text.\n
            '
            | +|
            html.italic
            |
            metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str
            | Wraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            'This is italic text.'
            | +|
            html.pre
            |
            metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str
            | Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            | +|
            html.summary
            |
            metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str
            | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '\nThis is summary text.\n'
            | +|
            html.underline
            |
            metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str
            | Wraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            'This is underlined text.'
            |
            +#### Jinja filters + +The following filters are available in the html namespace: + +- `html.escape` +- `html.inline` +
            -Jinja filter reference +Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '

            This is a paragraph.

            ' \| html.escape }}").render()
            '<p>This is a paragraph.</p>'
            | -| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
            'This is a multi-line string.
            This is the second line.
            And the third.'
            | +|
            html.escape
            |
            metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str
            | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '

            This is a paragraph.

            ' \| html.escape }}").render()
            '<p>This is a paragraph.</p>'
            | +|
            html.inline
            |
            metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str
            | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
            'This is a multi-line string.
            This is the second line.
            And the third.'
            |
            diff --git a/.metadock/generated_documents/jinja-md.code-snippets b/.metadock/generated_documents/jinja-md.code-snippets index 56d51e8..d3d2231 100644 --- a/.metadock/generated_documents/jinja-md.code-snippets +++ b/.metadock/generated_documents/jinja-md.code-snippets @@ -42,6 +42,14 @@ ], "description": "With suffix filter" }, + "(filter) Wrap text": { + "scope": "jinja-md,md", + "prefix": "wrap", + "body": [ + "wrap($1)" + ], + "description": "Wrap text filter" + }, "(filter) Zip iterables": { "scope": "jinja-md,md", "prefix": "zip", @@ -143,15 +151,6 @@ "description": "HTML code macro" }, - "(macro) HTML pre": { - "scope": "jinja-md,md", - "prefix": "html.pre", - "body": [ - "html.pre($1)" - ], - "description": "HTML pre macro" - }, - "(macro) HTML details": { "scope": "jinja-md,md", "prefix": "html.details", @@ -170,6 +169,15 @@ "description": "HTML italic macro" }, + "(macro) HTML pre": { + "scope": "jinja-md,md", + "prefix": "html.pre", + "body": [ + "html.pre($1)" + ], + "description": "HTML pre macro" + }, + "(macro) HTML summary": { "scope": "jinja-md,md", "prefix": "html.summary", diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index 6bc7d13..c3cbf35 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -34,7 +34,7 @@ Each of the commands supports a programmatic invocation from the `metadock.Metad - Name: {{ md.code(python_interface.get("method_name")) }} - Signature: {{ md.code(python_interface.get("signature")) }} {%- endset -%} -{{ html.details(html.summary(html.code("metadock " ~ command)), (command_details | md.convert)) }} + {{ html.details(html.summary(html.code("metadock " ~ command)), (command_details | md.convert)) }} {% endfor %} ## Example Usage @@ -102,38 +102,81 @@ and filters which can be used to make formatting content easier. The macros and {{ namespace_spec.get("docstring") }} {% endset -%} +{%- set ns_macro_intro -%} +{%- if namespace_spec.get("macros", {}).keys() | length %} +The following macros are available in the {{ namespace }} namespace: + +{{ + namespace_spec.get("macros", {}).keys() + | map("with_prefix", ns_code_prefix) + | map("wrap", "`") + | md.list +}} +{%- else -%} +There are no macros available in the {{ namespace }} namespace. +{%- endif -%} +{%- endset -%} {%- set ns_macro_table -%} {{ md.tablehead("Macro", "Signature", "Doc", bold=true) }} {% for macro, macro_spec in namespace_spec.get("macros", {}).items() -%} {{ md.tablerow( - html.code(ns_code_prefix ~ macro), - html.code(macro_spec.get("method_name") ~ ": " ~ macro_spec.get("signature")), + html.pre(ns_code_prefix ~ macro), + html.pre(macro_spec.get("method_name") ~ ": " ~ macro_spec.get("signature")), (macro_spec.get("docstring") | inline | html.escape) ~ "

            " ~ (html.pre(macro_spec.get("example")) | html.inline), ) }} {% endfor -%} {%- endset -%} +{%- set ns_filter_intro -%} +{%- if namespace_spec.get("filters", {}).keys() | length %} +The following filters are available in the {{ namespace }} namespace: + +{{ + namespace_spec.get("filters", {}).keys() + | map("with_prefix", ns_code_prefix) + | map("wrap", "`") + | md.list +}} +{%- else -%} +There are no filters available in the {{ namespace }} namespace. +{%- endif -%} +{%- endset -%} {%- set ns_filter_table -%} {{ md.tablehead("Filter", "Signature", "Doc", bold=true) }} {% for filter, filter_spec in namespace_spec.get("filters", {}).items() -%} {{ md.tablerow( - html.code(ns_code_prefix ~ filter), - html.code(filter_spec.get("method_name") ~ ": " ~ filter_spec.get("signature")), - (filter_spec.get("docstring") | inline | html.escape) ~ "

            " ~ (html.pre(filter_spec.get("example")) - | html.inline), + html.pre(ns_code_prefix ~ filter), + html.pre(filter_spec.get("method_name") ~ ": " ~ filter_spec.get("signature")), + ( + filter_spec.get("docstring") + | inline + | html.escape + ) ~ "

            " ~ ( + html.pre(filter_spec.get("example")) + | html.inline + ), ) }} {% endfor -%} {%- endset -%} {{ namespace_intro }} -{{ html.details(html.summary("Jinja macro reference"), ns_macro_table) }} +#### Jinja macros +{{ ns_macro_intro }} + +{% if namespace_spec.get("macros", {}).keys() | length -%} +{{ html.details(html.summary(html.bold("Jinja macro reference")), ns_macro_table) }} +{%- endif %} -{{ html.details(html.summary("Jinja filter reference"), ns_filter_table) }} +#### Jinja filters +{{ ns_filter_intro }} +{% if namespace_spec.get("filters", {}).keys() | length -%} +{{ html.details(html.summary(html.bold("Jinja filter reference")), ns_filter_table) }} +{% endif %} {% endfor %} ## Acknowledgements diff --git a/.vscode/jinja-md.code-snippets b/.vscode/jinja-md.code-snippets index 56d51e8..d3d2231 100644 --- a/.vscode/jinja-md.code-snippets +++ b/.vscode/jinja-md.code-snippets @@ -42,6 +42,14 @@ ], "description": "With suffix filter" }, + "(filter) Wrap text": { + "scope": "jinja-md,md", + "prefix": "wrap", + "body": [ + "wrap($1)" + ], + "description": "Wrap text filter" + }, "(filter) Zip iterables": { "scope": "jinja-md,md", "prefix": "zip", @@ -143,15 +151,6 @@ "description": "HTML code macro" }, - "(macro) HTML pre": { - "scope": "jinja-md,md", - "prefix": "html.pre", - "body": [ - "html.pre($1)" - ], - "description": "HTML pre macro" - }, - "(macro) HTML details": { "scope": "jinja-md,md", "prefix": "html.details", @@ -170,6 +169,15 @@ "description": "HTML italic macro" }, + "(macro) HTML pre": { + "scope": "jinja-md,md", + "prefix": "html.pre", + "body": [ + "html.pre($1)" + ], + "description": "HTML pre macro" + }, + "(macro) HTML summary": { "scope": "jinja-md,md", "prefix": "html.summary", diff --git a/README.md b/README.md index f0d27b1..201b193 100644 --- a/README.md +++ b/README.md @@ -279,48 +279,49 @@ and filters which can be used to make formatting content easier. The macros and Jinja namespace for the global Metadock environment, including all global macros, filters, and namespaces. -**Macros**: - - debug - -**Namespaces**: - html - md -**Filters**: - - chain - inline - with_prefix - with_suffix - zip +#### Jinja macros +The following macros are available in the global namespace: +- `debug`
            -Jinja macro reference +Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| debug | metadock.env.MetadockEnv.debug: (self, message: str) -> None | Prints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'
            | +|
            debug
            |
            metadock.env.MetadockEnv.debug: (self, message: str) -> None
            | Prints a debug message to stdout, and returns an empty string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("No changes!{{ debug('This is a debug message.') }}").render()
            This is a debug message.
            'No changes!'
            |
            +#### Jinja filters + +The following filters are available in the global namespace: + +- `chain` +- `inline` +- `with_prefix` +- `with_suffix` +- `wrap` +- `zip` +
            -Jinja filter reference +Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| chain | metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any] | Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
            'first 1 second 2'
            | -| inline | metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | -| with_prefix | metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | -| with_suffix | metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | -| zip | metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]] | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            | +|
            chain
            |
            metadock.env.MetadockEnv.chain_filter: (self, iterables: Sequence[Iterable[Any]]) -> Iterable[Any]
            | Filter which flattens a sequence of iterables into a single iterable.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string('{{ {"first": 1, "second": 2}.items() \| chain \| join(" ") }}').render()
            'first 1 second 2'
            | +|
            inline
            |
            metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str
            | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | +|
            with_prefix
            |
            metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str
            | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | +|
            with_suffix
            |
            metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str
            | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | +|
            wrap
            |
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            | Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' \| wrap('`') }}").render()
            '`This is a string.`'
            | +|
            zip
            |
            metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]
            | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            |
            @@ -344,31 +345,49 @@ Jinja Namespace for Markdown-related functions and filters. +#### Jinja macros + +The following macros are available in the md namespace: + +- `md.blockquote` +- `md.code` +- `md.codeblock` +- `md.list` +- `md.tablehead` +- `md.tablerow` +
            -Jinja macro reference +Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| md.blockquote | metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'
            | -| md.code | metadock.env.MetadockMdNamespace.code: (self, content: str) -> str | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'
            | -| md.codeblock | metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            '```sh\nThis is a codeblock.\n```'
            | -| md.list | metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'
            | -| md.tablehead | metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|'
            | -| md.tablerow | metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'
            | +|
            md.blockquote
            |
            metadock.env.MetadockMdNamespace.blockquote: (self, content: str) -> str
            | Produces a Markdown blockquote from the given content by prepending each line with a gt symbol ("> ").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.blockquote('This is a blockquote.') }}").render()
            '> This is a blockquote.'
            | +|
            md.code
            |
            metadock.env.MetadockMdNamespace.code: (self, content: str) -> str
            | Produces a Markdown inline code block from the given content by wrapping the string in graves ("\`").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.code('This is an inline code block.') }}").render()
            '`This is an inline code block.`'
            | +|
            md.codeblock
            |
            metadock.env.MetadockMdNamespace.codeblock: (self, content: str, language: str = '') -> str
            | Produces a Markdown codeblock from the given content by wrapping the string in triple-graves ("\`\`\`"), and optionally specifies a language.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ md.codeblock('This is a codeblock.', language = 'sh') }}").render()
            '```sh\nThis is a codeblock.\n```'
            | +|
            md.list
            |
            metadock.env.MetadockMdNamespace.list: (self, *items: str) -> str
            | Produces a Markdown list from the given content by prepending each line with a dash ("- "). If any of its arguments are, themselves, formatted as Markdown lists, then they are simply indented as sublists.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.list('This is a list.', md.list('This is a sublist,', 'in two pieces.')) }}"
            ... ).render()
            '- This is a list.\n - This is a sublist,\n - in two pieces.'
            | +|
            md.tablehead
            |
            metadock.env.MetadockMdNamespace.tablehead: (self, *header_cells: str, bold: bool = False) -> str
            | Produces a Markdown table header from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes, plus adding a header divider row. Cell contents have their pipes escaped with a backslash ("\\"). To bold the header cell contents, supply `bold = true`.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3', bold = true) }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|'
            | +|
            md.tablerow
            |
            metadock.env.MetadockMdNamespace.tablerow: (self, *row_cells: str) -> str
            | Produces a Markdown table row from the given cells by joining each cell with pipes ("\|") and wrapping the result in pipes. Cell contents have their pipes escaped with a backslash ("\\").

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ md.tablehead('Column 1', 'Column 2', 'Column 3') }}\n"
            ... "{{ md.tablerow('Value 1', 'Value 2', 'Value 3') }}"
            ... ).render()
            '\| Column 1 \| Column 2 \| Column 3 \|\n\| --- \| --- \| --- \|\n\| Value 1 \| Value 2 \| Value 3 \|'
            |
            +#### Jinja filters + +The following filters are available in the md namespace: + +- `md.convert` +- `md.list` +
            -Jinja filter reference +Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| md.convert | metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str | Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
            '

            This is a heading

            \n
            \n

            And a block quote.

            \n
            \n'
            | -| md.list | metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'
            | +|
            md.convert
            |
            metadock.env.MetadockMdNamespace.convert_filter: (self, md_content: str) -> str
            | Filter which converts Markdown content to HTML, by invoking `marko.convert` (using github-flavored md).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '# This is a heading\n\n> And a block quote.' \| md.convert }}").render()
            '

            This is a heading

            \n
            \n

            And a block quote.

            \n
            \n'
            | +|
            md.list
            |
            metadock.env.MetadockMdNamespace.list_filter: (self, values: str \| Iterable[str]) -> str
            | Filter which unpacks an iterable of values into a Markdown list, or formats a single value as a Markdown list element.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string(
            ... "{{ ['This is a list.', 'This is a second element'] \| md.list }}\n"
            ... ).render()
            '- This is a list.\n- This is a second element\n'
            |
            @@ -376,49 +395,53 @@ Jinja filter reference Jinja namespace which owns HTML-related functions and filters. -**Macros**: - bold - code - codeblock - details - italic - summary - underline -**Filters**: - - escape - inline +#### Jinja macros +The following macros are available in the html namespace: +- `html.bold` +- `html.code` +- `html.details` +- `html.italic` +- `html.pre` +- `html.summary` +- `html.underline`
            -Jinja macro reference +Jinja macro reference | Macro | Signature | Doc | | --- | --- | --- | -| html.bold | metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str | Wraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            'This is bold text.'
            | -| html.code | metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str | Wraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            'This is code text.'
            | -| html.pre | metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str | Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            | -| html.details | metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '
            \nThis is details text.\n
            '
            | -| html.italic | metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str | Wraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            'This is italic text.'
            | -| html.summary | metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '\nThis is summary text.\n'
            | -| html.underline | metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str | Wraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            'This is underlined text.'
            | +|
            html.bold
            |
            metadock.env.MetadockHtmlNamespace.bold: (self, content: str) -> str
            | Wraps a string in HTML bold tags (<b></b>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.bold('This is bold text.') }}").render()
            'This is bold text.'
            | +|
            html.code
            |
            metadock.env.MetadockHtmlNamespace.code: (self, content: str) -> str
            | Wraps a string in HTML code tags (<code></code>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.code('This is code text.') }}").render()
            'This is code text.'
            | +|
            html.details
            |
            metadock.env.MetadockHtmlNamespace.details: (self, *contents: str) -> str
            | Wraps a string in line-broken HTML details tags (<details></details>). Multiple arguments get separated by two line breaks.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.details('This is details text.') }}").render()
            '
            \nThis is details text.\n
            '
            | +|
            html.italic
            |
            metadock.env.MetadockHtmlNamespace.italic: (self, content: str) -> str
            | Wraps a string in HTML italic tags (<i></i>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.italic('This is italic text.') }}").render()
            'This is italic text.'
            | +|
            html.pre
            |
            metadock.env.MetadockHtmlNamespace.pre: (self, content: str, indent: int = 0) -> str
            | Wraps a string in preformatted HTML pre tags (<pre></pre>), and indents the content by the given amount.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.pre('This is code text.', indent = 4) }}").render()
            '
                This is code text.
            '
            | +|
            html.summary
            |
            metadock.env.MetadockHtmlNamespace.summary: (self, content: str) -> str
            | Wraps a string in line-broken HTML summary tags (<summary>\n\n</summary>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.summary('This is summary text.') }}").render()
            '\nThis is summary text.\n'
            | +|
            html.underline
            |
            metadock.env.MetadockHtmlNamespace.underline: (self, content: str) -> str
            | Wraps a string in HTML underline tags (<u></u>).

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ html.underline('This is underlined text.') }}").render()
            'This is underlined text.'
            |
            +#### Jinja filters + +The following filters are available in the html namespace: + +- `html.escape` +- `html.inline` +
            -Jinja filter reference +Jinja filter reference | Filter | Signature | Doc | | --- | --- | --- | -| html.escape | metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '

            This is a paragraph.

            ' \| html.escape }}").render()
            '<p>This is a paragraph.</p>'
            | -| html.inline | metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
            'This is a multi-line string.
            This is the second line.
            And the third.'
            | +|
            html.escape
            |
            metadock.env.MetadockHtmlNamespace.escape_filter: (self, content: str) -> str
            | Filter which escapes a string by replacing all HTML special characters with their HTML entity equivalents.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ '

            This is a paragraph.

            ' \| html.escape }}").render()
            '<p>This is a paragraph.</p>'
            | +|
            html.inline
            |
            metadock.env.MetadockHtmlNamespace.inline_filter: (self, content: str) -> str
            | Filter which inlines a string by replacing all newlines with HTML line-breaks <br> singleton tags.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| html.inline }}").render()
            'This is a multi-line string.
            This is the second line.
            And the third.'
            |
            diff --git a/metadock/env.py b/metadock/env.py index 7b5bcbb..76c0618 100644 --- a/metadock/env.py +++ b/metadock/env.py @@ -349,6 +349,7 @@ class MetadockEnv(MetadockNamespace): inline with_prefix with_suffix + wrap zip """ @@ -356,7 +357,7 @@ class MetadockEnv(MetadockNamespace): html = MetadockHtmlNamespace() exports = ["debug"] namespaces = ["html", "md"] - filters = ["chain", "inline", "with_prefix", "with_suffix", "zip"] + filters = ["chain", "inline", "with_prefix", "with_suffix", "wrap", "zip"] def debug(self, message: str) -> Literal[""]: """Prints a debug message to stdout, and returns an empty string.""" @@ -412,6 +413,18 @@ def with_suffix_filter(self, value: str, suffix: str, sep: str = "") -> str: """ return sep.join((value, suffix)) + def wrap_filter(self, value: str, wrap: str) -> str: + """Filter which wraps an inner string with a given outer string. + + Args: + value (str): Piped input string to be wrapped. + wrap (str): String to wrap the input string with. + + Returns: + str: The wrapped string. + """ + return wrap + value + wrap + def zip_filter(self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]: """Filter which zips an input iterable with one or more iterables. diff --git a/tests/test_env.py b/tests/test_env.py index 46cfb33..a4e860d 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -375,3 +375,26 @@ def test_env__inline(empty_metadock_project_dir): assert (project_dir / "generated_documents" / "example1.md").read_text() == ( """This is a paragraph with a line break. This is the second line.""" ) + + +def test_env__wrap(empty_metadock_project_dir): + project_dir = empty_metadock_project_dir + (project_dir / "templated_documents" / "simple.md").write_text("""{{ lines | join(", ") | wrap("||") }}""") + (project_dir / "content_schematics" / "schematic1.yml").write_text( + """ + content_schematics: + - name: example1 + template: simple.md + target_formats: [ md ] + context: + lines: + - line a + - line b + - line c + """ + ) + + metadock = MetadockProject(project_dir) + metadock.build() + + assert (project_dir / "generated_documents" / "example1.md").read_text() == ("""||line a, line b, line c||""") From 755b76d1cd283528cc132e65e7186ec7cb448ce0 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 17:46:07 -0800 Subject: [PATCH 20/22] escaping grave in metadock --- .metadock/content_schematics/jinja_helpers/global.yml | 4 ++-- .metadock/generated_documents/README.html | 2 +- .metadock/generated_documents/README.md | 2 +- README.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.metadock/content_schematics/jinja_helpers/global.yml b/.metadock/content_schematics/jinja_helpers/global.yml index 4532314..b92d753 100644 --- a/.metadock/content_schematics/jinja_helpers/global.yml +++ b/.metadock/content_schematics/jinja_helpers/global.yml @@ -95,8 +95,8 @@ global: >>> from metadock.env import MetadockEnv >>> env = MetadockEnv().jinja_environment() >>> # Wrap with graves, like md.code(...) - >>> env.from_string("{{ 'This is a string.' | wrap('`') }}").render() - '`This is a string.`' + >>> env.from_string("{{ 'This is a string.' | wrap('\`') }}").render() + '\`This is a string.\`' source_file: metadock/env.py method_name: metadock.env.MetadockEnv.wrap_filter signature: "(self, value: str, wrap: str) -> str" diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 9480caa..8526bbc 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -320,7 +320,7 @@

            Jinja filters

            wrap
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            -Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' | wrap('') }}").render()<br>'This is a string.`'
            +Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' | wrap('`') }}").render()
            '`This is a string.`'
            zip
            diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 201b193..bd99715 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -320,7 +320,7 @@ The following filters are available in the global namespace: |
            inline
            |
            metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str
            | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | |
            with_prefix
            |
            metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str
            | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | |
            with_suffix
            |
            metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str
            | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | -|
            wrap
            |
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            | Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' \| wrap('`') }}").render()
            '`This is a string.`'
            | +|
            wrap
            |
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            | Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' \| wrap('\`') }}").render()
            '\`This is a string.\`'
            | |
            zip
            |
            metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]
            | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            | diff --git a/README.md b/README.md index 201b193..bd99715 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ The following filters are available in the global namespace: |
            inline
            |
            metadock.env.MetadockEnv.inline_filter: (self, value: str) -> str
            | Filter which inlines a string by replacing all newlines with spaces, and all double spaces with single spaces.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a multi-line string.\nThis is the second line.\nAnd the third.' \| inline }}").render()
            'This is a multi-line string. This is the second line. And the third.'
            | |
            with_prefix
            |
            metadock.env.MetadockEnv.with_prefix_filter: (self, value: str, prefix: str, sep: str = '') -> str
            | Filter which prepends a prefix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix') }}").render()
            'PrefixThis is a string.'
            >>> env.from_string("{{ 'This is a string.' \| with_prefix('Prefix: ', sep = ' : ') }}").render()
            'Prefix : This is a string.'
            | |
            with_suffix
            |
            metadock.env.MetadockEnv.with_suffix_filter: (self, value: str, suffix: str, sep: str = '') -> str
            | Filter which appends a suffix to a string, with an optional separator.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix') }}").render()
            'This is a stringSuffix'
            >>> env.from_string("{{ 'This is a string' \| with_suffix('Suffix', sep = ' : ') }}").render()
            'This is a string : Suffix'
            | -|
            wrap
            |
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            | Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' \| wrap('`') }}").render()
            '`This is a string.`'
            | +|
            wrap
            |
            metadock.env.MetadockEnv.wrap_filter: (self, value: str, wrap: str) -> str
            | Filter which wraps an inner string with a given outer string.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> # Wrap with graves, like md.code(...)
            >>> env.from_string("{{ 'This is a string.' \| wrap('\`') }}").render()
            '\`This is a string.\`'
            | |
            zip
            |
            metadock.env.MetadockEnv.zip_filter: (self, input_iterable: Iterable[Any], *iterables: Iterable[Any]) -> Iterable[tuple[Any, ...]]
            | Filter which zips an input iterable with one or more iterables.

            >>> from metadock.env import MetadockEnv
            >>> env = MetadockEnv().jinja_environment()
            >>> env.from_string("{{ ['a', 'b', 'c'] \| zip([1, 2, 3]) \| list }}").render()
            "[('a', 1), ('b', 2), ('c', 3)]"
            | From 71c339cbf118a437d742f30ead8651d7a7b32147 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 18:16:29 -0800 Subject: [PATCH 21/22] adding docs for yaml imports to README --- .../content_schematics/example_project.yml | 50 +++++++++++++- .metadock/generated_documents/README.html | 58 ++++++++++++++++ .metadock/generated_documents/README.md | 67 +++++++++++++++++++ .../repo_readme_template.md | 32 +++++++++ README.md | 67 +++++++++++++++++++ 5 files changed, 272 insertions(+), 2 deletions(-) diff --git a/.metadock/content_schematics/example_project.yml b/.metadock/content_schematics/example_project.yml index e11d35f..cb9876b 100644 --- a/.metadock/content_schematics/example_project.yml +++ b/.metadock/content_schematics/example_project.yml @@ -1,5 +1,4 @@ example_project: - structure: | MyProject/ - ... @@ -75,6 +74,53 @@ example_project: - Drop all records which are missing software version. - Add software version as a hard requirement for staging. + import_key_examples.yml: | + content_schematics: + + - name: alerting_project_proposal + template: airflow_project_proposal_template.md + target_formats: [ md+html, md ] + + context: + + jira: + + # "block" syntax for importing a root-level key "IGDP" + project: + import: jira/projects.yml + key: IGDP + + # "flow" syntax for importing a sub-key, "David_Sillman" inside "eng_identity" + code_owners: + - { import: jira/identities.yml, key: eng_identity.David_Sillman } + + # "flow" syntax for importing a sub-key using a merge key ("<<"), + <<: { import: team_contexts/data.yml, key: resources.alerting_channels } + + # "block" syntax for importing multiple subkeys from multiple files using a merge key, + <<: + - import: team_contexts/data_contacts.yml + key: contacts.email + - import: team_contexts/data_push_api.yml + key: push_api.contracts + + import_key_examples_2.yml: | + content_schematics: + + - name: confluence_docs_summary + template: confluence/data_docs/confluence_docs_summary_template.md + target_formats: [ md+html, md ] + context: + + # "block" syntax for whole-file import, + all_contracts: + import: confluence/data_docs/contracts.yml + + # "flow" syntax for importing multiple whole files using a merge key, + <<: + - import: confluence/data_docs/projects.yml + - import: confluence/data_docs/sources.yml + generated_documents: gitlab_mr__feature1.md: | # [IGDP-13] Adding software version as hard requirement for staging @@ -111,4 +157,4 @@ example_project:
        -

        For more information, please check out the Jira ticket associated with this MR, IGDP-13.

        \ No newline at end of file +

        For more information, please check out the Jira ticket associated with this MR, IGDP-13.

        diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 8526bbc..1260001 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -244,6 +244,64 @@

        [IGDP-13] Adding software version as hard requirement for staging

    +

    Code splitting with YAML imports

    +

    In order to keep your content schematics DRY, you can use YAML imports to split your content schematics into multiple +YAML files. For example, if you have a set of content schematics responsible for laying out a "knowledge base" of +services maintained by your team, you might have a YAML file for each service, e.g. +services/airflow/google_forms_scrubber.yml and services/pipelines/user_interaction_data_pipeline.yml which +separately model their respective service specifications.

    +

    A content schematic can import context from a specific YAML key in another YAML file by using the special import-key +object, e.g.:

    +
    content_schematics:
    +
    +- name: alerting_project_proposal
    +  template: airflow_project_proposal_template.md
    +  target_formats: [ md+html, md ]
    +
    +  context:
    +
    +    jira:
    +
    +      # "block" syntax for importing a root-level key "IGDP"
    +      project:
    +        import: jira/projects.yml
    +        key: IGDP
    +
    +      # "flow" syntax for importing a sub-key, "David_Sillman" inside "eng_identity"
    +      code_owners: 
    +        - { import: jira/identities.yml, key: eng_identity.David_Sillman }
    +
    +      # "flow" syntax for importing a sub-key using a merge key ("<<"),
    +      <<: { import: team_contexts/data.yml, key: resources.alerting_channels }
    +
    +      # "block" syntax for importing multiple subkeys from multiple files using a merge key,
    +      <<:
    +        - import: team_contexts/data_contacts.yml
    +          key: contacts.email
    +        - import: team_contexts/data_push_api.yml
    +          key: push_api.contracts
    +
    +

    Note that all paths for the import field are relative to the content_schematics folder for the project. +If you'd like to import the entire content of a file as context, you may omit the key field, e.g.:

    +
    content_schematics:
    +
    +- name: confluence_docs_summary
    +  template: confluence/data_docs/confluence_docs_summary_template.md
    +  target_formats: [ md+html, md ]
    +  context:
    +
    +    # "block" syntax for whole-file import,
    +    all_contracts:
    +      import: confluence/data_docs/contracts.yml
    +
    +    # "flow" syntax for importing multiple whole files using a merge key,
    +    <<:
    +      - import: confluence/data_docs/projects.yml
    +      - import: confluence/data_docs/sources.yml
    +
    +

    At the moment, no protection against cyclic dependencies are implemented (apart from a recursion depth exception which +will likely be thrown before memory is consumed). Users are responsible for ensuring that their imports do not create +cyclic dependencies.

    Jinja Templating Helpers

    In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros and filters which can be used to make formatting content easier. The macros and filters are segregated into diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index bd99715..1aecb28 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -269,6 +269,73 @@ The natively supported values for `target_formats` are: - Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or `.py`. +## Code splitting with YAML imports + +In order to keep your content schematics DRY, you can use YAML imports to split your content schematics into multiple +YAML files. For example, if you have a set of content schematics responsible for laying out a "knowledge base" of +services maintained by your team, you might have a YAML file for each service, e.g. +`services/airflow/google_forms_scrubber.yml` and `services/pipelines/user_interaction_data_pipeline.yml` which +separately model their respective service specifications. + +A content schematic can import context from a specific YAML key in another YAML file by using the special _import-key_ +object, e.g.: + +```yml +content_schematics: + +- name: alerting_project_proposal + template: airflow_project_proposal_template.md + target_formats: [ md+html, md ] + + context: + + jira: + + # "block" syntax for importing a root-level key "IGDP" + project: + import: jira/projects.yml + key: IGDP + + # "flow" syntax for importing a sub-key, "David_Sillman" inside "eng_identity" + code_owners: + - { import: jira/identities.yml, key: eng_identity.David_Sillman } + + # "flow" syntax for importing a sub-key using a merge key ("<<"), + <<: { import: team_contexts/data.yml, key: resources.alerting_channels } + + # "block" syntax for importing multiple subkeys from multiple files using a merge key, + <<: + - import: team_contexts/data_contacts.yml + key: contacts.email + - import: team_contexts/data_push_api.yml + key: push_api.contracts +``` + +Note that all paths for the `import` field are relative to the `content_schematics` folder for the project. +If you'd like to import the entire content of a file as context, you may omit the `key` field, e.g.: + +```yml +content_schematics: + +- name: confluence_docs_summary + template: confluence/data_docs/confluence_docs_summary_template.md + target_formats: [ md+html, md ] + context: + + # "block" syntax for whole-file import, + all_contracts: + import: confluence/data_docs/contracts.yml + + # "flow" syntax for importing multiple whole files using a merge key, + <<: + - import: confluence/data_docs/projects.yml + - import: confluence/data_docs/sources.yml +``` + +At the moment, no protection against cyclic dependencies are implemented (apart from a recursion depth exception which +will likely be thrown before memory is consumed). Users are responsible for ensuring that their imports do not create +cyclic dependencies. + ## Jinja Templating Helpers In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros diff --git a/.metadock/templated_documents/repo_readme_template.md b/.metadock/templated_documents/repo_readme_template.md index c3cbf35..2948fd4 100644 --- a/.metadock/templated_documents/repo_readme_template.md +++ b/.metadock/templated_documents/repo_readme_template.md @@ -88,6 +88,38 @@ The natively supported values for `target_formats` are: - Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or `.py`. +## Code splitting with YAML imports + +In order to keep your content schematics DRY, you can use YAML imports to split your content schematics into multiple +YAML files. For example, if you have a set of content schematics responsible for laying out a "knowledge base" of +services maintained by your team, you might have a YAML file for each service, e.g. +`services/airflow/google_forms_scrubber.yml` and `services/pipelines/user_interaction_data_pipeline.yml` which +separately model their respective service specifications. + +A content schematic can import context from a specific YAML key in another YAML file by using the special _import-key_ +object, e.g.: + +{{ + md.codeblock( + example_project.get("content_schematics").get("import_key_examples.yml"), + language="yml", + ) +}} + +Note that all paths for the `import` field are relative to the `content_schematics` folder for the project. +If you'd like to import the entire content of a file as context, you may omit the `key` field, e.g.: + +{{ + md.codeblock( + example_project.get("content_schematics").get("import_key_examples_2.yml"), + language="yml", + ) +}} + +At the moment, no protection against cyclic dependencies are implemented (apart from a recursion depth exception which +will likely be thrown before memory is consumed). Users are responsible for ensuring that their imports do not create +cyclic dependencies. + ## Jinja Templating Helpers In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros diff --git a/README.md b/README.md index bd99715..1aecb28 100644 --- a/README.md +++ b/README.md @@ -269,6 +269,73 @@ The natively supported values for `target_formats` are: - Generates the given template as plaintext, and adds the given string as a file extension, e.g. `.txt`, `.sql` or `.py`. +## Code splitting with YAML imports + +In order to keep your content schematics DRY, you can use YAML imports to split your content schematics into multiple +YAML files. For example, if you have a set of content schematics responsible for laying out a "knowledge base" of +services maintained by your team, you might have a YAML file for each service, e.g. +`services/airflow/google_forms_scrubber.yml` and `services/pipelines/user_interaction_data_pipeline.yml` which +separately model their respective service specifications. + +A content schematic can import context from a specific YAML key in another YAML file by using the special _import-key_ +object, e.g.: + +```yml +content_schematics: + +- name: alerting_project_proposal + template: airflow_project_proposal_template.md + target_formats: [ md+html, md ] + + context: + + jira: + + # "block" syntax for importing a root-level key "IGDP" + project: + import: jira/projects.yml + key: IGDP + + # "flow" syntax for importing a sub-key, "David_Sillman" inside "eng_identity" + code_owners: + - { import: jira/identities.yml, key: eng_identity.David_Sillman } + + # "flow" syntax for importing a sub-key using a merge key ("<<"), + <<: { import: team_contexts/data.yml, key: resources.alerting_channels } + + # "block" syntax for importing multiple subkeys from multiple files using a merge key, + <<: + - import: team_contexts/data_contacts.yml + key: contacts.email + - import: team_contexts/data_push_api.yml + key: push_api.contracts +``` + +Note that all paths for the `import` field are relative to the `content_schematics` folder for the project. +If you'd like to import the entire content of a file as context, you may omit the `key` field, e.g.: + +```yml +content_schematics: + +- name: confluence_docs_summary + template: confluence/data_docs/confluence_docs_summary_template.md + target_formats: [ md+html, md ] + context: + + # "block" syntax for whole-file import, + all_contracts: + import: confluence/data_docs/contracts.yml + + # "flow" syntax for importing multiple whole files using a merge key, + <<: + - import: confluence/data_docs/projects.yml + - import: confluence/data_docs/sources.yml +``` + +At the moment, no protection against cyclic dependencies are implemented (apart from a recursion depth exception which +will likely be thrown before memory is consumed). Users are responsible for ensuring that their imports do not create +cyclic dependencies. + ## Jinja Templating Helpers In the Jinja templating context which is loaded for each templated document, there are a handful of helpful Jinja macros From b60b5504ad3c84c1f5390011aabf8036a164bc79 Mon Sep 17 00:00:00 2001 From: David Sillman Date: Sat, 25 Nov 2023 18:18:25 -0800 Subject: [PATCH 22/22] fixing import key typo in readme ex project --- .metadock/content_schematics/example_project.yml | 7 +++---- .metadock/generated_documents/README.html | 7 +++---- .metadock/generated_documents/README.md | 7 +++---- README.md | 7 +++---- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/.metadock/content_schematics/example_project.yml b/.metadock/content_schematics/example_project.yml index cb9876b..fa166fa 100644 --- a/.metadock/content_schematics/example_project.yml +++ b/.metadock/content_schematics/example_project.yml @@ -112,11 +112,10 @@ example_project: target_formats: [ md+html, md ] context: - # "block" syntax for whole-file import, - all_contracts: - import: confluence/data_docs/contracts.yml + # "flow" syntax for a single whole-file import, + all_contracts: { import: confluence/data_docs/contracts.yml } - # "flow" syntax for importing multiple whole files using a merge key, + # "block" syntax for importing multiple whole files using a merge key, <<: - import: confluence/data_docs/projects.yml - import: confluence/data_docs/sources.yml diff --git a/.metadock/generated_documents/README.html b/.metadock/generated_documents/README.html index 1260001..3fb7f75 100644 --- a/.metadock/generated_documents/README.html +++ b/.metadock/generated_documents/README.html @@ -290,11 +290,10 @@

    Code splitting with YAML imports

    target_formats: [ md+html, md ] context: - # "block" syntax for whole-file import, - all_contracts: - import: confluence/data_docs/contracts.yml + # "flow" syntax for a single whole-file import, + all_contracts: { import: confluence/data_docs/contracts.yml } - # "flow" syntax for importing multiple whole files using a merge key, + # "block" syntax for importing multiple whole files using a merge key, <<: - import: confluence/data_docs/projects.yml - import: confluence/data_docs/sources.yml diff --git a/.metadock/generated_documents/README.md b/.metadock/generated_documents/README.md index 1aecb28..569cfe0 100644 --- a/.metadock/generated_documents/README.md +++ b/.metadock/generated_documents/README.md @@ -322,11 +322,10 @@ content_schematics: target_formats: [ md+html, md ] context: - # "block" syntax for whole-file import, - all_contracts: - import: confluence/data_docs/contracts.yml + # "flow" syntax for a single whole-file import, + all_contracts: { import: confluence/data_docs/contracts.yml } - # "flow" syntax for importing multiple whole files using a merge key, + # "block" syntax for importing multiple whole files using a merge key, <<: - import: confluence/data_docs/projects.yml - import: confluence/data_docs/sources.yml diff --git a/README.md b/README.md index 1aecb28..569cfe0 100644 --- a/README.md +++ b/README.md @@ -322,11 +322,10 @@ content_schematics: target_formats: [ md+html, md ] context: - # "block" syntax for whole-file import, - all_contracts: - import: confluence/data_docs/contracts.yml + # "flow" syntax for a single whole-file import, + all_contracts: { import: confluence/data_docs/contracts.yml } - # "flow" syntax for importing multiple whole files using a merge key, + # "block" syntax for importing multiple whole files using a merge key, <<: - import: confluence/data_docs/projects.yml - import: confluence/data_docs/sources.yml