From c4d10113e05ce386d66f3000e6a38ab591da3841 Mon Sep 17 00:00:00 2001 From: Pabloader Date: Thu, 26 Mar 2026 11:06:22 +0000 Subject: [PATCH] Blockquote highlight --- src/common/assets/highlight.module.css | 10 ++++++++++ src/common/highlight.ts | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/common/assets/highlight.module.css b/src/common/assets/highlight.module.css index 5445676..615b8b9 100644 --- a/src/common/assets/highlight.module.css +++ b/src/common/assets/highlight.module.css @@ -67,6 +67,16 @@ padding-left: 1.5em; } +.blockquote { + display: block; + opacity: .5; + white-space: pre-wrap; + word-wrap: break-word; + border-left: 2px solid currentColor; + margin-bottom: .5em; + padding-left: .5em; +} + .hr { border: none; border-top: 1px solid var(--hrColor, #555); diff --git a/src/common/highlight.ts b/src/common/highlight.ts index 47959d7..0a3fa11 100644 --- a/src/common/highlight.ts +++ b/src/common/highlight.ts @@ -41,12 +41,14 @@ export const parseTable = (table: string): string => { export const highlight = (message: string, keepMarkup = true): string => { let resultHTML = ''; - const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |\n)/g; + const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)/g; const headerRegex = /#{1,3} $/; + const blockquoteRegex = /> $/; const stack: string[] = []; let inCodeBlock = false; let inMonospaced = false; let inHeader = false; + let inBlockquote = false; let lastIndex = 0; let match: RegExpExecArray | null; @@ -83,6 +85,7 @@ export const highlight = (message: string, keepMarkup = true): string => { const headerMatch = token.match(headerRegex); if (headerMatch) { if (inHeader) resultHTML += ''; + if (inBlockquote) { resultHTML += ''; inBlockquote = false; } const markup = keepMarkup ? headerMatch[0] : ''; const len = headerMatch[0].length; inHeader = true; @@ -90,10 +93,23 @@ export const highlight = (message: string, keepMarkup = true): string => { continue; } + const blockquoteMatch = token.match(blockquoteRegex); + if (blockquoteMatch) { + if (inHeader) { resultHTML += ''; inHeader = false; } + if (inBlockquote) resultHTML += ''; + const markup = keepMarkup ? '> ' : ''; + inBlockquote = true; + resultHTML += `${token.slice(0, -2)}${markup}`; + continue; + } + if (token === '\n') { if (inHeader) { resultHTML += `${keepMarkup ? '\n' : ''}`; inHeader = false; + } else if (inBlockquote) { + resultHTML += `${keepMarkup ? '\n' : ''}`; + inBlockquote = false; } else { resultHTML += '\n'; } @@ -126,6 +142,7 @@ export const highlight = (message: string, keepMarkup = true): string => { resultHTML += message.slice(lastIndex); if (inHeader) resultHTML += ''; + if (inBlockquote) resultHTML += ''; resultHTML += ''.repeat(stack.length); if (!keepMarkup) {