But now, I would like to transform these texts into links.
For example in a google doc, I have the tag {{to-replace}} and I would like to change it to the label “Here is n8n” and that text should now links to the url “https://n8n.io”
I found an article explaining on how to do it using Google Apps Script:
function singleLinkWithinParagraph(){
// ## Inputs ##
let text = "Here is n8n";
let url = "https://n8n.io/";
let textToFind = "{{to-replace}}";
// ############
let body = DocumentApp.getActiveDocument().getBody();
let foundText = body.findText(textToFind);
// Get the start and end location of the text in the paragraph.
let startText = foundText.getStartOffset();
let endText = startText + text.length - 1;
// Get the element indext for this section of text.
let element = foundText.getElement();
// Replace the text and insert the URL.
element.asText()
.replaceText(textToFind, text)
.setLinkUrl(startText, endText, url);
};
This workflow includes an approach to find the start index of a table cell but might help with finding your way around programming Google Docs in general.
thanks, I have finally achieved what I have in mind by parsing the data from a get document node, searching links, record range and then update them using a batch update with http request.
Hi all, here is my workflow to replace links (and also “tags”) in a google doc.
A few comments:
it takes a list of replacements as inputs (search/replace): you can have property like [[property1]] is replaced by “value1” or you can also have replacements of link like: “xxxx”(which is a part of a link, for example a google id), is replaced by another google id link.
first node loads google doc content
second node adds the content of the node to a property
third node searches links in the content and prepare a replacement command
fourth node searches for text occurrences to be replaced
final node update the google doc file using all the replacement commands.