Skip to content

Commit e290fd0

Browse files
authored
Merge pull request #7 from lightningrodlabs/fix/code-highlight
Fix code highlighting
2 parents c94356f + 4976425 commit e290fd0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

ui/src/elements/markdown-note.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ export class MarkdownNote extends LitElement {
511511
.tooltip::part(popup) {
512512
z-index: 10;
513513
}
514+
515+
/* loaded from https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/vs.min.css */
516+
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#fff;color:#000}.hljs-comment,.hljs-quote,.hljs-variable{color:green}.hljs-built_in,.hljs-keyword,.hljs-name,.hljs-selector-tag,.hljs-tag{color:#00f}.hljs-addition,.hljs-attribute,.hljs-literal,.hljs-section,.hljs-string,.hljs-template-tag,.hljs-template-variable,.hljs-title,.hljs-type{color:#a31515}.hljs-deletion,.hljs-meta,.hljs-selector-attr,.hljs-selector-pseudo{color:#2b91af}.hljs-doctag{color:grey}.hljs-attr{color:red}.hljs-bullet,.hljs-link,.hljs-symbol{color:#00b0e8}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}
514517
`,
515518
];
516-
}
519+
}

ui/src/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,16 @@ Marked.setOptions
8181
renderer: new HilightRenderer,
8282
highlight: (code, lang) => {
8383
if (lang) {
84-
return hljs.highlight(lang, code).value
84+
try {
85+
const highlightResult = hljs.highlight(code, { language: lang });
86+
return highlightResult.value;
87+
} catch (error) {
88+
const autoResult = hljs.highlightAuto(code);
89+
return autoResult.value;
90+
}
8591
}
86-
return code
92+
const autoResult = hljs.highlightAuto(code);
93+
return autoResult.value;
8794
},
8895
gfm: true,
8996
tables: true,

0 commit comments

Comments
 (0)