npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-markdown-input

v0.0.2

Published

A simple Markdown input with preview for Svelte

Downloads

88

Readme

svelte-markdown-input

A simple markdown input action and store for Svelte. Designed for simple inputs of HTML snippets.

By itself, the package is 473 bytes minified, 304 bytes minified and gzipped. The micromark package will add about 14Kb to your page, and including GFM will make it aroubnd 22Kb.

Usage

Installation

Install using your package manager of choice, e.g.

pnpm i -D svelte-markdown-input

Basic Usage

Import the createMarkdown factory function to create an instance of the combined action / store. Apply it to a textarea via use:markdown and output the rendered HTML using {@html $markdown}:

<script lang="ts">
  import { createMarkdown } from 'svelte-markdown-input'

  const markdown = createMarkdown()
</script>

<textarea use:markdown></textarea>
<div>{@html $markdown}</div>

Options

Pass an options object to the createMarkdown factory function to set additional options. These currently support:

debounce - time in ms to debounce input / rendering (default 60) micromark_options - allows setting micromark options (default undefined)

The micromark_options give you the ability to control the Markdown-to-HTML rendering. You could, for instance, decide to enable Github Flavored Markdown, and wrap things up into an easy-to-use input component (this is what the demo uses):

<script lang="ts">
  import { createMarkdown } from 'svelte-markdown-input'
  import { gfm, gfmHtml } from 'micromark-extension-gfm'
  import 'github-markdown-css/github-markdown-light.css'

  export let hidden = 'lg:hidden'
  export let shown = 'lg:block'
  export let value = ''
  export let allow_gfm = false

  const markdown = createMarkdown({
    debounce: 60,
    micromark_options: allow_gfm
      ? {
        allowDangerousHtml: true,
        extensions: [gfm()],
        htmlExtensions: [gfmHtml()],
      }
      : undefined,
  })

  let editing = true
</script>

<div class="h-full flex flex-col">
  <div class="{hidden} flex items-center mb-2">
    <button class="px-3 py-1.5 border border-transparent text-sm font-medium rounded-md {editing ? 'text-gray-900 bg-gray-100 hover:bg-gray-200' : 'text-gray-500 hover:text-gray-900 bg-white hover:bg-gray-100'}" role="tab" type="button" on:click={() => editing = true}>Write</button>
    <button class="ml-2 px-3 py-1.5 border border-transparent text-sm font-medium rounded-md {!editing ? 'text-gray-900 bg-gray-100 hover:bg-gray-200' : 'text-gray-500 hover:text-gray-900 bg-white hover:bg-gray-100'}"  role="tab" type="button" on:click={() => editing = false}>Preview</button>
  </div>

  <div class="h-full flex gap-2 overflow-hidden">
    <textarea class="flex-1 m-0.5 border border-gray-200 rounded-md p-4 overflow-scroll font-mono text-sm resize-none {shown}" class:hidden={!editing} use:markdown bind:value></textarea>
    <div class="flex-1 m-0.5 border border-gray-200 rounded-md p-4 overflow-scroll max-w-full {shown} markdown-body" class:hidden={editing}>{@html $markdown}</div>
  </div>
</div>