Closed 3goats closed 1 year ago
<script>
import Highlight from "svelte-highlight";
import json from "svelte-highlight/languages/json";
import github from "svelte-highlight/styles/github";
let url = "https://www.swapi.tech/api/people/1";
import fetchStore from "./fetch.js";
const [data, loading, error, get] = fetchStore(url);
</script>
<button on:click={get}> Fetch again </button>
{#if $loading}
Loading: {$loading}
{:else if $error}
Error: {$error}
{:else}
<Highlight language={json} code={JSON.stringify($data, null, 2)} />
{/if}
<svelte:head>
{@html github}
</svelte:head>
Thanks very much. I thought I tried this, but must have been doing something stupid. If I want to highlight an editable div before sending it as the fetch POST body/data. Is there a best way to do this ? I'm still trying to learn Svelte, so some of the concepts are new to me.
If you're seeking a proper code editor, I would recommend CodeMirror, which is what I believe the Svelte REPL uses. I don't think this library serves as an appropriate text editor.
Another example is sveld, which uses both CodeMirror and Svelte Highlight. The editable content on the left is powered by CodeMirror while the static text on the right is highlighted by this library.
Thanks for the direction here. I took a look at this. I couldn't seem to find any examples for sveld
. Also these might be an overkill for my use case at this stage. I will be repopulating the content for the POST body and only need to change a couple of the values, so really just looking for something super easy for now - Especially since I'm still trying to learn svelt.
Really just to hook a button up to the div content and have it sent to fetch.
Arh - I can see the screenshot is an example. I will take a look now.
Excellent. Thanks again. Is there a way to easily hook these up to the input and output of fetch
? i.e. Have the content of the editor sent as a POST and then hi-light the response.
Is there a way to use/access svelte-highlight from within the Githubissues.
So I need to highlight some date retuned from a remote endpoint using fetch. Could you show and example for hi-lighting the JSON returned in this REPL example:
https://svelte.dev/repl/a74f1ed8e3eb4aec82cb743e13443ee4?version=3.48.0