@@ -8,28 +8,60 @@ import youtubeEmbed from "./src/plugins/youtubeEmbed.mjs"
8
8
import responsiveImages from "./src/plugins/responsiveImages.mjs"
9
9
import codeHighlightPre from "./src/plugins/codeHighlightPre.mjs"
10
10
import preact from "@astrojs/preact" // @ts -check
11
+ import remarkShiki from "@stefanprobst/remark-shiki"
12
+ import * as shiki from "shiki"
13
+ import rangeParser from "parse-numeric-range"
11
14
12
15
import { defineConfig } from "astro/config"
13
16
import sitemap from "@astrojs/sitemap"
14
17
15
18
// https://astro.build/config
16
19
import mdx from "@astrojs/mdx"
17
20
21
+ const shikiHighlighter = await shiki . getHighlighter ( { theme : "dark-plus" } )
22
+
18
23
// https://astro.build/config
19
24
export default defineConfig (
20
25
/** @type {import('astro').AstroUserConfig } */
21
26
{
22
27
integrations : [ preact ( ) , sitemap ( ) , mdx ( ) ] ,
23
28
site : "https://blog.webdevsimplified.com" ,
24
29
markdown : {
25
- // TODO: Maybe use shiki and see if it is better and has line highlighting.
26
- syntaxHighlight : "prism" ,
27
- remarkPlugins : [ "remark-gfm" , youtubeEmbed , responsiveImages ] ,
30
+ syntaxHighlight : false ,
31
+ // TODO: Add official Shiki integration when line highlighting is supported
32
+ remarkPlugins : [
33
+ [
34
+ remarkShiki ,
35
+ {
36
+ highlighter : shikiHighlighter ,
37
+ parseMeta,
38
+ } ,
39
+ ] ,
40
+ youtubeEmbed ,
41
+ responsiveImages ,
42
+ ] ,
28
43
} ,
29
44
}
30
45
)
31
46
32
- // TODO: Add line highlighting to code blocks.
47
+ function parseMeta ( meta , { lang } ) {
48
+ if ( lang != null ) parseLang ( lang )
49
+
50
+ if ( meta == null ) return undefined
51
+ if ( meta . length === 0 ) return undefined
52
+
53
+ return rangeParser ( meta . replaceAll ( / [ { } ] / g, "" ) ) . map ( line => {
54
+ return { line, classes : [ "highlighted-line" ] }
55
+ } )
56
+ }
57
+
58
+ function parseLang ( lang ) {
59
+ if ( shikiHighlighter . getLoadedLanguages ( ) . includes ( lang ) ) return
60
+
61
+ console . error ( `The language "${ lang } " doesn't exist` )
62
+ }
63
+
33
64
// TODO: Check to see if my plugins can be replaced with official integrations.
65
+ // TODO: Implement experimental assets integration
34
66
// TODO: Move over to the content folder
35
67
// TODO: Add TS Support
0 commit comments