Blockquote highlight
This commit is contained in:
parent
0595c98991
commit
c4d10113e0
|
|
@ -67,6 +67,16 @@
|
||||||
padding-left: 1.5em;
|
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 {
|
.hr {
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--hrColor, #555);
|
border-top: 1px solid var(--hrColor, #555);
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,14 @@ export const parseTable = (table: string): string => {
|
||||||
|
|
||||||
export const highlight = (message: string, keepMarkup = true): string => {
|
export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
let resultHTML = '';
|
let resultHTML = '';
|
||||||
const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |\n)/g;
|
const tokenRegex = /(\*\*?|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)/g;
|
||||||
const headerRegex = /#{1,3} $/;
|
const headerRegex = /#{1,3} $/;
|
||||||
|
const blockquoteRegex = /> $/;
|
||||||
const stack: string[] = [];
|
const stack: string[] = [];
|
||||||
let inCodeBlock = false;
|
let inCodeBlock = false;
|
||||||
let inMonospaced = false;
|
let inMonospaced = false;
|
||||||
let inHeader = false;
|
let inHeader = false;
|
||||||
|
let inBlockquote = false;
|
||||||
let lastIndex = 0;
|
let lastIndex = 0;
|
||||||
let match: RegExpExecArray | null;
|
let match: RegExpExecArray | null;
|
||||||
|
|
||||||
|
|
@ -83,6 +85,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
const headerMatch = token.match(headerRegex);
|
const headerMatch = token.match(headerRegex);
|
||||||
if (headerMatch) {
|
if (headerMatch) {
|
||||||
if (inHeader) resultHTML += '</span>';
|
if (inHeader) resultHTML += '</span>';
|
||||||
|
if (inBlockquote) { resultHTML += '</span>'; inBlockquote = false; }
|
||||||
const markup = keepMarkup ? headerMatch[0] : '';
|
const markup = keepMarkup ? headerMatch[0] : '';
|
||||||
const len = headerMatch[0].length;
|
const len = headerMatch[0].length;
|
||||||
inHeader = true;
|
inHeader = true;
|
||||||
|
|
@ -90,10 +93,23 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const blockquoteMatch = token.match(blockquoteRegex);
|
||||||
|
if (blockquoteMatch) {
|
||||||
|
if (inHeader) { resultHTML += '</span>'; inHeader = false; }
|
||||||
|
if (inBlockquote) resultHTML += '</span>';
|
||||||
|
const markup = keepMarkup ? '> ' : '';
|
||||||
|
inBlockquote = true;
|
||||||
|
resultHTML += `${token.slice(0, -2)}<span class="${styles.blockquote}">${markup}`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (token === '\n') {
|
if (token === '\n') {
|
||||||
if (inHeader) {
|
if (inHeader) {
|
||||||
resultHTML += `${keepMarkup ? '\n' : ''}</span>`;
|
resultHTML += `${keepMarkup ? '\n' : ''}</span>`;
|
||||||
inHeader = false;
|
inHeader = false;
|
||||||
|
} else if (inBlockquote) {
|
||||||
|
resultHTML += `${keepMarkup ? '\n' : ''}</span>`;
|
||||||
|
inBlockquote = false;
|
||||||
} else {
|
} else {
|
||||||
resultHTML += '\n';
|
resultHTML += '\n';
|
||||||
}
|
}
|
||||||
|
|
@ -126,6 +142,7 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
resultHTML += message.slice(lastIndex);
|
resultHTML += message.slice(lastIndex);
|
||||||
|
|
||||||
if (inHeader) resultHTML += '</span>';
|
if (inHeader) resultHTML += '</span>';
|
||||||
|
if (inBlockquote) resultHTML += '</span>';
|
||||||
resultHTML += '</span>'.repeat(stack.length);
|
resultHTML += '</span>'.repeat(stack.length);
|
||||||
|
|
||||||
if (!keepMarkup) {
|
if (!keepMarkup) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue