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

@paperfeel/preprocessor

v1.0.0

Published

Paperfeel preprocessor for SvelteKit.

Downloads

1

Readme

Overview

About

This package is a SvelteKit preprocessor that allows you to write Svelte in Markdown files. It uses unified.js under the hood to transform Markdown content and is fully customizable with remark and rehype plugins.

Installation

[!note] This is a pure ESM package. Please install on Node.js v16 or newer.

npm install -D @paperfeel/preprocessor

Usage

To use this preprocessor, make the following changes to your svelte.config.js file:

  1. Replace vitePreprocess() with paperfeel()
  2. Add .md to the list of allowed file extensions
import adapter from "@sveltejs/adapter-auto";
import { paperfeel } from "@paperfeel/preprocessor";

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

export default config;

Then add pages or components that end in .md:

---
title: My First Page
---

<script lang="ts">
    import Foo from "./Foo.svelte";
</script>

# {meta.title}
This is some example content!

<div>
    <Foo/>
</div>

[!tip] The front matter is automatically parsed and is available via the meta variable. It can also be imported from a Svelte component.

<script>
    import Foo, { meta } from "./Foo.svelte";
</script>

API

This package exports the function paperfeel. There is no default export.

paperfeel(options)

Paperfeel preprocessor.

Parameters
Returns

Preprocessor (PreprocessorGroup[]).

Options

Paperfeel preprocessor options.

Fields
  • plugins ((Plugin | [ Plugin, PluginSettings ])[], optional) — Plugins passed to unified.js. This preprocessor automatically sorts plugins and puts remark plugins in front of rehype plugins.
  • escape (string[], optional) — List of selectors for nodes in which curly braces must be escaped. The content of code nodes is automatically escaped by this preprocessor.
  • frontMatter (GrayMatterOptions, optional) — Options passed to gray-matter.
  • svelte (VitePreprocessOptions, optional) — Options passed to @sveltejs/vite-plugin-svelte.

Best Practices

Avoid Self-Closing Tags

Due to the underlying HTML parser that is used, it is best to either avoid self-closing HTML tags or to wrap them in a div. Otherwise, everything after the self-closing tag will not be rendered.

<!-- bad -->
<MyComponent/>

<!-- good -->
<MyComponent></MyComponent>

<!-- good -->
<div>
    <MyComponent/>
</div>

Keep State Handling Minimal

Markdown is primarily for writing content — if you need to handle state, it's best to put it in a separate Svelte component and import it into your Markdown.

<!-- bad -->
<script>
    let counter = 0;
    
    const increment = () => {
        counter++
    };
</script>

<button on:click={increment}>Clicks: {counter}</button>

<!-- good -->
<script>
    import Counter from "./Counter.svelte";
</script>

<div>
    <Counter/>
</div>

Frequently Asked Questions

How can I use rehype-katex with Paperfeel?

  1. In the Paperfeel preprocessor config, add rehype-katex (and optionally remark-math) to the list of plugins.
  2. Add span.katex-display to the list of nodes in which to escape the curly brackets.

[!caution] If span.katex-display is not added to escape in the config, Svelte will try to parse content inside curly brackets as JavaScript, which will ultimately fail to render.

paperfeel({
    plugins: [
        remarkMath,
        rehypeKatex
    ],
    escape: [
        "span.katex-display"
    ]
}

Contributing

Your contributions are greatly appreciated. If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue.

Acknowledgments

License