{children}
21 | }
22 |
23 | const html = Prism.highlight(String(children), Prism.languages[language], language)
24 | return
25 | }
26 |
27 | const EJS_REGEX = /<%([\s\S]+?)%>/g
28 |
29 | export function TemplateSyntaxHighlighter({ children }: { children: string }) {
30 | const html = children.replace(EJS_REGEX, (_, code) => {
31 | const highlighted = Prism.highlight(code, Prism.languages.javascript, "javascript")
32 | return `<%${highlighted}%>`
33 | })
34 |
35 | return
36 | }
37 |
--------------------------------------------------------------------------------
/src/components/tag-link.tsx:
--------------------------------------------------------------------------------
1 | import { Link } from "@tanstack/react-router"
2 | import React from "react"
3 | import { cx } from "../utils/cx"
4 |
5 | type TagLinkProps = {
6 | name: string
7 | className?: string
8 | }
9 |
10 | export function TagLink({ name, className }: TagLinkProps) {
11 | return (
12 |
13 | #
14 | {name.split("/").map((part, i) => {
15 | return (
16 | []
`, 26 | }, 27 | { 28 | input: `[[![[123]]]]`, 29 | output: `[[]]
`, 30 | }, 31 | { 32 | input: `\`\`\` 33 | ![[123]] 34 | \`\`\``, 35 | output: `![[123]]
36 |
`,
37 | },
38 | {
39 | input: `\`![[123]]\``,
40 | output: `![[123]]
`, 45 | }, 46 | { 47 | input: `- ![[123]]`, 48 | output: `
`, 63 | }, 64 | { 65 | input: `![[123x]]`, 66 | output: ``, 67 | }, 68 | { 69 | input: `![[x]]`, 70 | output: ``, 71 | }, 72 | { 73 | input: `![[x|y]]`, 74 | output: ``, 75 | }, 76 | { 77 | input: `![[Hello world|foo]]`, 78 | output: ``, 79 | }, 80 | { 81 | input: `![[foo.bar]]`, 82 | output: ``, 83 | }, 84 | 85 | // Invalid note links 86 | { 87 | input: `hello`, 88 | output: `
hello
`, 89 | }, 90 | { 91 | input: `[[123]]`, 92 | output: `[[123]]
`, 93 | }, 94 | { 95 | input: `[`, 96 | output: `[
`, 97 | }, 98 | { 99 | input: `![[`, 100 | output: `![[
`, 101 | }, 102 | { 103 | input: `![[]]`, 104 | output: `![[]]
`, 105 | }, 106 | { 107 | input: `![[123]`, 108 | output: `![[123]
`, 109 | }, 110 | { 111 | input: `![[123`, 112 | output: `![[123
`, 113 | }, 114 | { 115 | input: `[123]]`, 116 | output: `[123]]
`, 117 | }, 118 | { 119 | input: `123]]`, 120 | output: `123]]
`, 121 | }, 122 | { 123 | input: `[123]`, 124 | output: `[123]
`, 125 | }, 126 | { 127 | input: `![[123|]]`, 128 | output: `![[123|]]
`, 129 | }, 130 | ]) 131 | -------------------------------------------------------------------------------- /src/remark-plugins/wikilink.test.ts: -------------------------------------------------------------------------------- 1 | import { micromark } from "micromark" 2 | import { expect, test } from "vitest" 3 | import { wikilink, wikilinkHtml } from "./wikilink" 4 | 5 | function runTests(tests: Array<{ input: string; output: string }>) { 6 | for (const { input, output } of tests) { 7 | test(input, () => { 8 | const html = micromark(input, { 9 | extensions: [wikilink()], 10 | htmlExtensions: [wikilinkHtml()], 11 | }) 12 | expect(html).toBe(output) 13 | }) 14 | } 15 | } 16 | 17 | runTests([ 18 | // Valid wikilinks 19 | { 20 | input: `[[123]]`, 21 | output: `[
[[
[[123]]
36 |
`,
37 | },
38 | {
39 | input: `\`[[123]]\``,
40 | output: `[[123]]
hello
`, 89 | }, 90 | { 91 | input: `[`, 92 | output: `[
`, 93 | }, 94 | { 95 | input: `[[`, 96 | output: `[[
`, 97 | }, 98 | { 99 | input: `[[]]`, 100 | output: `[[]]
`, 101 | }, 102 | { 103 | input: `[[123]`, 104 | output: `[[123]
`, 105 | }, 106 | { 107 | input: `[[123`, 108 | output: `[[123
`, 109 | }, 110 | { 111 | input: `[123]]`, 112 | output: `[123]]
`, 113 | }, 114 | { 115 | input: `123]]`, 116 | output: `123]]
`, 117 | }, 118 | { 119 | input: `[123]`, 120 | output: `[123]
`, 121 | }, 122 | { 123 | input: `[[123|]]`, 124 | output: `[[123|]]
`, 125 | }, 126 | ]) 127 | -------------------------------------------------------------------------------- /src/routes/__root.tsx: -------------------------------------------------------------------------------- 1 | import { HeadContent, Link, Outlet, createRootRoute } from "@tanstack/react-router" 2 | import { useThemeColor } from "../hooks/theme-color" 3 | import { createPortal } from "react-dom" 4 | 5 | export const Route = createRootRoute({ 6 | component: RootComponent, 7 | notFoundComponent: NotFoundComponent, 8 | head: () => ({ 9 | meta: [{ title: "Lumen" }], 10 | }), 11 | }) 12 | 13 | function NotFoundComponent() { 14 | return ( 15 |