Skip to content

Commit 010ff3a

Browse files
authored
Merge pull request #33 from asherber/markdown-in-notes
Markdown in notes
2 parents b538967 + db9be35 commit 010ff3a

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@sveltejs/adapter-static": "1.0.0-next.13",
4747
"date-fns": "2.23.0",
4848
"js-search": "2.0.0",
49+
"marked": "^11.1.1",
4950
"redis": "3.1.2"
5051
}
5152
}

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { marked } from 'marked'
23
export let text: string
34
$: parts = text.split(' \n')
45
</script>
@@ -7,5 +8,5 @@
78
{#if index !== 0}
89
<br />
910
{/if}
10-
{part}
11+
{@html marked.parseInline(part)}
1112
{/each}

src/lib/components/script-notes/script-notes.svelte

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
77
type Block =
88
| {
9-
type: 'p' | 'code'
9+
type: 'p'
10+
content: string
11+
style: string
12+
}
13+
| {
14+
type: 'code'
1015
content: string
1116
}
1217
| {
@@ -17,6 +22,7 @@
1722
type Content = Block[]
1823
1924
let content: Content = []
25+
2026
$: {
2127
const lines = notes.split('\n\n')
2228
content = lines.map((line) => {
@@ -42,9 +48,15 @@
4248
}),
4349
}
4450
} else {
51+
let classString = ''
52+
if (line.startsWith('###')) classString = 'text-lg font-bold'
53+
else if (line.startsWith('##')) classString = 'text-xl font-bold'
54+
else if (line.startsWith('#')) classString = 'text-2xl font-bold'
55+
4556
return {
4657
type: 'p',
47-
content: line,
58+
content: line.replace(/#+\s*/, ''),
59+
style: classString,
4860
}
4961
}
5062
})
@@ -54,7 +66,7 @@
5466
<div class="my-3 flex flex-col space-y-2">
5567
{#each content as block}
5668
{#if block.type == 'p'}
57-
<p>
69+
<p class="{block.style}">
5870
<Leaf text="{block.content}" />
5971
</p>
6072
{:else if block.type == 'ul'}

0 commit comments

Comments
 (0)