-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,571 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script lang="ts" module> | ||
const HyperMD_ = await import("hypermd"); | ||
const loadingP = Promise.all([ | ||
// Load these modes if you want highlighting ... | ||
import("codemirror/mode/htmlmixed/htmlmixed.js"), // for embedded HTML. | ||
import("codemirror/mode/stex/stex.js"), // for Math TeX Formulae. | ||
import("codemirror/mode/yaml/yaml.js"), // for frontmatter. | ||
// Load PowerPacks if you want to use 3rd-party libraries for enhanced features... | ||
import("hypermd/powerpack/fold-math-with-katex.js"), | ||
import("hypermd/powerpack/hover-with-marked.js"), | ||
]); | ||
</script> | ||
|
||
<script lang="ts"> | ||
export interface Props { | ||
value: string; | ||
mode: "hypermd" | "normal"; | ||
} | ||
let { mode = $bindable(), value = $bindable() }: Props = $props(); | ||
let editor: CodeMirror.Editor; | ||
let textarea: HTMLTextAreaElement; | ||
// eslint-disable-next-line unicorn/prefer-top-level-await | ||
void (async () => { | ||
await loadingP; | ||
// @ts-expect-error(TS2454): Using `bind:this`. | ||
editor = HyperMD_.fromTextArea(textarea); | ||
editor.setSize(null, "200%"); | ||
editor.focus(); | ||
})(); | ||
let isMounting = true; | ||
$effect(() => { | ||
// Force the effect to run if the mode changes. | ||
mode = mode; | ||
if (isMounting) { | ||
isMounting = false; | ||
return; | ||
} | ||
if (mode === "hypermd") { | ||
HyperMD_.switchToHyperMD(editor); | ||
} else { | ||
HyperMD_.switchToNormal(editor); | ||
} | ||
}); | ||
</script> | ||
|
||
<textarea bind:this={textarea} bind:value></textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module "codemirror/mode/htmlmixed/htmlmixed.js" {} | ||
declare module "codemirror/mode/stex/stex.js" {} | ||
declare module "codemirror/mode/yaml/yaml.js" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,61 @@ | ||
<script lang="ts"> | ||
import { sveltekitUrl as svelteKitDocsUrl } from "$lib/demo.ts"; | ||
import HyperMDC from "$lib/hypermd.svelte"; | ||
let mode: "hypermd" | "normal" = $state("hypermd"); | ||
const value = `--- | ||
title: Hello, HyperMD! | ||
--- | ||
# Your HyperMD editor is here | ||
![Logo](/favicon.png) | ||
Maybe you prefer the hard ~~core~~ code way, want to import all libraries manually 🤘. | ||
No problem! HyperMD provides ai1 (all-in-one) single-file bundle :gift:! | ||
**Check-out this page's source code.** It just imports all the stuff, without any trick! | ||
------------------- | ||
All built-in features are ready-to-go. You may manipulate the editor via cm or HyperMD global variables. Try out: | ||
1. \`HyperMD.switchToNormal(cm)\` | ||
2. \`HyperMD.switchToHyperMD(cm)\` | ||
3. \`cm.getValue()\` returns the Markdown source text | ||
**Note**: This demo is using these powerpacks and 3rd-party libs and services. Special thanks to them! | ||
1. **fold-math-with-katex** uses _KaTeX_, the math typesetting library. | ||
2. **hover-with-marked** uses _marked_ to render footnotes[^1]. | ||
[^1]: Like this one! | ||
[hypermd-doc]: https://laobubu.net/HyperMD/docs/ HyperMD documentation | ||
[cm-manual]: https://codemirror.net/doc/manual.html CodeMirror User manual | ||
`; | ||
</script> | ||
|
||
<h1>Welcome to SvelteKit</h1> | ||
<p> | ||
Visit <a href={svelteKitDocsUrl}>svelte.dev/docs/kit</a> to read the documentation | ||
</p> | ||
<div> | ||
<button | ||
class="rounded-sm border px-2 py-0.5" | ||
onclick={() => { | ||
mode = "normal"; | ||
}} | ||
type="button" | ||
> | ||
Switch To Normal | ||
</button> | ||
<button | ||
class="rounded-md border px-2 py-0.5" | ||
onclick={() => { | ||
mode = "hypermd"; | ||
}} | ||
type="button" | ||
> | ||
Switch To HyperMD | ||
</button> | ||
</div> | ||
|
||
<HyperMDC {value} bind:mode /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { sveltekitUrl } from "$lib/demo"; | ||
import { describe, test } from "vitest"; | ||
|
||
describe("demo test", () => { | ||
test("svelte is secure", ({ expect }) => { | ||
expect(sveltekitUrl).toMatch(/^https:\/\//); | ||
expect("https://svelte.dev/").toMatch(/^https:\/\//); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.