Reputation: 45
I've an HTML content in cell A1, I want to render the HTML content and add the rendered HTML content in cell B1
e.g. if I've this HTML in A1
<label class="s-label mb4 d-block" for="wmd-input">
Body
<p class="s-description mt2">Include all the information someone would need to answer your question</p>
</label>
I want the output in B1 to be
Body
Include all the information someone would need to answer your question
I've tried
var htmlTarget = current.getRange('A1').getValue();
var htmlOutput = HtmlService.createHtmlOutput(htmlTarget);
var message = htmlOutput.getContent();
database.getRange('B1').setValue(message);
And it gets the same HTML and pastes it with the tags without rendering anything
Upvotes: 3
Views: 6881
Reputation: 201358
I believe your goal as follows.
getContent()
in Class HtmlOutput returns the HTML data. Ref I thought that this might be the reason of your issue.In order to retrieve the rendered text without the HTML tags, in this answer, I would like to propose to retrieve the text data by converting the HTML data to Google Document using the method of "Files: insert" in Drive API v2. (Because, the version of Drive API is still v2 at Advanced Google service.)
When your script is modified, it becomes as follows.
Before you use this script, please enable Drive API at Advanced Google services.
From:var htmlTarget = current.getRange('A1').getValue();
var htmlOutput = HtmlService.createHtmlOutput(htmlTarget);
var message = htmlOutput.getContent();
database.getRange('B1').setValue(message);
To:
var htmlTarget = current.getRange('A1').getValue();
var blob = Utilities.newBlob(htmlTarget, MimeType.HTML);
var id = Drive.Files.insert({title: "sample", mimeType: MimeType.GOOGLE_DOCS}, blob).id;
var message = DocumentApp.openById(id).getBody().getText();
DriveApp.getFileById(id).setTrashed(true); // or Drive.Files.remove(id);
database.getRange('B1').setValue(message);
Upvotes: 2