-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,37 @@ | ||
import n from"dompurify";var o={install(o,t={}){o.directive("dompurify-html",function(o={}){const t=n();!function(n,o){const t=n.hooks;let i;for(i in t)o.addHook(i,t[i])}(o,t);const i=function(n,i){const e=i.arg,r=o.namedConfigurations;r&&void 0!==r[e]?n.innerHTML=t.sanitize(i.value,r[e]):n.innerHTML=t.sanitize(i.value,o.default)};return{mounted:i,updated:i}}(t))}};export default o; | ||
import dompurify from "dompurify"; | ||
function setUpHooks(config, dompurifyInstance) { | ||
var _a; | ||
const hooks = (_a = config.hooks) != null ? _a : {}; | ||
let hookName; | ||
for (hookName in hooks) { | ||
const hook = hooks[hookName]; | ||
if (hook !== void 0) { | ||
dompurifyInstance.addHook(hookName, hook); | ||
} | ||
} | ||
} | ||
function buildDirective(config = {}) { | ||
const dompurifyInstance = dompurify(); | ||
setUpHooks(config, dompurifyInstance); | ||
const updateComponent = function(el, binding) { | ||
var _a, _b; | ||
const arg = binding.arg; | ||
const namedConfigurations = config.namedConfigurations; | ||
const defaultConfig = (_a = config.default) != null ? _a : {}; | ||
if (namedConfigurations && arg !== void 0) { | ||
el.innerHTML = dompurifyInstance.sanitize(binding.value, (_b = namedConfigurations[arg]) != null ? _b : defaultConfig); | ||
return; | ||
} | ||
el.innerHTML = dompurifyInstance.sanitize(binding.value, defaultConfig); | ||
}; | ||
return { | ||
mounted: updateComponent, | ||
updated: updateComponent | ||
}; | ||
} | ||
var index = { | ||
install(app, config = {}) { | ||
app.directive("dompurify-html", buildDirective(config)); | ||
} | ||
}; | ||
export { index as default }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
import { ObjectDirective } from '@vue/runtime-core'; | ||
import { HookEvent, HookName, SanitizeAttributeHookEvent, SanitizeElementHookEvent } from 'dompurify'; | ||
export interface MinimalDOMPurifyConfig { | ||
ADD_ATTR?: string[]; | ||
ADD_DATA_URI_TAGS?: string[]; | ||
ADD_TAGS?: string[]; | ||
ALLOW_DATA_ATTR?: boolean; | ||
ALLOWED_ATTR?: string[]; | ||
ALLOWED_TAGS?: string[]; | ||
FORBID_ATTR?: string[]; | ||
FORBID_TAGS?: string[]; | ||
ALLOWED_URI_REGEXP?: RegExp; | ||
ALLOW_UNKNOWN_PROTOCOLS?: boolean; | ||
ADD_ATTR?: string[] | undefined; | ||
ADD_DATA_URI_TAGS?: string[] | undefined; | ||
ADD_TAGS?: string[] | undefined; | ||
ALLOW_DATA_ATTR?: boolean | undefined; | ||
ALLOWED_ATTR?: string[] | undefined; | ||
ALLOWED_TAGS?: string[] | undefined; | ||
FORBID_ATTR?: string[] | undefined; | ||
FORBID_CONTENTS?: string[] | undefined; | ||
FORBID_TAGS?: string[] | undefined; | ||
ALLOWED_URI_REGEXP?: RegExp | undefined; | ||
ALLOW_UNKNOWN_PROTOCOLS?: boolean | undefined; | ||
USE_PROFILES?: false | { | ||
mathMl?: boolean; | ||
svg?: boolean; | ||
svgFilters?: boolean; | ||
html?: boolean; | ||
mathMl?: boolean | undefined; | ||
svg?: boolean | undefined; | ||
svgFilters?: boolean | undefined; | ||
html?: boolean | undefined; | ||
} | undefined; | ||
CUSTOM_ELEMENT_HANDLING?: { | ||
tagNameCheck?: RegExp | ((tagName: string) => boolean) | null | undefined; | ||
attributeNameCheck?: RegExp | ((lcName: string) => boolean) | null | undefined; | ||
allowCustomizedBuiltInElements?: boolean | undefined; | ||
}; | ||
} | ||
export interface DirectiveConfig { | ||
default?: MinimalDOMPurifyConfig; | ||
namedConfigurations?: Record<string, MinimalDOMPurifyConfig>; | ||
default?: MinimalDOMPurifyConfig | undefined; | ||
namedConfigurations?: Record<string, MinimalDOMPurifyConfig> | undefined; | ||
hooks?: { | ||
uponSanitizeElement?: (currentNode: Element, data: SanitizeElementHookEvent, config: MinimalDOMPurifyConfig) => void; | ||
uponSanitizeAttribute?: (currentNode: Element, data: SanitizeAttributeHookEvent, config: MinimalDOMPurifyConfig) => void; | ||
uponSanitizeElement?: ((currentNode: Element, data: SanitizeElementHookEvent, config: MinimalDOMPurifyConfig) => void) | undefined; | ||
uponSanitizeAttribute?: ((currentNode: Element, data: SanitizeAttributeHookEvent, config: MinimalDOMPurifyConfig) => void) | undefined; | ||
} & { | ||
[H in HookName]?: (currentNode: Element, data: HookEvent, config: MinimalDOMPurifyConfig) => void; | ||
[H in HookName]?: ((currentNode: Element, data: HookEvent, config: MinimalDOMPurifyConfig) => void) | undefined; | ||
}; | ||
} | ||
export declare function buildDirective(config?: DirectiveConfig): ObjectDirective<HTMLElement>; |