本文整理汇总了TypeScript中html-entities.AllHtmlEntities.decode方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AllHtmlEntities.decode方法的具体用法?TypeScript AllHtmlEntities.decode怎么用?TypeScript AllHtmlEntities.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类html-entities.AllHtmlEntities
的用法示例。
在下文中一共展示了AllHtmlEntities.decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: crawl
async function crawl(publicId: string) {
const $search = await $crawl(`http://weixin.sogou.com/weixin?type=1&query=${publicId}`)
const url = entities.decode($search('.results > div').attr('href'))
const response = await fetch(url, wxFetchOptions)
const text = await response.text()
const regex = /var msgList = '(.+?)';/
const matches = text.match(regex)
if (matches) {
const data = JSON.parse(entities.decode(entities.decode(matches[1])))
const articles = data.list.map(({app_msg_ext_info}) => {
const {author, content_url, title} = app_msg_ext_info
return {author, url: `https://mp.weixin.qq.com${content_url.replace(/\\\//g, '/')}`, title}
})
console.log(articles)
for (let i = 0; i < articles.length; i++) {
const {url} = articles[i]
const $detailPage = await $crawl(url)
$detailPage('#js_content img').each((index, element) => {
const $element = $detailPage(element)
const style = $element.attr('style')
$element.replaceWith(`<img src='${$element.attr('data-src')}'${style ? ` style='${style}'` : ''}/>`)
})
const $content = $detailPage('#js_content')
console.log($content.html())
break
}
} else {
console.log('not matched')
}
}
示例2:
result.answers.forEach((ans) => {
ans.score /= 100;
ans.answer = htmlentities.decode(ans.answer);
var answerEntity = {
score: ans.score,
entity: ans.answer,
type: 'answer'
}
answerEntities.push(answerEntity as builder.IEntity);
});
示例3: code
code(code: string, lang: string, escaped?: boolean) {
if (escaped) {
code = entities.decode(code);
}
// These three lines are the reason for this entire file!
// Here we automatically detect the language for the given code snippet
// and inject it into the output markdown.
if (!lang) {
lang = inferLanguage(code);
}
return `\`\`\`${lang}\n${code}\n\`\`\`\n\n`;
}
示例4:
import * as htmlEntities from "html-entities";
let entities = new htmlEntities.AllHtmlEntities();
console.log(entities.encode('<>"\'&©®')); // <>"'&©®
console.log(entities.encodeNonUTF('<>"\'&©®')); // <>"'&©®
console.log(entities.encodeNonASCII('<>"\'&©®')); // <>"\'&©®
console.log(entities.decode('<>"'&©®∆')); // <>"'&©®∆
示例5: or
client.fetch(url.href).then((result: any) => {
if (result.error !== undefined && result.error !== null) {
return res.sendStatus(204);
}
const contentType: string = result.response.headers['content-type'];
// HTMLじゃなかった場合は中止
if (contentType.indexOf('text/html') === -1) {
return res.sendStatus(204);
}
const $: any = result.$;
let title = or(
$('meta[property="misskey:title"]').attr('content'),
$('meta[property="og:title"]').attr('content'),
$('meta[property="twitter:title"]').attr('content'),
$('title').text());
if (title === null) {
return res.sendStatus(204);
}
title = clip(entities.decode(title), 100);
const lang: string = $('html').attr('lang');
const type = or(
$('meta[property="misskey:type"]').attr('content'),
$('meta[property="og:type"]').attr('content'));
let image = or(
$('meta[property="misskey:image"]').attr('content'),
$('meta[property="og:image"]').attr('content'),
$('meta[property="twitter:image"]').attr('content'),
$('link[rel="image_src"]').attr('href'),
$('link[rel="apple-touch-icon"]').attr('href'),
$('link[rel="apple-touch-icon image_src"]').attr('href'));
image = image !== null ? wrapMisskeyProxy(URL.resolve(url.href, image)) : null;
let description = or(
$('meta[property="misskey:summary"]').attr('content'),
$('meta[property="og:description"]').attr('content'),
$('meta[property="twitter:description"]').attr('content'),
$('meta[name="description"]').attr('content'));
description = description !== null
? clip(entities.decode(description), 300)
: null;
if (title === description) {
description = null;
}
let siteName = or(
$('meta[property="misskey:site-name"]').attr('content'),
$('meta[property="og:site_name"]').attr('content'),
$('meta[name="application-name"]').attr('content'));
siteName = siteName !== null ? entities.decode(siteName) : null;
let icon = or(
$('meta[property="misskey:site-icon"]').attr('content'),
$('link[rel="shortcut icon"]').attr('href'),
$('link[rel="icon"]').attr('href'),
'/favicon.ico');
icon = icon !== null ? wrapMisskeyProxy(URL.resolve(url.href, icon)) : null;
const compiler: (locals: any) => string = jade.compileFile(
`${__dirname}/summary.jade`);
// コンパイル
const viewer: string = compiler({
url: url,
title: title,
icon: icon,
lang: lang,
description: description,
type: type,
image: image,
siteName: siteName
});
res.send(viewer);
}, (err: any) => {
示例6: text
text(text: string) {
return entities.decode(text);
}
示例7: codespan
codespan(text: string) {
return `\`${entities.decode(text)}\``;
}