本文整理汇总了TypeScript中he.encode函数的典型用法代码示例。如果您正苦于以下问题:TypeScript encode函数的具体用法?TypeScript encode怎么用?TypeScript encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
this.renderer.link = function(href, title, text) {
if (!href) {
return marked.Renderer.prototype.link.call(this, href, title, text);
}
if (this.options.sanitize) {
try {
const prot = decodeURIComponent(unescape(href))
.replace(/[^\w:]/g, '')
.toLowerCase();
if (prot.startsWith('javascript:') || prot.startsWith('vbscript:')) {
return '';
}
} catch (e) {
return '';
}
}
let onclick = 'cancelClick(event)';
if (href.startsWith('http://') || href.startsWith('https://')) {
onclick = 'openLinkWithExternalBrowser(event)';
} else if (re_ext.test(href)) {
onclick = 'openMarkdownLink(event)';
} else if (href.indexOf('#') !== -1) {
onclick = 'openHashLink(event)';
}
self.link_id += 1;
const id = `md-link-${self.link_id}`;
self.tooltips += `<paper-tooltip for="${id}" offset="0">${he.encode(href)}</paper-tooltip>`;
return title !== null ?
`<a id="${id}" href="${href}" onclick="${onclick}" title=${title}>${text}</a>` :
`<a id="${id}" href="${href}" onclick="${onclick}">${text}</a>`;
};
示例2: commandPaletteFormatEntry
function commandPaletteFormatEntry(entry: CommandMenuItem, selected: boolean, extraClassString = ""): string {
return `<div class='${PopDownListPicker.CLASS_RESULT_ENTRY} ${selected ? PopDownListPicker.CLASS_RESULT_SELECTED : ""} ${extraClassString}' ${PopDownListPicker.ATTR_DATA_ID}='${entry.id}'>
<div class='${CLASS_RESULT_ICON_LEFT}'>${commandPaletteFormatIcon(entry.iconLeft)}</div>
<div class='${CLASS_RESULT_ICON_RIGHT}'>${commandPaletteFormatIcon(entry.iconRight)}</div>
<div class='${CLASS_RESULT_LABEL}'>${he.encode(entry.label)}</div>
<div class='${CLASS_RESULT_SHORTCUT}'>${entry.shortcut !== undefined && entry.shortcut !== null ? he.encode(entry.shortcut) : ""}</div>
</div>`;
}
示例3: parseSrcSet
opts => {
const parsed = parseSrcSet(he.decode(opts.srcset));
const firstCandidate: { url?: string } = parsed[0];
const { url } = firstCandidate || { url: null };
let encodedUrl = '';
// Must re-encode url prior to comparison with expected string.
if (url !== null) {
encodedUrl = he.encode(url);
} else {
encodedUrl = '';
}
expect(encodedUrl).toStrictEqual(opts.expect);
},
示例4: generateStackblitzContent
function generateStackblitzContent(componentName, demoName) {
const fileName = `${componentName}-${demoName}`;
const basePath = `demo/src/app/components/${componentName}/demos/${demoName}/${fileName}`;
const codeContent = fs.readFileSync(`${basePath}.ts`).toString();
const markupContent = fs.readFileSync(`${basePath}.html`).toString();
return `<!DOCTYPE html>
<html lang="en">
<body>
<form id="mainForm" method="post" action="${stackblitzUrl}">
<input type="hidden" name="description" value="Example usage of the ${componentName} widget from https://ng-bootstrap.github.io">
${generateTags(['Angular', 'Bootstrap', 'ng-bootstrap', capitalize(componentName)])}
<input type="hidden" name="files[.angular-cli.json]" value="${he.encode(getStackblitzTemplate('.angular-cli.json'))}">
<input type="hidden" name="files[index.html]" value="${he.encode(generateIndexHtml())}">
<input type="hidden" name="files[main.ts]" value="${he.encode(getStackblitzTemplate('main.ts'))}">
<input type="hidden" name="files[polyfills.ts]" value="${he.encode(getStackblitzTemplate('polyfills.ts'))}">
<input type="hidden" name="files[styles.css]" value="${he.encode(generateDemosCSS())}">
<input type="hidden" name="files[app/app.module.ts]" value="${he.encode(generateAppModuleTsContent(componentName, demoName, basePath + '.ts'))}">
<input type="hidden" name="files[app/app.component.ts]" value="${he.encode(getStackblitzTemplate('app/app.component.ts'))}">
<input type="hidden" name="files[app/app.component.html]" value="${he.encode(generateAppComponentHtmlContent(componentName, demoName))}">
<input type="hidden" name="files[app/${fileName}.ts]" value="${he.encode(codeContent)}">
<input type="hidden" name="files[app/${fileName}.html]" value="${he.encode(markupContent)}">
<input type="hidden" name="dependencies" value="${he.encode(JSON.stringify(generateDependencies()))}">
</form>
<script>document.getElementById("mainForm").submit();</script>
</body>
</html>`;
}
示例5: highlight
let mermaid: any = undefined;
marked.setOptions({
langPrefix: 'hljs ',
highlight(code: string, lang: string): string {
if (lang === undefined) {
return code;
}
if (lang === 'mermaid') {
if (mermaid === undefined) {
mermaid = require('mermaid');
mermaid.init(undefined, 'div.mermaid');
}
return '<div class="mermaid">' + he.encode(code) + '</div>';
}
if (lang === 'katex') {
return '<div class="katex">' + katex.renderToString(code, { displayMode: true }) + '</div>';
}
try {
return highlight(lang, code).value;
} catch (e) {
console.log('Error on highlight: ' + e.message);
return code;
}
},
// @ts-ignore: emoji is a dedicated method added by my fork