Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here are the steps to add a RichLink (Chip Block) into Google Docs using Google Apps Script:

  1. First, open a Google Doc and go to Tools > Script editor.

  2. In the Script editor, create a new script file and name it something like "AddRichLinkToDoc".

  3. Next, in the script file, add the following code to create a RichLink Block:

function createRichLink() {
    var richLink = {
        title: 'Google',
        link: 'https://www.google.com',
        description: 'Search the world\'s information, including webpages, images, videos and more.',
        thumbnailUrl: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'
    };
    var richLinkBlock = {
        richLink: richLink
    };
    return richLinkBlock;
}

This code creates a new RichLink object with the title, link, description, and thumbnail URL, and then returns a block object containing the RichLink.

  1. Now, add the following code to insert the RichLink into your document:
function insertRichLink() {
    var richLinkBlock = createRichLink();
    var selection = DocumentApp.getActiveDocument().getSelection();
    if (selection) {
        var element = selection.getSelectedElements()[0];
        var range = element.getElement().getParent();
        range.insertBlock(richLinkBlock);
    }
}

This code calls the createRichLink function to create a new RichLink block, gets the current selection in the document, and then inserts the RichLink block into the document.

  1. Finally, save your script and then run the insertRichLink function to add the RichLink to your document.

Overall, with these steps, you can easily add RichLink (Chip Block) to Google Doc using Google App Script.