Skip to content

Commit 6ad171e

Browse files
committed
fix highlighting
1 parent 69cb697 commit 6ad171e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/site-kit/src/lib/markdown/renderer.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,18 @@ function replace_blank_lines(html: string) {
719719
}
720720

721721
const delimiter_substitutes = {
722-
'---': ' ',
723-
'+++': ' ',
724-
':::': ' '
722+
'---': ' ',
723+
'+++': ' ',
724+
':::': ' '
725725
};
726726

727+
const delimiter_patterns = Object.fromEntries(
728+
Object.entries(delimiter_substitutes).map(([key, substitute]) => [
729+
key,
730+
new RegExp(`${substitute}([^ ][^]+?)${substitute}`, 'g')
731+
])
732+
);
733+
727734
function highlight_spans(content: string, classname: string) {
728735
return content
729736
.split('\n')
@@ -878,13 +885,13 @@ async function syntax_highlight({
878885
.replace(' tabindex="0"', '');
879886

880887
html = html
881-
.replace(/ {13}([^ ][^]+?) {13}/g, (_, content) => {
888+
.replace(delimiter_patterns['---'], (_, content) => {
882889
return highlight_spans(content, 'highlight remove');
883890
})
884-
.replace(/ {11}([^ ][^]+?) {11}/g, (_, content) => {
891+
.replace(delimiter_patterns['+++'], (_, content) => {
885892
return highlight_spans(content, 'highlight add');
886893
})
887-
.replace(/ {9}([^ ][^]+?) {9}/g, (_, content) => {
894+
.replace(delimiter_patterns[':::'], (_, content) => {
888895
return highlight_spans(content, 'highlight');
889896
});
890897

0 commit comments

Comments
 (0)