我们有一个Google脚本作为附件运行,并将基本格式转换为基本HTML。查看Google文档的网址
但是,我似乎无法检测链接时,他们是一个完整的句子。
应该找到链接的函数;
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>
这就是文字看起来像在谷歌文档。
赞赏任何帮助。这里真的超出我的深度。即使它只是为了帮助我从脚本编辑器中运行它。即选择一个文档,这样我就可以看到日志输出并增加我的试验和错误输出!