From 8d1842939036ee38e0f9299dd25e860c245aec39 Mon Sep 17 00:00:00 2001 From: Orest Bida Date: Mon, 25 Sep 2023 21:48:20 +0200 Subject: [PATCH] Feat: added css themes --- playground/index.html | 111 +++++++- playground/plugins/shiki-highlighter.js | 323 +++++++++++++++--------- playground/src/main.css | 114 ++++++++- 3 files changed, 423 insertions(+), 125 deletions(-) diff --git a/playground/index.html b/playground/index.html index 7a31cf18..a9787dec 100644 --- a/playground/index.html +++ b/playground/index.html @@ -355,37 +355,128 @@

Misc



-
+

Themes

-
-
+ +
+ + + + + + +
+ + +

diff --git a/playground/plugins/shiki-highlighter.js b/playground/plugins/shiki-highlighter.js index 583943d8..e762620f 100644 --- a/playground/plugins/shiki-highlighter.js +++ b/playground/plugins/shiki-highlighter.js @@ -23,146 +23,243 @@ async function ShikiHighlight(opts = {}) { * @returns {string} */ transformIndexHtml(html) { - let htmlString = html; + htmlString = shikiHighlightBlock(html, shiki); + htmlString = createCustomBlock(htmlString); + return htmlString; + } + }; +} + +/** + * @param {string} html + * @param {import('shiki-es').Highlighter} shiki + */ +function shikiHighlightBlock(html, shiki) { - const codeBlocks = html.matchAll(//gs); + let htmlString = html; + const codeBlocks = html.matchAll(//gs); + + for(const block of codeBlocks) { + + /** + * @type {string} + */ + const blockString = block[0]; + const split = blockString.split('\n'); + + if(split.length < 1) + continue; + + /** + * All attributes (everything after "