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

@markdoc-garden/svelte-renderer

v1.0.2

Published

Render your Markdoc files in Svelte(kit).

Downloads

2

Readme

Packaging tool use to transpile between Markdoc for your templating needs and Svelte as your base Javascript framework. It allows you to render markdoc directly using a pre-processor or use a svelte component to render generated markdown trees - as and when necessary.

  • ✅ Offers a svelte component to render markdoc snippets.
  • ✅ Offers a svelte preprocessor to render markdoc files as svelte files.
  • ✅ Integrates with svelte-kit with ease, along with layouts.
  • ✅ Uses a simple config file to get markdoc configuration and custom svelte commponents.
  • ✅ Provides a plugin API with basic typing to parse markdoc-rendered, post-parsing AST.
  • ✅ Pipes results from frontmatter and plugins into variables.
  • ✅ First class typescript usage, follows conventions set by svelte-kit documentation.

Setup

  • NPM - npm install --save-dev @markdoc-garden/svelte-renderer
  • YARN - yarn add --dev @markdoc-garden/svelte-renderer
  • PNPM - pnpm add --save-dev @markdoc-garden/svelte-renderer

As a preprocessor

The first step is to add it to your svelte configuration. NOTE, that this preprocessor must be passed before vitePreprocess and extensions must include only those files that are markdoc pages.

// svelte.config.js
import adapter from "@sveltejs/adapter-auto";
import { vitePreprocess } from "@sveltejs/kit/vite";
import { markdocPreprocess } from "@markdoc-garden/svelte-renderer";

const extensions = [".md", ".markdoc"];

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: [markdocPreprocess({ extensions }), vitePreprocess()],
  extensions: [...extensions, ".svelte"],
  kit: {
    adapter: adapter(),
  },
};

export default config;

The full reference for the passed configuration to the preprocessor is:

import { markdocPreprocess } from "@markdoc-garden/svelte-renderer";

const config = {
  preprocess: [
    markupPreprocess({
      // Mandatory. These files are passed as markdoc pages
      extensions: [".md", ".markdoc"],
      // Optional, defaults to the given value. Refers an absolute path to your exported config file.
      markdocConfigPath: "src/lib/markdoc.config.js",
    }),
  ],
};

The second step is to add your own markdoc config file. You can configure the path to it, as given, and it must have three KEY exports.

// src/lib/markdoc.config.js
import type { Plugin } from "@markdoc-garden/svelte-renderer";
import type { Config } from "@markdoc/markdoc";
import type { SvelteComponent } from "svelte";

export const plugins: Plugin[] = [];
export const config: Config = {};
export const components: Record<string, typeof SvelteComponent> = [];

In a svelte-component

You can render a markdoc-renderable-tree within a svelte component too! Simply follow the markdoc documentation on how to generate a Renderable Tree Node and plug that into props along with an Object of custom svelte components.

<script>
  import { Renderer } from "@markdoc-garden/svelte-renderer";
  import md from "@markdoc/markdoc";

  import Button from "@components/Button.svelte";
  import Notification from "@components/Notification.svelte";

  const components = {
    button: Button,
    notification: Notification
  }

  const text = `# Hey, this is some markdoc!`;
  const ast = md.parse(text);
  const renderabletree = md.transform(ast);
</script>

<Renderer content={renderabletree} {components}>

Piping variable values from frontmatter

Any values declared in the frontmatter of your markdoc file will be available as a variable under the $frontmatter.[variable] scope.

---
title: Simbaaaaa!
---

# {% $frontmatter.title %}

Layouts

Since it transpiles to simple svelte components, you can add layouts and more! Simply use the standard +layout structure of svelte-kit and it simply works!

Plugins

TBD(ocumented).