UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

1 lines 4.74 kB
{"version":3,"file":"ng-zorro-antd-core-highlight.mjs","sources":["../../components/core/highlight/highlight.pipe.ts","../../components/core/highlight/highlight.module.ts","../../components/core/highlight/public-api.ts","../../components/core/highlight/ng-zorro-antd-core-highlight.ts"],"sourcesContent":["/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { Pipe, PipeTransform } from '@angular/core';\n\n// Regular Expressions for parsing tags and attributes\nconst SURROGATE_PAIR_REGEXP = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n// ! to ~ is the ASCII range.\nconst NON_ALPHANUMERIC_REGEXP = /([^\\#-~ |!])/g;\n\n/**\n * Escapes all potentially dangerous characters, so that the\n * resulting string can be safely inserted into attribute or\n * element text.\n */\nfunction encodeEntities(value: string): string {\n return value\n .replace(/&/g, '&amp;')\n .replace(SURROGATE_PAIR_REGEXP, (match: string) => {\n const hi = match.charCodeAt(0);\n const low = match.charCodeAt(1);\n return `&#${(hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000};`;\n })\n .replace(NON_ALPHANUMERIC_REGEXP, (match: string) => `&#${match.charCodeAt(0)};`)\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;');\n}\n\n@Pipe({\n name: 'nzHighlight',\n pure: true\n})\nexport class NzHighlightPipe implements PipeTransform {\n private UNIQUE_WRAPPERS: [string, string] = ['##==-open_tag-==##', '##==-close_tag-==##'];\n\n transform(value: string, highlightValue: string, flags?: string, klass?: string): string | null {\n if (!highlightValue) {\n return value;\n }\n\n // Escapes regex keyword to interpret these characters literally\n const searchValue = new RegExp(highlightValue.replace(/([.*+?^=!:${}()|[\\]\\/\\\\])/g, '\\\\$&'), flags);\n const wrapValue = value.replace(searchValue, `${this.UNIQUE_WRAPPERS[0]}$&${this.UNIQUE_WRAPPERS[1]}`);\n return encodeEntities(wrapValue)\n .replace(new RegExp(this.UNIQUE_WRAPPERS[0], 'g'), klass ? `<span class=\"${klass}\">` : '<span>')\n .replace(new RegExp(this.UNIQUE_WRAPPERS[1], 'g'), '</span>');\n }\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { CommonModule } from '@angular/common';\nimport { NgModule } from '@angular/core';\n\nimport { NzHighlightPipe } from './highlight.pipe';\n\n@NgModule({\n imports: [CommonModule],\n exports: [NzHighlightPipe],\n declarations: [NzHighlightPipe]\n})\nexport class NzHighlightModule {}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nexport * from './highlight.pipe';\nexport * from './highlight.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAAA;;;;AAOA;AACA,MAAM,qBAAqB,GAAG,iCAAiC,CAAC;AAChE;AACA,MAAM,uBAAuB,GAAG,eAAe,CAAC;AAEhD;;;;;AAKA,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,KAAK;SACT,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,qBAAqB,EAAE,CAAC,KAAa;QAC5C,MAAM,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC,EAAE,GAAG,MAAM,IAAI,KAAK,IAAI,GAAG,GAAG,MAAM,CAAC,GAAG,OAAO,GAAG,CAAC;KACjE,CAAC;SACD,OAAO,CAAC,uBAAuB,EAAE,CAAC,KAAa,KAAK,KAAK,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;SAChF,OAAO,CAAC,IA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