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-preprocess-escape

v0.1.0

Published

A [Svelte](https://github.com/sveltejs/svelte) preprocesor that allows escaping content within components or elements. In simpler terms: this lets you open a compiler escape hatch to render Svelte code within Svelte components. This is particularly useful

Downloads

2

Readme

svelte-preprocess-escape

A Svelte preprocesor that allows escaping content within components or elements. In simpler terms: this lets you open a compiler escape hatch to render Svelte code within Svelte components. This is particularly useful for displaying example Svelte code (or whatever else you might want) within code blocks.

IMPORTANT: The implementation here is pretty rough/experimental, hasn't been significantly dogfooded or tested, and was designed only to solve something within my own particular problem space. This may work reasonably well for you -- or not at all.

Installing

npm install svelte-preprocess-escape --save-dev

Or, if you're using Yarn:

yarn add svelte-preprocess-escape --dev

Basic Usage Example

// svelte.config.js
import escape from 'svelte-preprocess-escape' // the preprocessor is default-exported
import preprocess from 'svelte-preprocess'

/** @type {import('@sveltejs/kit').Config} */
const config = {
  // If using svelte-preprocess, ensure `escape()` precedes it in the
  // preprocessor list
  preprocess: [escape(), preprocess()],
  kit: {
    adapter: adapter(),
    target: '#svelte'
  },
  ...
}
<!-- component.svelte -->
<h1>Regular Old Markup</h1>

<pre>
  <code escape-content>
    <script lang="ts">
      const f = () => {
        return true
      }
    </script>
  
    <style lang="scss">
      a {
        color: red;
      }
    </style>
  </code>
</pre>

In this example, since the escape-content attribute is present on the <code> element, the content therein will simply render as text, maintaining any indendation (thanks to <pre>). The preprocessor automatically dedents the content, so it renders as you'd expect.

Note that the preprocessor will simply ignore any nested instances of elements or components marked with escape-content, so there's no option to nest within them, nor is there an option to break out of them.

Options

You can supply a few options as an object to the exported function:

| Property | Type | Default | Description | |-------------|----------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | tag | string | escape-content | The attribute name to supply. E.g., | | extensions | string[] | ['.svelte'] | The file extensions the preprocessor will be available to act on | | highlighter | function | | An optional highlighter function, useful for performing code highlighting on the escaped contents. Must conform to the signature (code: string, filename?: string) => string |

Building

This project uses the built-in packaging functionality of SvelteKit to generate the package code. To build outside of the usual package management environment:

git clone [email protected]:boatilus/svelte-preprocess-escape.git
cd svelte-preprocess-escape
npm install
npm package

This will produce a /package directory containing the TypeScript source transpiled to JavaScript, as well as a TypeScript definition file.

License

MIT