Skip to content

Markdown in notes #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@sveltejs/adapter-static": "1.0.0-next.13",
"date-fns": "2.23.0",
"js-search": "2.0.0",
"marked": "^11.1.1",
"redis": "3.1.2"
}
}
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/lib/components/script-notes/leaf-inner.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { marked } from 'marked'
export let text: string
$: parts = text.split(' \n')
</script>
Expand All @@ -7,5 +8,5 @@
{#if index !== 0}
<br />
{/if}
{part}
{@html marked.parseInline(part)}
{/each}
18 changes: 15 additions & 3 deletions src/lib/components/script-notes/script-notes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

type Block =
| {
type: 'p' | 'code'
type: 'p'
content: string
style: string
}
| {
type: 'code'
content: string
}
| {
Expand All @@ -17,6 +22,7 @@
type Content = Block[]

let content: Content = []

$: {
const lines = notes.split('\n\n')
content = lines.map((line) => {
Expand All @@ -42,9 +48,15 @@
}),
}
} else {
let classString = ''
if (line.startsWith('###')) classString = 'text-lg font-bold'
else if (line.startsWith('##')) classString = 'text-xl font-bold'
else if (line.startsWith('#')) classString = 'text-2xl font-bold'

return {
type: 'p',
content: line,
content: line.replace(/#+\s*/, ''),
style: classString,
}
}
})
Expand All @@ -54,7 +66,7 @@
<div class="my-3 flex flex-col space-y-2">
{#each content as block}
{#if block.type == 'p'}
<p>
<p class="{block.style}">
<Leaf text="{block.content}" />
</p>
{:else if block.type == 'ul'}
Expand Down