Skip to content

Commit 82d2f25

Browse files
committed
feat: code syntax highlight
1 parent dc1dc33 commit 82d2f25

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

html/src/index.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ pub fn index_html(
1717
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1818
<title>{owner_name} Blog</title>
1919
<link rel="stylesheet" href="{csv_file_path}">
20+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism-tomorrow.min.css">
21+
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js"></script>
22+
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
23+
<script>
24+
// Load languages on demand from the CDN
25+
if (window.Prism && Prism.plugins.autoloader) {{
26+
Prism.plugins.autoloader.languages_path = "https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/";
27+
}}
28+
</script>
2029
{icon_html}
2130
</head>
2231
<body>
@@ -156,6 +165,7 @@ pub fn index_html(
156165
searchInput.addEventListener('input', doSearch);
157166

158167
initialize();
168+
Prism.highlightAll();
159169
</script>
160170
"#,
161171
);

html/src/post.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ pub fn post_html(
3434
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
3535
<title>{title}</title>
3636
<link rel="stylesheet" href="{css_file_path}">
37+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism-tomorrow.min.css">
38+
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js"></script>
39+
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
40+
<script>
41+
// Load languages on demand from the CDN
42+
if (window.Prism && Prism.plugins.autoloader) {{
43+
Prism.plugins.autoloader.languages_path = "https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/";
44+
}}
45+
</script>
3746
{icon_html}
3847
</head>
3948
<body>
@@ -47,6 +56,7 @@ pub fn post_html(
4756
</main>
4857
</div>
4958
{footer_html}
59+
<script>Prism.highlightAll();</script>
5060
</body>
5161
</html>
5262
"#,

0 commit comments

Comments
 (0)