Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4 add the possibility to define xss options #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ app.mount('#app')

You can use the [linkify options](https://linkify.js.org/docs/options.html).

### Define XSS Options

```vue
<template>
<div v-linkify:options="{
xssOptions: {
whiteList: {
span: ['style'],
}
},
}">
...
</div>
</template>
```

You can use the [xss options](https://jsxss.com/en/options#customize-whitelist).

### Add event listener

```vue
Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { App, Directive } from "@vue/runtime-core";
import linkifyHtml from "linkify-html";
import { Options } from "linkifyjs";
import xss from "xss";
import xss, { IFilterXSSOptions } from "xss";

const linkify = (rawHtml: string, options: Options): string => {
const sanitized = xss(rawHtml);
interface VueLinkifyOptions extends Options {
xssOptions?: IFilterXSSOptions;
}

const linkify = (rawHtml: string, options: VueLinkifyOptions): string => {
const sanitized = xss(rawHtml, options.xssOptions);
return linkifyHtml(sanitized, options);
};

Expand Down