Highlight separators
This commit is contained in:
parent
3db25c5af3
commit
df5077e107
|
|
@ -80,4 +80,8 @@
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--hrColor, #555);
|
border-top: 1px solid var(--hrColor, #555);
|
||||||
margin: 0.5em 0;
|
margin: 0.5em 0;
|
||||||
|
|
||||||
|
&.inline {
|
||||||
|
margin-top: -0.5em;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ 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)> |\n)/g;
|
const tokenRegex = /(\*{1,3}|"|```|`|(?:^|\n)#{1,3} |(?:^|\n)> |\n)|---/g;
|
||||||
const headerRegex = /#{1,3} $/;
|
const headerRegex = /#{1,3} $/;
|
||||||
const blockquoteRegex = /> $/;
|
const blockquoteRegex = /> $/;
|
||||||
const stack: string[] = [];
|
const stack: string[] = [];
|
||||||
|
|
@ -116,7 +116,9 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isClose) {
|
if (token === '***' || token === '---') {
|
||||||
|
resultHTML += `${keepToken ? token : ''}<hr class="${clsx(styles.hr, keepToken && styles.inline)}"/>`;
|
||||||
|
} else if (isClose) {
|
||||||
stack.pop();
|
stack.pop();
|
||||||
resultHTML += `${keepToken ? token : ''}</span>`;
|
resultHTML += `${keepToken ? token : ''}</span>`;
|
||||||
} else if (token === '*') {
|
} else if (token === '*') {
|
||||||
|
|
@ -147,7 +149,6 @@ export const highlight = (message: string, keepMarkup = true): string => {
|
||||||
|
|
||||||
if (!keepMarkup) {
|
if (!keepMarkup) {
|
||||||
resultHTML = resultHTML.replace(/((?:(?:^|\n)\|.+)+)/g, match => parseTable(match));
|
resultHTML = resultHTML.replace(/((?:(?:^|\n)\|.+)+)/g, match => parseTable(match));
|
||||||
resultHTML = resultHTML.replace(/(^|\n)---(\n|$)/g, (_, pre, post) => `${pre}<hr class="${styles.hr}">${post}`);
|
|
||||||
resultHTML = resultHTML.replace(/((?:(?:^|\n)[-+] .+)+)/g, match => parseList(match, false));
|
resultHTML = resultHTML.replace(/((?:(?:^|\n)[-+] .+)+)/g, match => parseList(match, false));
|
||||||
resultHTML = resultHTML.replace(/((?:(?:^|\n)\d+\. .+)+)/g, match => parseList(match, true));
|
resultHTML = resultHTML.replace(/((?:(?:^|\n)\d+\. .+)+)/g, match => parseList(match, true));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue