Apps Script to Bold Paragraphs ending with question mark

You can create a Google Apps Script for Google Docs that converts any text element ending with a question mark to an H3 element. Here’s a basic example of how you can achieve this:

function convertQuestionToH3() {
  var body = DocumentApp.getActiveDocument().getBody();
  var paragraphs = body.getParagraphs();
  
  for (var i = 0; i < paragraphs.length; i++) {
    var paragraph = paragraphs[i];
    var text = paragraph.getText();
    
    // Check if the paragraph ends with a question mark
    if (text.slice(-1) === '?') {
      // Convert the paragraph to H3 element
      paragraph.setHeading(DocumentApp.ParagraphHeading.HEADING3);
    }
  }
}

Here’s how you can set up and use this script:

  1. Open your Google Docs document.
  2. Click on Extensions -> Apps Script.
  3. Delete any code in the script editor and replace it with the code provided above.
  4. Save the script.
  5. Run the function convertQuestionToH3() by clicking the play button or by going to Run -> Run function -> convertQuestionToH3.

This script will iterate through all paragraphs in the document and if it finds a paragraph that ends with a question mark, it will convert that paragraph into an H3 heading.