From 1adefc47ab1a73915f20861bdfe0963e7468b4e4 Mon Sep 17 00:00:00 2001 From: hlaelissalt Date: Fri, 13 Nov 2026 00:38:25 +0100 Subject: [PATCH 1/3] fix: the identifiers of the tables stay on one line --- astro.config.ts | 2 ++ src/lib/rehype-nowrap-ids.ts | 18 ++++++++++++++++++ src/styles/didactika.css | 1 + 3 files changed, 21 insertions(+) create mode 100644 src/lib/rehype-nowrap-ids.ts diff --git a/astro.config.ts b/astro.config.ts index dfac138..1427cda 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -2,6 +2,7 @@ import {existsSync, readFileSync} from 'node:fs'; import {join} from 'node:path'; import {defineConfig} from 'astro/config'; import starlight from '@astrojs/starlight'; +import rehypeNowrapIds from './src/lib/rehype-nowrap-ids'; import type {StarlightUserConfig} from '@astrojs/starlight/types'; interface Language { @@ -89,6 +90,7 @@ export default defineConfig({ site: 'https://docs.didactika.org', trailingSlash: 'always', build: {format: 'directory'}, + markdown: {rehypePlugins: [rehypeNowrapIds]}, // In Docker the files change on the other side of a mount, where the system does not tell the watcher; polling does the same job. vite: {server: {watch: {usePolling: process.env.DOCS_POLL === '1'}}}, integrations: [ diff --git a/src/lib/rehype-nowrap-ids.ts b/src/lib/rehype-nowrap-ids.ts new file mode 100644 index 0000000..d80cc54 --- /dev/null +++ b/src/lib/rehype-nowrap-ids.ts @@ -0,0 +1,18 @@ +/** + * Keeps the identifiers of the tables (UC-001, RF-002, RN-007...) on one line: a hyphen is a place where a browser may break a + * line, and in a narrow column it did, leaving "UC-" and "001" on two lines. + */ +import {visit} from 'unist-util-visit'; +import {toString} from 'hast-util-to-string'; + +const IDENTIFIER = /^[A-Z]{2,5}-\d{2,4}$/; + +export default function rehypeNowrapIds() { + return (tree: unknown) => { + visit(tree as never, 'element', (node: {tagName: string; properties?: Record}) => { + if ((node.tagName === 'td' || node.tagName === 'th') && IDENTIFIER.test(toString(node as never).trim())) { + node.properties = {...node.properties, className: ['nowrap']}; + } + }); + }; +} diff --git a/src/styles/didactika.css b/src/styles/didactika.css index 0d32698..7d9f1f0 100644 --- a/src/styles/didactika.css +++ b/src/styles/didactika.css @@ -246,6 +246,7 @@ dialog.d-search::backdrop { background: rgb(2 8 10 / 60%); backdrop-filter: blur .sl-markdown-content table { display: table; width: 100%; border: 1px solid var(--line); border-radius: var(--radius); border-collapse: separate; border-spacing: 0; overflow: hidden; font-size: 0.875rem; } .sl-markdown-content :is(th, td) { padding: 0.65rem 0.85rem; border: 0; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; } .sl-markdown-content tr:last-child td { border-bottom: 0; } +.sl-markdown-content :is(td, th).nowrap { white-space: nowrap; } .sl-markdown-content th { background: var(--panel-2); color: var(--muted); font: 600 0.72rem/1.2 var(--font); letter-spacing: 0.06em; text-transform: uppercase; } .sl-markdown-content tbody tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); } From 0fa2ed98171e3fe9e9fe1a14432ff4634d978528 Mon Sep 17 00:00:00 2001 From: hlaelissalt Date: Fri, 13 Nov 2026 00:40:10 +0100 Subject: [PATCH 2/3] fix: the identifiers of the tables stay on one line (a script instead of a Markdown plugin) --- astro.config.ts | 7 +++++-- src/lib/rehype-nowrap-ids.ts | 18 ------------------ 2 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 src/lib/rehype-nowrap-ids.ts diff --git a/astro.config.ts b/astro.config.ts index 1427cda..e0ce34c 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -2,7 +2,6 @@ import {existsSync, readFileSync} from 'node:fs'; import {join} from 'node:path'; import {defineConfig} from 'astro/config'; import starlight from '@astrojs/starlight'; -import rehypeNowrapIds from './src/lib/rehype-nowrap-ids'; import type {StarlightUserConfig} from '@astrojs/starlight/types'; interface Language { @@ -90,7 +89,6 @@ export default defineConfig({ site: 'https://docs.didactika.org', trailingSlash: 'always', build: {format: 'directory'}, - markdown: {rehypePlugins: [rehypeNowrapIds]}, // In Docker the files change on the other side of a mount, where the system does not tell the watcher; polling does the same job. vite: {server: {watch: {usePolling: process.env.DOCS_POLL === '1'}}}, integrations: [ @@ -113,6 +111,11 @@ export default defineConfig({ tag: 'script', content: "(function(){try{var at=Number(localStorage.getItem('didactika-theme-at'));if(!at||Date.now()-at>2592000000){localStorage.removeItem('starlight-theme');}}catch(e){}var a=new URLSearchParams(location.search).get('mode');if(a==='dark'||a==='light'){try{localStorage.setItem('starlight-theme',a);}catch(e){}document.documentElement.dataset.theme=a;}})();", }, + { + // A hyphen is a place where a browser may break a line: keep identifiers such as UC-001 on one line. + tag: 'script', + content: "document.addEventListener('DOMContentLoaded',function(){document.querySelectorAll('.sl-markdown-content td,.sl-markdown-content th').forEach(function(c){if(/^[A-Z]{2,5}-\d{2,4}$/.test(c.textContent.trim())){c.classList.add('nowrap');}});});", + }, {tag: 'link', attrs: {rel: 'icon', href: '/brand/favicon.svg', type: 'image/svg+xml'}}, {tag: 'link', attrs: {rel: 'icon', href: '/brand/favicon-32x32.png', sizes: '32x32', type: 'image/png'}}, {tag: 'link', attrs: {rel: 'icon', href: '/brand/favicon-16x16.png', sizes: '16x16', type: 'image/png'}}, diff --git a/src/lib/rehype-nowrap-ids.ts b/src/lib/rehype-nowrap-ids.ts deleted file mode 100644 index d80cc54..0000000 --- a/src/lib/rehype-nowrap-ids.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Keeps the identifiers of the tables (UC-001, RF-002, RN-007...) on one line: a hyphen is a place where a browser may break a - * line, and in a narrow column it did, leaving "UC-" and "001" on two lines. - */ -import {visit} from 'unist-util-visit'; -import {toString} from 'hast-util-to-string'; - -const IDENTIFIER = /^[A-Z]{2,5}-\d{2,4}$/; - -export default function rehypeNowrapIds() { - return (tree: unknown) => { - visit(tree as never, 'element', (node: {tagName: string; properties?: Record}) => { - if ((node.tagName === 'td' || node.tagName === 'th') && IDENTIFIER.test(toString(node as never).trim())) { - node.properties = {...node.properties, className: ['nowrap']}; - } - }); - }; -} From d770407040fae85c72abf5165416658e1487ab65 Mon Sep 17 00:00:00 2001 From: hlaelissalt Date: Fri, 13 Nov 2026 00:42:37 +0100 Subject: [PATCH 3/3] fix: the pattern of the identifiers has no escape to lose --- astro.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astro.config.ts b/astro.config.ts index e0ce34c..4eb4443 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -114,7 +114,7 @@ export default defineConfig({ { // A hyphen is a place where a browser may break a line: keep identifiers such as UC-001 on one line. tag: 'script', - content: "document.addEventListener('DOMContentLoaded',function(){document.querySelectorAll('.sl-markdown-content td,.sl-markdown-content th').forEach(function(c){if(/^[A-Z]{2,5}-\d{2,4}$/.test(c.textContent.trim())){c.classList.add('nowrap');}});});", + content: "document.addEventListener('DOMContentLoaded',function(){document.querySelectorAll('.sl-markdown-content td,.sl-markdown-content th').forEach(function(c){if(/^[A-Z]{2,5}-[0-9]{2,4}$/.test(c.textContent.trim())){c.classList.add('nowrap');}});});", }, {tag: 'link', attrs: {rel: 'icon', href: '/brand/favicon.svg', type: 'image/svg+xml'}}, {tag: 'link', attrs: {rel: 'icon', href: '/brand/favicon-32x32.png', sizes: '32x32', type: 'image/png'}},