本文整理汇总了TypeScript中sanitize-html类的典型用法代码示例。如果您正苦于以下问题:TypeScript sanitize-html类的具体用法?TypeScript sanitize-html怎么用?TypeScript sanitize-html使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sanitize-html类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
import * as sanitize from 'sanitize-html';
let options: sanitize.IOptions = {
allowedTags: sanitize.defaults.allowedTags.concat('h1', 'h2', 'img'),
allowedAttributes: {
'a': sanitize.defaults.allowedAttributes['a'].concat('rel'),
'img': ['src', 'height', 'width', 'alt']
},
transformTags: {
'a': sanitize.simpleTransform('a', { 'rel': 'nofollow' }),
'img': (tagName: string, attribs: sanitize.Attributes) => {
let img = { tagName, attribs };
img.attribs['alt'] = 'transformed' ;
return img;
}
},
exclusiveFilter: function(frame: sanitize.IFrame) {
return frame.tag === 'a' && !frame.text.trim();
},
allowedSchemesByTag: {
'a': ['http', 'https']
},
allowProtocolRelative: false
};
let unsafe = '<div><script>alert("hello");</script></div>';
let safe = sanitize(unsafe, options);
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:28,代码来源:sanitize-html-tests.ts
示例2: validate
/**
* Checks the value stored to see if its correct in its current form
*/
public validate(): Promise<boolean | Error> {
const transformedValue = this.value;
const toRemove: number[] = [];
for ( let i = 0, l = transformedValue.length; i < l; i++ ) {
transformedValue[ i ] = sanitizeHtml( transformedValue[ i ].trim(), { allowedTags: [] } );
if ( transformedValue[ i ].trim() === '' )
toRemove.push( i );
}
// Remove any '' cells
for ( let i = toRemove.length - 1; i >= 0; i-- )
transformedValue.splice( toRemove[ i ], 1 );
const maxCharacters = this.maxCharacters;
const minCharacters = this.minCharacters;
if ( transformedValue.length < this.minItems )
return Promise.reject<Error>( new Error( `You must select at least ${this.minItems} item${( this.minItems === 1 ? '' : 's' )} for ${this.name}` ) );
if ( transformedValue.length > this.maxItems )
return Promise.reject<Error>( new Error( `You have selected too many items for ${this.name}, please only use up to ${this.maxItems}` ) );
for ( let i = 0, l = transformedValue.length; i < l; i++ ) {
transformedValue[ i ] = transformedValue[ i ].trim();
if ( transformedValue[ i ].length > maxCharacters )
return Promise.reject<Error>( new Error( `The character length of '${transformedValue[ i ]}' in ${this.name} is too long, please keep it below ${maxCharacters}` ) );
else if ( transformedValue[ i ].length < minCharacters )
return Promise.reject<Error>( new Error( `The character length of '${transformedValue[ i ]}' in ${this.name} is too short, please keep it above ${minCharacters}` ) );
}
return Promise.resolve( true );
}
开发者ID:Webinate,项目名称:modepress,代码行数:36,代码来源:schema-text-array.ts
示例3: strictSanitize
export function strictSanitize(value: string) {
const config = {
allowedAttributes: {},
allowedTags: [] as string[],
textFilter(text: string) {
return text.replace(/"/g, '"');
},
};
return sanitizeHtml(value, config);
}
开发者ID:lovett,项目名称:notifier,代码行数:11,代码来源:sanitize.ts
示例4: tolerantSanitize
export function tolerantSanitize(value: string) {
const config = {
allowedAttributes: {
a: ['href'],
},
allowedSchemes: ['http', 'https', 'mailto'],
allowedTags: ['b', 'i', 'em', 'strong', 'a', 'p'],
textFilter(text: string) {
return text.replace(/"/g, '"');
},
};
return sanitizeHtml(value, config);
}
开发者ID:lovett,项目名称:notifier,代码行数:14,代码来源:sanitize.ts
示例5: sanitize
export function sanitize(
html: string,
opts: IOptions,
overrideOpts: (opts: sanitizeHTML.IOptions) => sanitizeHTML.IOptions,
): string {
let sanitizeHTMLOpts = defaultSanitizeHTMLOptions as sanitizeHTML.IOptions;
// Apply ting options
opts = opts || {};
sanitizeHTMLOpts.exclusiveFilter = (frame: sanitizeHTML.IFrame): boolean => {
if (frame.attribs.id) {
// id attribute is not allowed unless opts.idFilter returns true
return opts.idFilter ? !opts.idFilter(frame.attribs.id as string) : true;
}
return false;
};
if (overrideOpts) {
sanitizeHTMLOpts = overrideOpts(sanitizeHTMLOpts);
}
return sanitizeHTML(html, sanitizeHTMLOpts);
}
开发者ID:mgenware,项目名称:ting,代码行数:23,代码来源:main.ts
示例6: sanitize_
export const sanitize = (arg: string) => {
return sanitize_(arg, { allowedTags });
};
开发者ID:CrossLead,项目名称:crosslead-adapters,代码行数:3,代码来源:util.ts
注:本文中的sanitize-html类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论