Skip to content

Commit c9eeee5

Browse files
committed
chore: small tweakings of the Markdown viewer
1 parent 8517799 commit c9eeee5

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

templates/registry/markdown/entity_readme.md.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ Currently, the following namespaces exist:
2121
| Namespace | Entity | Stability |
2222
| --------- | ------ | --------- |
2323
{%- for bundle in ctx %}
24-
| {{ bundle.id | title_case | acronym }} | | |
2524
{%- for group in bundle.groups | sort(attribute='name') -%}
2625
{%- set my_file_name = bundle.id | kebab_case ~ ".md#" ~ (group.name | kebab_case) %}
27-
| | [{{ group.name }}]({{my_file_name}}) | {{ stability.badge(group.stability, group.deprecated) | trim }} |
26+
| {{ bundle.id | title_case | acronym if loop.first }} | [{{ group.name }}]({{my_file_name}}) | {{ stability.badge(group.stability, group.deprecated) | trim }} |
2827
{%- endfor %}
2928
{%- endfor %}
3029

templates/registry/markdown/event_readme.md.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ Currently, the following namespaces exist:
1919
| Namespace | Event | Stability |
2020
| --------- | ----- | --------- |
2121
{%- for bundle in ctx %}
22-
| {{ bundle.id | title_case | acronym }} | | |
2322
{%- for group in bundle.groups | sort(attribute='name') -%}
2423
{%- set my_file_name = bundle.id | kebab_case ~ ".md#" ~ (group.name | kebab_case) %}
25-
| | [{{ group.name }}]({{my_file_name}}) | {{ stability.badge(group.stability, group.deprecated) | trim }} |
24+
| {{ bundle.id | title_case | acronym if loop.first }} | [{{ group.name }}]({{my_file_name}}) | {{ stability.badge(group.stability, group.deprecated) | trim }} |
2625
{%- endfor %}
2726
{%- endfor %}

templates/registry/markdown/index.html.j2

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,32 +258,44 @@
258258
(function() {
259259
const content = document.getElementById('content');
260260
261-
function loadPage(path) {
261+
function loadPage(path, fragment) {
262262
fetch(path)
263263
.then(r => { if (!r.ok) throw new Error(r.status); return r.text(); })
264264
.then(md => {
265265
content.innerHTML = marked.parse(md);
266266
// Rewrite .md links to hash links
267267
content.querySelectorAll('a[href]').forEach(a => {
268268
const href = a.getAttribute('href');
269-
if (href && href.endsWith('.md') && !href.startsWith('http')) {
270-
const base = path.substring(0, path.lastIndexOf('/') + 1);
271-
const resolved = new URL(href, location.origin + '/' + base).pathname.replace(/^\//, '');
272-
a.setAttribute('href', '#' + resolved);
269+
if (href && !href.startsWith('http')) {
270+
const match = href.match(/^(.+\.md)(#.*)?$/);
271+
if (match) {
272+
const base = path.substring(0, path.lastIndexOf('/') + 1);
273+
const resolved = new URL(match[1], location.origin + '/' + base).pathname.replace(/^\//, '');
274+
a.setAttribute('href', '#' + resolved + (match[2] || ''));
275+
}
273276
}
274277
});
275278
// Update active nav link
276279
document.querySelectorAll('nav a').forEach(a => {
277280
a.classList.toggle('active', a.getAttribute('href') === '#' + path);
278281
});
282+
if (fragment) {
283+
const el = document.getElementById(fragment);
284+
if (el) { el.scrollIntoView(); return; }
285+
}
279286
window.scrollTo(0, 0);
280287
})
281288
.catch(() => { content.innerHTML = '<p>Page not found.</p>'; });
282289
}
283290
284291
function onHashChange() {
285-
const path = location.hash.slice(1) || 'README.md';
286-
loadPage(path);
292+
const raw = location.hash.slice(1) || 'README.md';
293+
const parts = raw.match(/^(.+\.md)(?:#(.*))?$/);
294+
if (parts) {
295+
loadPage(parts[1], parts[2]);
296+
} else {
297+
loadPage(raw);
298+
}
287299
}
288300
289301
window.addEventListener('hashchange', onHashChange);

templates/registry/markdown/metric_readme.md.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ Currently, the following namespaces exist:
2020
{%- import 'stability.j2' as stability -%}
2121
{%- import 'metric_macros.j2' as metrics -%}
2222
{%- for bundle in ctx %}
23-
| {{ bundle.id | title_case | acronym }} | | | | |
2423
{%- for group in bundle.groups | sort(attribute='metric_name') -%}
2524
{%- set my_file_name = bundle.id | kebab_case ~ ".md#" ~ (group.metric_name | kebab_case) %}
26-
| | [{{ group.metric_name }}]({{my_file_name}}) | {{ metrics.instrument(group.instrument) | trim }} | `{{ group.unit }}` | {{ stability.badge(group.stability, group.deprecated) | trim }} |
25+
| {{ bundle.id | title_case | acronym if loop.first }} | [{{ group.metric_name }}]({{my_file_name}}) | {{ metrics.instrument(group.instrument) | trim }} | `{{ group.unit }}` | {{ stability.badge(group.stability, group.deprecated) | trim }} |
2726
{%- endfor %}
2827
{%- endfor %}

0 commit comments

Comments
 (0)