From df5077e107517a59b4b97bdd78e6860326bf2166 Mon Sep 17 00:00:00 2001 From: Pabloader Date: Fri, 27 Mar 2026 15:36:36 +0000 Subject: [PATCH] Highlight separators --- src/common/assets/highlight.module.css | 4 ++++ src/common/highlight.ts | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/assets/highlight.module.css b/src/common/assets/highlight.module.css index 9a2acf4..d6832f6 100644 --- a/src/common/assets/highlight.module.css +++ b/src/common/assets/highlight.module.css @@ -80,4 +80,8 @@ border: none; border-top: 1px solid var(--hrColor, #555); margin: 0.5em 0; + + &.inline { + margin-top: -0.5em; + } } \ No newline at end of file diff --git a/src/common/highlight.ts b/src/common/highlight.ts index 0a3fa11..7156a4c 100644 --- a/src/common/highlight.ts +++ b/src/common/highlight.ts @@ -41,7 +41,7 @@ export const parseTable = (table: string): string => { export const highlight = (message: string, keepMarkup = true): string => { let resultHTML = ''; - const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)/g; + const tokenRegex = /(\*{1,3}|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)|---/g; const headerRegex = /#{1,3} $/; const blockquoteRegex = /> $/; const stack: string[] = []; @@ -116,7 +116,9 @@ export const highlight = (message: string, keepMarkup = true): string => { continue; } - if (isClose) { + if (token === '***' || token === '---') { + resultHTML += `${keepToken ? token : ''}
`; + } else if (isClose) { stack.pop(); resultHTML += `${keepToken ? token : ''}`; } else if (token === '*') { @@ -147,7 +149,6 @@ export const highlight = (message: string, keepMarkup = true): string => { if (!keepMarkup) { resultHTML = resultHTML.replace(/((?:(?:^|\n)\|.+)+)/g, match => parseTable(match)); - resultHTML = resultHTML.replace(/(^|\n)---(\n|$)/g, (_, pre, post) => `${pre}
${post}`); resultHTML = resultHTML.replace(/((?:(?:^|\n)[-+] .+)+)/g, match => parseList(match, false)); resultHTML = resultHTML.replace(/((?:(?:^|\n)\d+\. .+)+)/g, match => parseList(match, true)); }