Wir haben ein Google-Skript, das als Add-On ausgeführt wird und grundlegende Formatierungen in einfaches HTML konvertiert.Prüfen Sie den Text des Google-Dokuments auf die URL
Allerdings kann ich nicht scheinen Links zu erkennen, wenn sie einen vollständigen Satz sind.
Funktion, die Links finden sollte;
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 {
...
Ausgänge -
<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>
Dies ist, wie der Text in der Google Doc aussieht.
Jede Hilfe sehr geschätzt. Wirklich aus meiner Tiefe hier. Auch wenn es nur darum geht, mir das aus dem Skript-Editor zu helfen. dh wählen Sie ein Dokument aus, damit ich die Protokollausgabe sehen und meine Versuchs- und Fehlerausgabe erhöhen kann!