-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Markdown editor component and integrate it into AdventureModal
- Loading branch information
1 parent
7d609d0
commit dd08a6f
Showing
14 changed files
with
131 additions
and
20 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,80 @@ | ||
<script lang="ts"> | ||
import { marked } from 'marked'; // Import the markdown parser | ||
import { t } from 'svelte-i18n'; | ||
export let text: string | null | undefined = ''; // Markdown text | ||
let is_preview: boolean = false; // Toggle between Edit and Preview mode | ||
// Function to parse markdown to HTML | ||
const renderMarkdown = (markdown: string) => { | ||
return marked(markdown); | ||
}; | ||
// References for scroll syncing | ||
let editorRef: HTMLTextAreaElement | null = null; | ||
let previewRef: HTMLElement | null = null; | ||
// Sync scrolling between editor and preview | ||
const syncScroll = () => { | ||
if (editorRef && previewRef) { | ||
const ratio = editorRef.scrollTop / (editorRef.scrollHeight - editorRef.clientHeight); | ||
previewRef.scrollTop = ratio * (previewRef.scrollHeight - previewRef.clientHeight); | ||
} | ||
}; | ||
</script> | ||
|
||
<div class="join justify-center mt-2"> | ||
<button | ||
type="button" | ||
class="join-item btn btn-sm btn-outline" | ||
on:click={() => (is_preview = false)} | ||
class:btn-active={!is_preview} | ||
> | ||
{$t('transportation.edit')} | ||
</button> | ||
<button | ||
type="button" | ||
class="join-item btn btn-sm btn-outline" | ||
on:click={() => (is_preview = true)} | ||
class:btn-active={is_preview} | ||
> | ||
{$t('adventures.preview')} | ||
</button> | ||
</div> | ||
|
||
<div class="flex flex-col mt-4 gap-4"> | ||
<!-- Markdown Editor --> | ||
{#if !is_preview} | ||
<textarea | ||
class="textarea textarea-bordered resize-none h-64 w-full" | ||
bind:this={editorRef} | ||
bind:value={text} | ||
placeholder={$t('adventures.md_instructions')} | ||
on:scroll={syncScroll} | ||
></textarea> | ||
{/if} | ||
|
||
<!-- Markdown Preview --> | ||
{#if is_preview} | ||
<article | ||
class="prose overflow-auto h-96 max-w-full w-full p-4 border border-base-300 rounded-lg bg-base-300" | ||
bind:this={previewRef} | ||
> | ||
{@html renderMarkdown(text || '')} | ||
</article> | ||
{/if} | ||
</div> | ||
|
||
<style> | ||
/* Optional: Smooth scrolling for synced scroll effect */ | ||
textarea, | ||
article { | ||
scroll-behavior: smooth; | ||
} | ||
/* Force both editor and preview to have equal width */ | ||
textarea, | ||
article { | ||
width: 100%; | ||
} | ||
</style> |
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 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 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 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 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 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 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 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 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 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