Skip to content

Commit 683bb4a

Browse files
committed
Avoid calling hljs.highlightAll()
1 parent 7e76fdb commit 683bb4a

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script lang="ts">
2+
import hljs from 'highlight.js';
3+
import { onMount, type Snippet } from 'svelte';
4+
5+
let {
6+
children,
7+
language,
8+
nohl = false,
9+
...restProps
10+
}: {
11+
children: Snippet;
12+
language?: string;
13+
nohl?: boolean;
14+
} = $props();
15+
16+
let codeElement: HTMLElement;
17+
18+
onMount(() => {
19+
if (!nohl) {
20+
hljs.highlightElement(codeElement);
21+
}
22+
});
23+
</script>
24+
25+
<pre {...restProps}><code
26+
class={language != undefined ? 'language-' + language : ''}
27+
bind:this={codeElement}>{@render children()}</code
28+
></pre>

src/routes/+layout.svelte

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,8 @@
66
import NavBar from '$lib/components/shared/NavBar.svelte';
77
import Footer from '$lib/components/shared/Footer.svelte';
88
import SideNav from '$lib/components/shared/SideNav.svelte';
9-
import hljs from 'highlight.js';
10-
import { afterNavigate } from '$app/navigation';
11-
// import { onMount } from 'svelte';
129
1310
let { children } = $props();
14-
15-
afterNavigate(() => {
16-
hljs.highlightAll();
17-
});
18-
// onMount(() => {
19-
// hljs.highlightAll();
20-
// });
2111
</script>
2212

2313
<div class="flex min-h-screen flex-col">

src/routes/blog/articles/numworks-programming/+page.svelte

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import Article from '$lib/components/blog/Article.svelte';
33
import { NUMWORKS_PROGRAMMING } from '$lib/constants/articles';
4+
import Code from '@/components/shared/Code.svelte';
45
import Collapsible from '@/components/shared/Collapsible.svelte';
56
import Linkable from '@/components/shared/Linkable.svelte';
67
import TableOfContents from '@/components/shared/TableOfContents.svelte';
@@ -57,21 +58,21 @@
5758
the methods provided by the some modules below.
5859
</p>
5960
<Collapsible title="Kandinsky">
60-
<pre><code class="nohighlight"
61-
>get_pixel(x, y) - returns the color of the pixel at (x,y)
62-
set_pixel(x, y, color) - colors the pixel at (x,y)
63-
color(r, g, b) - defines an RGB color
64-
draw_string(text, x, y, fg, bg) - displays a string at (x, y), and if specified, with a foreground and background color
65-
fill_rect(x, y, w, h, col) - fills a rectangle spanning from (x, y) to (x + w, y + h) with a color</code
66-
></pre>
61+
<Code nohl
62+
>get_pixel(x, y) - returns the color of the pixel at (x,y) set_pixel(x, y, color) - colors the
63+
pixel at (x,y) color(r, g, b) - defines an RGB color draw_string(text, x, y, fg, bg) -
64+
displays a string at (x, y), and if specified, with a foreground and background color
65+
fill_rect(x, y, w, h, col) - fills a rectangle spanning from (x, y) to (x + w, y + h) with a
66+
color</Code
67+
>
6768
</Collapsible>
6869
<Collapsible title="Ion">
69-
<pre><code class="nohighlight">keydown(k) - returns true if the key k is down</code></pre>
70+
<Code nohl>keydown(k) - returns true if the key k is down</Code>
7071
</Collapsible><Collapsible title="Time"
71-
><pre><code class="nohighlight"
72-
>monotonic() - returns the clock's time (not to be confused with the actual time)
73-
sleep(t) - suspend execution for t seconds</code
74-
></pre>
72+
><Code nohl
73+
>monotonic() - returns the clock's time (not to be confused with the actual time) sleep(t) -
74+
suspend execution for t seconds</Code
75+
>
7576
</Collapsible>
7677
<Linkable id="limits">
7778
<p class="text-foreground text-xl font-bold">Limitations</p>
@@ -116,13 +117,13 @@ sleep(t) - suspend execution for t seconds</code
116117
and also uses a special implementation of python called MicroPython. Digging into the
117118
MicroPython source code, we can find a base definition of an object in C:
118119
</p>
119-
<pre><code class="language-c"
120-
>{`// Anything that wants to be a concrete MicroPython object must have mp_obj_base_t
120+
<Code language="c"
121+
>{`// Anything that wants to be a concrete MicroPython object must have mp_obj_base_t
121122
// as its first member (small ints, qstr objs and inline floats are not concrete).
122123
struct _mp_obj_base_t {
123124
const mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT;
124-
};`}</code
125-
></pre>
125+
};`}</Code
126+
>
126127
<p>
127128
Thus we can conclude that in MicroPython, an object takes up atleast 4 bytes (the size of a
128129
pointer). Of course, each object has a value associated to it, and with padding that brings us
@@ -163,8 +164,8 @@ struct _mp_obj_base_t {
163164
code for the header file, pulled from my latest app at the time of writing, below.
164165
</p>
165166
<Collapsible title="eadk.h">
166-
<pre class="h-96"><code class="language-c"
167-
>{`#ifndef EADK_H
167+
<Code language="c" class="h-96"
168+
>{`#ifndef EADK_H
168169
#define EADK_H
169170
170171
#include <stdbool.h>
@@ -453,8 +454,8 @@ extern size_t eadk_external_data_size;
453454
bool eadk_usb_is_plugged();
454455
uint32_t eadk_random();
455456
456-
#endif`}</code
457-
></pre>
457+
#endif`}</Code
458+
>
458459
</Collapsible>
459460
<p>
460461
This time, a lot more functions are provided. I have yet to explore all the different functions

0 commit comments

Comments
 (0)