From a1ab91bc091caf439ebea1f4977123fd851d4335 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Thu, 8 Jun 2023 11:59:16 +0300 Subject: [PATCH] fix(tools): use markdown headings on docspages Allows downstream to use markdown-it plugins to manipulate output e.g. by adding hash links to headers --- tools/pfe-tools/11ty/DocsPage.ts | 2 ++ tools/pfe-tools/11ty/templates/attributes.njk | 6 ++---- tools/pfe-tools/11ty/templates/band.njk | 2 +- tools/pfe-tools/11ty/templates/css-custom-properties.njk | 6 ++---- tools/pfe-tools/11ty/templates/css-shadow-parts.njk | 6 ++---- tools/pfe-tools/11ty/templates/events.njk | 6 ++---- tools/pfe-tools/11ty/templates/methods.njk | 6 ++---- tools/pfe-tools/11ty/templates/overview.njk | 6 ++++-- tools/pfe-tools/11ty/templates/properties.njk | 6 ++---- tools/pfe-tools/11ty/templates/slots.njk | 6 ++---- 10 files changed, 21 insertions(+), 31 deletions(-) diff --git a/tools/pfe-tools/11ty/DocsPage.ts b/tools/pfe-tools/11ty/DocsPage.ts index 5e3138c622..de60b0d4e6 100644 --- a/tools/pfe-tools/11ty/DocsPage.ts +++ b/tools/pfe-tools/11ty/DocsPage.ts @@ -85,6 +85,8 @@ export class DocsPage implements DocsPageRenderer { this.templates.addFilter('log', DocsPage.#log); this.templates.addFilter('type', DocsPage.#type); this.templates.addFilter('innerMD', DocsPage.#innerMD); + this.templates.addFilter('mdHeading', (header, length = 2) => + DocsPage.#innerMD(`${Array.from({ length }, () => '#').join('')} ${header}`)); this.templates.addFilter('stringifyParams', DocsPage.#stringifyParams); this.docsTemplatePath = options?.docsTemplatePath; } diff --git a/tools/pfe-tools/11ty/templates/attributes.njk b/tools/pfe-tools/11ty/templates/attributes.njk index 57f7f98c5b..70814cb60d 100644 --- a/tools/pfe-tools/11ty/templates/attributes.njk +++ b/tools/pfe-tools/11ty/templates/attributes.njk @@ -2,7 +2,7 @@ {% set header = header or 'Attributes' %}
- {{ header | innerMD | safe }} {% if not content and not attributes.length %} + {{ header | mdHeading(level) | safe }} {% if not content and not attributes.length %} None {%- else -%} @@ -20,9 +20,7 @@ {%- endif -%} {%- if deprecated.length -%}
- - {{ ('Deprecated ' + header) | innerMD | safe }} - + {{ ('Deprecated ' + header) | mdHeading(level + 1) | safe }}
{%- for attribute in deprecated -%}
{{ attribute.name }}
diff --git a/tools/pfe-tools/11ty/templates/band.njk b/tools/pfe-tools/11ty/templates/band.njk index 6741214533..1335f6f217 100644 --- a/tools/pfe-tools/11ty/templates/band.njk +++ b/tools/pfe-tools/11ty/templates/band.njk @@ -1,6 +1,6 @@ {% set level = level or 2 %}
- {{ header | innerMD | safe }} + {{ header | mdHeading(level) | safe }} {{ content | innerMD | safe }}
diff --git a/tools/pfe-tools/11ty/templates/css-custom-properties.njk b/tools/pfe-tools/11ty/templates/css-custom-properties.njk index cc30d4b4b3..867af9e648 100644 --- a/tools/pfe-tools/11ty/templates/css-custom-properties.njk +++ b/tools/pfe-tools/11ty/templates/css-custom-properties.njk @@ -11,7 +11,7 @@
- {{ header | innerMD | safe }} {% if not content and not cssProperties.length %} + {{ header | mdHeading(level) | safe }} {% if not content and not cssProperties.length %} None {%- else -%} @@ -37,9 +37,7 @@ {%- endif -%} {%- if deprecated.length -%}
- - {{ ('Deprecated ' + header) | innerMD | safe }} - + {{ ('Deprecated ' + header) | mdHeading(level + 1) | safe }} diff --git a/tools/pfe-tools/11ty/templates/css-shadow-parts.njk b/tools/pfe-tools/11ty/templates/css-shadow-parts.njk index 141d7c1194..ad85790c87 100644 --- a/tools/pfe-tools/11ty/templates/css-shadow-parts.njk +++ b/tools/pfe-tools/11ty/templates/css-shadow-parts.njk @@ -2,7 +2,7 @@ {% set header = header or 'CSS Shadow Parts' %}
- {{ header | innerMD | safe }} {% if not content and not parts.length %} + {{ header | mdHeading(level) | safe }} {% if not content and not parts.length %} None {%- else -%} @@ -14,9 +14,7 @@ {%- endif -%} {%- if deprecated.length -%}
- - {{ ('Deprecated '+header) | innerMD | safe }} - + {{ ('Deprecated ' + header) | mdHeading(level + 1) | safe }}
{% for part in deprecated -%}
{{ part.name }}
diff --git a/tools/pfe-tools/11ty/templates/events.njk b/tools/pfe-tools/11ty/templates/events.njk index 670400d0d5..445c90ab54 100644 --- a/tools/pfe-tools/11ty/templates/events.njk +++ b/tools/pfe-tools/11ty/templates/events.njk @@ -2,7 +2,7 @@ {% set header = header or 'Events' %}
- {{ header | innerMD | safe }} {% if not content and not events.length %} + {{ header | mdHeading(level) | safe }} {% if not content and not events.length %} None {% else %} @@ -18,9 +18,7 @@
{%- endif -%} {%- if deprecated.length -%}
- - {{ ('Deprecated ' + header) | innerMD | safe }} - + {{ ('Deprecated ' + header) | mdHeading(level + 1) | safe }}
{%- for event in deprecated -%}
{{ event.name }}
diff --git a/tools/pfe-tools/11ty/templates/methods.njk b/tools/pfe-tools/11ty/templates/methods.njk index fd082a4f85..95abe5eec9 100644 --- a/tools/pfe-tools/11ty/templates/methods.njk +++ b/tools/pfe-tools/11ty/templates/methods.njk @@ -4,7 +4,7 @@ {# TODO: inline code highlighting for type and default: render the markdown to html and extract the `` from the `
` #}
 
 
- {{ header | innerMD | safe }} {% if not content and not methods.length %} + {{ header | mdHeading(level) | safe }} {% if not content and not events.length %} None {% else %} @@ -15,9 +15,7 @@
{%- endif -%} {%- if deprecated.length -%}
- - {{ ('Deprecated '+header) | innerMD | safe }} - + {{ ('Deprecated ' + header) | mdHeading(level + 1) | safe }}
{%- for method in deprecated -%}
{{ method.name }}({{ method | stringifyParams }})
diff --git a/tools/pfe-tools/11ty/templates/overview.njk b/tools/pfe-tools/11ty/templates/overview.njk index 8dc8ab4563..0db92138c6 100644 --- a/tools/pfe-tools/11ty/templates/overview.njk +++ b/tools/pfe-tools/11ty/templates/overview.njk @@ -1,5 +1,6 @@
-

Overview

+ + ## Overview
{{ content | safe }} @@ -8,7 +9,8 @@
-

Installation

+ + ## Installation ```shell npm install {{ package.name }} diff --git a/tools/pfe-tools/11ty/templates/properties.njk b/tools/pfe-tools/11ty/templates/properties.njk index 4145ed9e75..d61f3681ef 100644 --- a/tools/pfe-tools/11ty/templates/properties.njk +++ b/tools/pfe-tools/11ty/templates/properties.njk @@ -4,7 +4,7 @@ {# TODO: inline code highlighting for type and default: render the markdown to html and extract the `` from the `
` #}
 
 
- {{ header | innerMD | safe }} {% if not content and not properties.length %} + {{ header | mdHeading(level) | safe }} {% if not content and not properties.length %} None {% else %} @@ -22,9 +22,7 @@
{% endif %} {%- if deprecated.length -%}
- - {{ ('Deprecated ' + header) | innerMD | safe }} - + {{ ('Deprecated ' + header) | mdHeading(level + 1) | safe }}
{%- for property in deprecated -%}
{{ property.name }}
diff --git a/tools/pfe-tools/11ty/templates/slots.njk b/tools/pfe-tools/11ty/templates/slots.njk index 6031323ea6..f7d210254b 100644 --- a/tools/pfe-tools/11ty/templates/slots.njk +++ b/tools/pfe-tools/11ty/templates/slots.njk @@ -2,7 +2,7 @@ {% set header = header or 'Slots' %}
- {{ header | innerMD | safe }} {% if not content and not slots.length %} + {{ header | mdHeading(level) | safe }} {% if not content and not slots.length %} None {%- else -%} @@ -17,9 +17,7 @@
{%- endif -%} {%- if deprecated.length -%}
- - {{ ('Deprecated ' + header) | innerMD | safe }} - + {{ ('Deprecated ' + header) | mdHeading(level + 1) | safe }}
{% for slot in deprecated -%}
{%- if slot.name -%} {{ slot.name }} {%- else -%}