
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
vue-text-highlight
Advanced tools
npm install --save vue-text-highlight
# or
yarn add vue-text-highlight
import Vue from 'vue';
import TextHighlight from 'vue-text-highlight';
Vue.component('text-highlight', TextHighlight);
// new Vue ...
<template>
<text-highlight :queries="queries">{{ description }}</text-highlight>
</template>
data() {
return {
queries: ['birds', 'scatt'],
description: 'Tropical birds scattered as Drake veered the Jeep'
};
}
All available props in TextHighlight
component are:
queries:
Array<String|RegExp>|String|RegExp
This prop accepts string, regex, and array of strings or regex. If array is given, it will highlight the union of matched strings/regex globally.
[caseSensitive]:
Boolean
Whether string being searched is case sensitive.
[diacriticsSensitive]:
Boolean
Whether string being searched is diacritics sensitive.
[highlightStyle]:
Object|Array|String
Styles to be applied to highlighted <mark>
. Similar to style bindings in vue, it accepts Array
syntax, Object
syntax, or plain styling as String
. This prop will then be merged with default highlight styles in TextHighlight
component. See style binding in Vue.js.
[highlightClass]:
Object|Array|String
Classes to be added to highlighted <mark>
. Similar to class bindings in vue, it accepts Array
syntax, Object
syntax, or class as String
. See class binding in Vue.js.
[highlightComponent]:
Object|String
By default vue-text-highlight uses <mark>
for the highlighting. Pass this props to override with other tag (string
) or custom component (Vue component definition).
This component will be passed with two props from text-highlight
:
index:
Number
Index of highlighted component.
text:
String
Highlighted words, equals to this.$slots.default[0].text
For more details, see example below.
Other props and listeners that are not listed above are forwarded to the highlighted component. These props will be merged with higher precendence than index
and text
passed from text-highlight
.
There might be a case where you want to do more things with the highlighted words. For that reason, vue-text-highlight supports custom component for the highlighted words. In this case, the following example alerts on click.
<template>
<text-highlight
:queries="queries"
:highlightComponent="MyClickableComponent"
:baz="foo"
@customlistener="alert"
>
{{ description }}
</text-highlight>
</template>
import MyClickableComponent from 'MyClickableComponent';
data() {
return {
queries: ['birds', 'scatt'],
description: 'Tropical birds scattered as Drake veered the Jeep'
MyClickableComponent,
foo: 'bar',
};
},
methods: {
alert() {},
}
<template>
<mark class="custom" @click="$emit('customlistener')">
<slot></slot>
</mark>
</template>
props: {
baz: String, // From OtherComponent.vue
index: Number, // From TextHighlight
text: String, // From TextHighlight, equals to `this.$slots.default[0].text`
}
Changes are tracked in the changelog.
vue-text-highlight is available under the MIT License.
FAQs
Text highlighter for Vue.js
The npm package vue-text-highlight receives a total of 8,140 weekly downloads. As such, vue-text-highlight popularity was classified as popular.
We found that vue-text-highlight demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.