【发布时间】:2017-10-19 10:30:21
【问题描述】:
我们有一个 Google 脚本,它作为插件运行并将基本格式转换为基本 HTML。
但是,当链接是一个完整的句子时,我似乎无法检测到它们。
应该找到链接的函数;
function processText(item, output) {
var text = item.getText();
var indices = item.getTextAttributeIndices();
Logger.log("processText. "+item+". "+text);
if (indices.length <= 1) {
var partAtts = item.getAttributes(indices[0]);
// Assuming that a whole para fully italic is a quote
if(item.isBold()) {
output.push('<b>' + text + '</b>');
}
else if(item.isItalic()) {
output.push('<blockquote>' + text + '</blockquote>');
}
else if (text.trim().indexOf('http://') > -1) {
output.push('<a href="' + text + '" rel="nofollow" class="a">' + text + '</a>');
}
else if (text.trim().indexOf('https://') > -1) {
output.push('<a href="' + text + '" rel="nofollow" class="b">' + text + '</a>');
}
else {
//using this to debug as have no idea how to run from script and use Logger.
output.push(partAtts[0]+"<<< "+text.trim().indexOf('http://')+ ", "+ text.trim().indexOf('https://')+ " (pt) "+text+". "+indices);
//output.push(text);
}
}
else {
...
输出 -
<p>A sentence with a <a href="https://www.theguardian.com/politics/2017/oct/19/brexit-talks-uk-must-prepare-to-leave-without-deal-say-former-ministers" class="c">link</a></p>
<p>undefined<<< -1, -1 (pt) A full link sentence. 0</p>
这是 Google 文档中文本的样子。
任何帮助表示赞赏。真的超出了我的深度。即使它只是为了帮助我从脚本编辑器运行它。即选择一个文档,这样我就可以看到日志输出并增加我的试错输出!
【问题讨论】:
标签: google-apps-script hyperlink google-docs