Skip to content

Commit 95bb2a6

Browse files
authored
Merge pull request #1206 from bajrangCoder/main
feat: add syntax highlighting for code blocks on plugin page
2 parents ab91f68 + c48422c commit 95bb2a6

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/pages/plugin/plugin.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ export default async function PluginInclude(
308308
const pluginSettings = settings.uiSettings[`plugin-${plugin.id}`];
309309
$page.body = view({
310310
...plugin,
311-
body: markdownIt({ html: true, xhtmlOut: true })
311+
body: markdownIt({
312+
html: true,
313+
xhtmlOut: true,
314+
})
312315
.use(MarkdownItGitHubAlerts)
313316
.use(anchor, {
314317
slugify: (s) =>
@@ -394,6 +397,28 @@ export default async function PluginInclude(
394397
copyButton.className = "copy-button";
395398
copyButton.textContent = "Copy";
396399

400+
const codeElement = pre.querySelector("code");
401+
if (codeElement) {
402+
const langMatch = codeElement.className.match(
403+
/language-(\w+)|(javascript)/,
404+
);
405+
if (langMatch) {
406+
const langMap = {
407+
bash: "sh",
408+
shell: "sh",
409+
};
410+
const lang = langMatch[1] || langMatch[2];
411+
const mappedLang = langMap[lang] || lang;
412+
const highlight = ace.require("ace/ext/static_highlight");
413+
highlight(codeElement, {
414+
mode: `ace/mode/${mappedLang}`,
415+
theme: settings.value.editorTheme.startsWith("ace/theme/")
416+
? settings.value.editorTheme
417+
: "ace/theme/" + settings.value.editorTheme,
418+
});
419+
}
420+
}
421+
397422
copyButton.addEventListener("click", async () => {
398423
const code = pre.querySelector("code")?.textContent || pre.textContent;
399424
try {

src/pages/plugin/plugin.scss

+6-2
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,19 @@
191191
word-wrap: normal;
192192
white-space: pre;
193193
font-size: 0.8rem;
194-
padding: 5px;
194+
border-radius: 4px;
195+
padding: 1em;
195196
margin: 5px 0;
196197
background: var(--primary-color);
197198
color: var(--primary-text-color);
198-
border-left: solid 5px var(--active-color);
199+
/* border-left: solid 5px var(--active-color); */
199200
overflow: auto;
200201
width: calc(100% - 10px);
201202
display: block;
202203
user-select: text;
204+
div {
205+
background: var(--primary-color);
206+
}
203207
}
204208
}
205209
}

www/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
type,
4848
listener,
4949
useCapture,
50-
allowed
50+
allowed,
5151
) {
5252
if (typeof useCapture === "boolean") {
5353
allowed = useCapture;
@@ -101,6 +101,7 @@
101101
<script src="./js/ace/ext-error_marker.js"></script>
102102
<script src="./js/ace/ext-whitespace.js"></script>
103103
<script src="./js/ace/ext-static_highlight.js"></script>
104+
<script src="./js/ace/ext-inline_autocomplete.js"></script>
104105

105106
<script>
106107
var color = localStorage.getItem("__primary_color");

0 commit comments

Comments
 (0)