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

@pixolith/vue-raw-html

v1.1.10

Published

Render given String as raw html

Downloads

1

Readme

Vue Raw HTML

What is this

This Directive provides a way to render a string as raw html propagating the vue scoping to all child elements, allowing you to use scoped css as you normally would.

Why

Usually for rendering raw html you would use v-html. The Problem is, depending on the input, the scoped attributes are not passed down which makes it difficult to apply scoped styling. This directive will propagate all scoped attributes down to the children which makes styling the raw html effectively no different than any other elements.

Install

npm install @pixolith/vue-raw-html

CDN

<script src="https://unpkg.com/@pixolith/vue-raw-html/dist/vue-raw-html.umd.js">

Requirements

Raw Loader (https://webpack.js.org/loaders/raw-loader/) is required to inject a raw string when requiring a file of a given type. This allows webpack to handle the filetype and pass the string to this plugin.

When using Nuxt this needs to be added to the nuxt.config.js. This example is for loading .svg file types but any external file that contains parseable html or inline html can be loaded.

    extend(config, ctx) {
        // We need to patch the url-loader regex to ignore SVG files.
        const urlLoader = config.module.rules.find(
            rule => rule.use && rule.use[0].loader === 'url-loader',
        );

        urlLoader.test = /\.(png|jpe?g|gif)$/;

        // i recommend to use the svgo-loader in conjunction since it will clean the svg beforehand
        config.module.rules.push({
            test: /\.svg$/,
            use: [
                {
                    loader: 'raw-loader',
                },
            ],
        });
    },

Please note that when not using Nuxt you will also have to add raw-loader to your webpack config for the filetype you want to load as string.

Usage

In templates as directive

Register the directive anywhere in your vue application (globally or component based) or as a plugin in Nuxt

import Vue from 'vue';
import { directive as vueRawHTML } from '@pixolith/vue-raw-html';

or es modules
import { directive as vueRawHTML } from '@pixolith/vue-raw-html/dist/vue-raw-html.module';

Vue.directive('raw-html', vueRawHTML);

this gives you access to v-raw-html="require('./logo.svg')" renderering the contents of logo.svg directly into the html. Please be aware that you need to escape your unsafe input stay safe from XSS injections.

<template>
    <div v-raw-html="require('./logo.svg')" class="my-class" />
</template>

<style lang="scss" scoped>
    .my-class {
        position: relative;
        height: 100%;
        width: 100%;
    }
</style>

will result in:

<div class="my-class" data-my-scope>
    <svg
        xmlns="http://www.w3.org/2000/svg"
        width="26"
        height="24"
        data-my-scope
    ></svg>
</div>

<style>
    div[data-my-scope].my-class {
        position: relative;
        height: 100%;
        width: 100%;
    }
</style>

As a global plugin

import Vue from 'vue';
import { install as VueRawHTML } from './../../dist/vue-raw-html.module';

Vue.install(VueRawHTML);

Pass a custom key

Vue.install(VueRawHTML, {
    key: 'cat',
});

Server Side Rendering

In order to render the directive in node.js on the server you need to pass custom instructions to the bundle renderer. See: https://ssr.vuejs.org/api/#directives

import VueRawHTML from '@pixolith/vue-raw-html';

const renderer = createRenderer({
    directives: {
        'raw-html': VueRawHTML.ssrDirective,
    },
});

This will create the directive v-cat="rawString";

Nuxt Config example for SSR

When using nuxt this can be added to nuxt.config.js. See Nuxt.js docs: https://nuxtjs.org/api/configuration-render#bundleRenderer

import VueRawHTML from '@pixolith/vue-raw-html';

bundleRenderer: {
    directives: {
        'raw-html': VueRawHTML.ssrDirective,
    }
}

With this the SSR renderer (for instance with nuxt generate) will be able to generate full html for this custom directive resulting in the full html string rendered on the server.

Donations

Even though on a company account this project is maintained on personal time. If you want to support the development of this feel free to buy me a beer at https://www.paypal.me/mdslktr.