Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kamiazya/vue-highlight

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kamiazya/vue-highlight

Vue(3+) directive for highlighting keywords in text

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

License: MIT PRs Welcome

@kamiazya/vue-highlight ✨

Vue(3+) directive for highlighting keywords in text.

You can highlight matching keywords in the text within a given element with your own CSS.

Internally, it uses the Custom Highlighting API, so it does not corrupt the DOM.

Installation 📥

# By npm
$ npm install @kamiazya/vue-highlight
# By yarn
$ yarn add @kamiazya/vue-highlight
# By pnpm
$ pnpm add @kamiazya/vue-highlight

Usage 📘

Basic usage

Highlight the keyword "bar" in the text "foo bar baz".

<script setup>
import { ref } from "vue";
import vHighlight from "@kamiazya/vue-highlight";

const keyword = ref("bar");
</script>

<template>
  <div v-highlight="keyword">
    foo bar baz
  </div>
</template>
<style>
::highlight(v-highlight) {
  background-color: yellow;
  color: black;
}
</style>

If you want to use v-highlight directive in global, you can register the vHighlight direvtive to app instance.

import { vHighlight } from '@kamiazya/vue-highlight'; // Import the directive
import { createApp } from 'vue';

import App from './src/App.vue';

const app = createApp(App);
app.directive('highlight', vHighlight); // Register the directive
app.mount('#container');

Multiple keywords

Highlight the keywords "foo" and "baz" in the text "foo bar baz".

<script setup>
import { ref } from "vue";
import vHighlight from "@kamiazya/vue-highlight";

const keyword = ref(["foo", "baz"]);
</script>

<template>
<div v-highlight="keyword">
  foo bar baz
</div>
</template>
<style>
::highlight(v-highlight) {
  background-color: yellow;
  color: black;
}
</style>

Custom highlight name

Highlight the keyword "bar" in the text "foo bar baz" with a custom highlight name.

<script setup>
import { ref } from "vue";
import vHighlight from "@kamiazya/vue-highlight";

const keyword = ref("bar");
</script>

<template>
<div v-highlight:my-custom-highlight="keyword">
foo bar baz
</div>
</template>
<style>
::highlight(my-custom-highlight) {
  background-color: yellow;
  color: black;
}
</style>

Multiple highlights

Highlight the keywords "foo" and "baz" in the text "foo bar baz" with multiple highlights.

<script setup>
import { ref } from "vue";
import vHighlight from "@kamiazya/vue-highlight";

const keyword1 = ref("bar");
const keyword2 = ref("foo");
</script>

<template>
<div
  v-highlight:highlight1="keyword1"
  v-highlight:highlight2="keyword2"
>
foo bar baz
</div>
</template>
<style>
::highlight(highlight1) {
  background-color: yellow;
  color: black;
}
::highlight(highlight2) {
  background-color: red;
  color: white;
}
</style>

License ⚖️

This software is released under the MIT License, see LICENSE.

Keywords

FAQs

Package last updated on 24 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc