How do I Preserve Bold Text from ChatGPT into a Google Doc?

I’ve got a scenario with a ChatGPT module. The response from ChatGPT is a list with some text that’s bold, but instead of bold text it’s putting asterisks on either side of the text (see screenshot).

I’m mapping this response into a Google Doc and rather than getting bold text in my Google Doc it’s showing up with the asterisks and it looks messy. How do I preserve the bold text so that when ChatGPT replies with bold text, it shows up in my Google Doc as bold text?

Can I do this with a text parser in Make and a script in my Google doc?

Hi @LaurenK
Workflow:
image

Google Docs supports HTML formatting, so you can use the Markdown module in Make.com to convert this text into HTML format.
image

Output:

Best regards,

Msquare Automation
Gold Partner of Make
@Msquare_Automation

1 Like

Hi @Msquare_Automation

I just tried that but it came in with the html in the Google Doc. I’m creating a Google Doc from a template and mapping the ChatGPT result in.

Here’s my workflow:

Creating from a template does not allow you to insert formatting, only variables in plain text.

You have to create the document from scratch if you want to insert a full HTML formatted document with formatting.

If you want to create a document from template and insert your own formatting, that is an advanced question for another thread.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

1 Like

After the document is created from template you can try and use the get contents from document module to retrieve the html code. Then run another create a document module.

Hope this helps!

Hi @LaurenK
You can use download a doc module to get the html code of template doc and then replace the test_varible with the Markdown converted html code.
Workflow:

Markdown:


Download a document (select html format):

Set variable to convert the data to string:
image
Create a doc:
In my case I have added “[add]” variable to add new content there, so i am replacing the html code of this part .In your case it will be “test_variable”.

Best regards,

Msquare Automation
Gold Partner of Make
@Msquare_Automation

Hi @LaurenK
Have you solve the issue with styling in Doc Template?
I am trying to find out how to do it as well.

@Oleksandr_Pushkar I solved it.

First, you need to create a script in Google Scripts. The instructions and the code to do this are below. Deploy the script as a web app to get the URL.

Then in your Make.com scenario it’ll go like this (also see picture below):

All of your ChatGPT modules → Create Google Doc → HTTP module with the web app URL & the docId passed through as JSON (see screenshot below)

To create a Google Apps Script that will search for text between double asterisks and make it bold in a Google Doc, you can follow these steps. I’ll include an example script that you can adapt.

  1. Open Google Apps Script:
  1. Write the Script:
  • In the script editor, replace the default content with the following code:

javascript

Copy code

function makeTextBold(docId) {
  // Open the document by ID
  var doc = DocumentApp.openById(docId);
  var body = doc.getBody();
  
  // Regular expression to find text between double asterisks
  var pattern = /\*\*(.*?)\*\*/g;
  var text = body.getText();
  var match;

  while (match = pattern.exec(text)) {
    var start = match.index;
    var end = start + match[0].length;
    var boldText = match[1];

    // Replace the asterisks and apply bold formatting to the text inside them
    var boldTextLength = boldText.length;
    body.replaceText(escapeRegExp(match[0]), boldText);
    
    // Find the newly replaced text and apply bold styling
    var searchResult = body.findText(escapeRegExp(boldText));
    while (searchResult) {
      var thisElement = searchResult.getElement();
      var thisElementText = thisElement.asText();
      var startPos = searchResult.getStartOffset();
      var endPos = searchResult.getEndOffsetInclusive();
      thisElementText.setBold(startPos, endPos, true);
      searchResult = body.findText(escapeRegExp(boldText), searchResult);
    }
  }

  // Save the changes
  doc.saveAndClose();
}

// Helper function to escape special characters for regular expression
function escapeRegExp(string) {
  return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\DISCOURSE_PLACEHOLDER_1');
}
  1. Deploy as Web App:
  • Go to the menu: Deploy > New deployment.
  • Click on Select type and choose Web app.
  • Fill in the description.
  • Under Execute as, select Me.
  • Under Who has access, choose Anyone.
  • Click Deploy. You might need to authorize the script by logging into your Google account and allowing permissions.
  1. Get the Web App URL:
  • Once deployed, copy the URL provided. This is the endpoint you will call from make.com.
  1. Setup in make.com:
  • In your make.com scenario, use an HTTP module to make a POST request to the Web App URL.
  • Pass the Google Doc ID as a parameter or within the request body, depending on how you set up the HTTP module.

This script and deployment method will allow your Google Script to be triggered via HTTP requests from make.com, applying bold formatting to the text that’s between double asterisks in the specified Google Doc. Adjust the script according to the specifics of how you send data from make.com if necessary.

1 Like