From f7cd7294a295fcd11418121996851f7fe97ee83a Mon Sep 17 00:00:00 2001 From: avivkeller Date: Sun, 12 Oct 2025 11:24:18 -0400 Subject: [PATCH 1/5] fix(visual): truncate headings, escape HTML in orama --- src/generators/orama-db/index.mjs | 4 +++- src/generators/web/ui/index.css | 14 ++++++++++++++ src/utils/unist.mjs | 27 +++++++++++++++++++-------- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/generators/orama-db/index.mjs b/src/generators/orama-db/index.mjs index 3fa2af43..2b91375a 100644 --- a/src/generators/orama-db/index.mjs +++ b/src/generators/orama-db/index.mjs @@ -77,7 +77,9 @@ export default { return { title: hierarchicalTitle, - description: paragraph ? transformNodeToString(paragraph) : undefined, + description: paragraph + ? transformNodeToString(paragraph, true) + : undefined, path: `${entry.api}.html#${entry.slug}`, }; }) diff --git a/src/generators/web/ui/index.css b/src/generators/web/ui/index.css index 745c9c49..96c59c31 100644 --- a/src/generators/web/ui/index.css +++ b/src/generators/web/ui/index.css @@ -22,6 +22,7 @@ main { } table { + /* In tables, don't pad `a` elements */ a { padding-right: unset; @@ -34,6 +35,18 @@ main { align-items: center; gap: 8px; + >h1, + >h2, + >h3, + >h4, + >h5, + >h6 { + flex: 1; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; + } + .change-history { margin-left: auto; } @@ -47,6 +60,7 @@ main { } .signature { + /* Signature styling - remove line numbers and padding */ .line { padding-left: unset !important; diff --git a/src/utils/unist.mjs b/src/utils/unist.mjs index 5ec5fc7b..463f9d37 100644 --- a/src/utils/unist.mjs +++ b/src/utils/unist.mjs @@ -2,27 +2,37 @@ import { pointEnd, pointStart } from 'unist-util-position'; +/** + * Escapes HTML entiries ("<" and ">") in a string + * @param {string} string The string + */ +const escapeHTMLEntities = string => + string.replace(//g, '>'); + /** * Extracts text content from a node recursively * * @param {import('unist').Node} node The Node to be transformed into a string + * @param {boolean} [escape] Escape HTML entities ("<", ">")? * @returns {string} The transformed Node as a string */ -export const transformNodeToString = node => { +export const transformNodeToString = (node, escape) => { switch (node.type) { case 'inlineCode': - return `\`${node.value}\``; + return `\`${escape ? escapeHTMLEntities(node.value) : node.value}\``; case 'strong': - return `**${transformNodesToString(node.children)}**`; + return `**${transformNodesToString(node.children, escape)}**`; case 'emphasis': - return `_${transformNodesToString(node.children)}_`; + return `_${transformNodesToString(node.children, escape)}_`; default: { if (node.children) { - return transformNodesToString(node.children); + return transformNodesToString(node.children, escape); } + const string = node.value?.replace(/\n/g, ' ') || ''; + // Replace line breaks (\n) with spaces to keep text in a single line - return node.value?.replace(/\n/g, ' ') || ''; + return escape ? escapeHTMLEntities(string) : string; } } }; @@ -32,10 +42,11 @@ export const transformNodeToString = node => { * and transfor them back to what their source would look like * * @param {Array} nodes Nodes to parsed and joined + * @param {boolean} [escape] Escape HTML entities ("<", ">")? * @returns {string} The parsed and joined nodes as a string */ -export const transformNodesToString = nodes => { - const mappedChildren = nodes.map(node => transformNodeToString(node)); +export const transformNodesToString = (nodes, escape) => { + const mappedChildren = nodes.map(node => transformNodeToString(node, escape)); return mappedChildren.join(''); }; From 3afb9ed80b7b23ae940f3f3d5043c3ee6d58993d Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sun, 12 Oct 2025 11:26:25 -0400 Subject: [PATCH 2/5] Update src/generators/web/ui/index.css Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/generators/web/ui/index.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/generators/web/ui/index.css b/src/generators/web/ui/index.css index 96c59c31..85ef12b4 100644 --- a/src/generators/web/ui/index.css +++ b/src/generators/web/ui/index.css @@ -22,7 +22,6 @@ main { } table { - /* In tables, don't pad `a` elements */ a { padding-right: unset; From c1ae1d34f70359fa62cbf4c5ca8923c992d0362d Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sun, 12 Oct 2025 11:26:30 -0400 Subject: [PATCH 3/5] Update src/generators/web/ui/index.css Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/generators/web/ui/index.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/generators/web/ui/index.css b/src/generators/web/ui/index.css index 85ef12b4..f778cb9e 100644 --- a/src/generators/web/ui/index.css +++ b/src/generators/web/ui/index.css @@ -59,7 +59,6 @@ main { } .signature { - /* Signature styling - remove line numbers and padding */ .line { padding-left: unset !important; From 42798cb1af45f839b927e94f615e6722668297e8 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sun, 12 Oct 2025 11:26:35 -0400 Subject: [PATCH 4/5] Update src/utils/unist.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/utils/unist.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/unist.mjs b/src/utils/unist.mjs index 463f9d37..fe3bccff 100644 --- a/src/utils/unist.mjs +++ b/src/utils/unist.mjs @@ -3,7 +3,7 @@ import { pointEnd, pointStart } from 'unist-util-position'; /** - * Escapes HTML entiries ("<" and ">") in a string + * Escapes HTML entities ("<" and ">") in a string * @param {string} string The string */ const escapeHTMLEntities = string => From f8f86b40458fe8324c7a3855a7fd03c7d4343384 Mon Sep 17 00:00:00 2001 From: avivkeller Date: Sun, 12 Oct 2025 11:41:22 -0400 Subject: [PATCH 5/5] fixup! --- src/generators/web/ui/index.css | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/generators/web/ui/index.css b/src/generators/web/ui/index.css index f778cb9e..dac478ec 100644 --- a/src/generators/web/ui/index.css +++ b/src/generators/web/ui/index.css @@ -34,12 +34,12 @@ main { align-items: center; gap: 8px; - >h1, - >h2, - >h3, - >h4, - >h5, - >h6 { + > h1, + > h2, + > h3, + > h4, + > h5, + > h6 { flex: 1; text-overflow: ellipsis; overflow: hidden;