Skip to content

Commit 11082d7

Browse files
committed
Add code highlighting
1 parent 1708d9c commit 11082d7

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ mdsycx = { git = "https://github.com/lukechu10/mdsycx", rev = "eb1ac15" }
1111
serde = { version = "1.0.210", features = ["derive"] }
1212
sycamore = "0.9.0-beta.4"
1313
sycamore-router = "0.9.0-beta.4"
14+
wasm-bindgen = "0.2.93"
1415

assets/index.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@
9191
}
9292

9393
code {
94-
@apply text-sm;
94+
@apply !text-sm;
9595
}
9696

9797
code:not(pre code) {
9898
@apply font-mono bg-gray-700 px-1.5 py-0.5 rounded;
9999
}
100100

101-
pre code {
102-
@apply block bg-gray-800 p-4 rounded mb-4;
101+
pre {
102+
@apply block !bg-slate-800 p-4 rounded mb-4 !leading-snug !py-3 !px-5;
103103
}
104104

105105
blockquote {

assets/prism.css

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/prism.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<link data-trunk rel="tailwind-css" href="assets/index.scss" />
77
<link data-trunk rel="copy-file" href="404.html" />
88
<link data-trunk rel="copy-dir" href="assets" />
9+
10+
<link type="text/css" rel="stylesheet" href="/assets/prism.css" />
11+
<script type="text/javascript" src="/assets/prism.js"></script>
12+
913
<script type="text/javascript">
1014
// Single Page Apps for GitHub Pages
1115
// MIT License

src/pages/post.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{collections::HashMap, sync::LazyLock};
22

33
use include_dir::{include_dir, Dir};
44
use mdsycx::ParseRes;
5+
use wasm_bindgen::prelude::*;
56
use serde::Deserialize;
67
use sycamore::prelude::*;
78

@@ -75,6 +76,9 @@ pub fn PostView(id: String) -> View {
7576
crate::shell::NotFound()
7677
};
7778
};
79+
on_mount(move || {
80+
highlightAll();
81+
});
7882
view! {
7983
div(class="max-w-prose mx-auto") {
8084
crate::components::ShowDate(date=post.front_matter.date)
@@ -84,3 +88,9 @@ pub fn PostView(id: String) -> View {
8488
}
8589
}
8690
}
91+
92+
#[wasm_bindgen]
93+
extern "C" {
94+
#[wasm_bindgen(js_namespace = Prism)]
95+
fn highlightAll();
96+
}

0 commit comments

Comments
 (0)