Apps script to select all h3 paragraphs convert them to regular paragraphs with bolded text

Below is a Google Apps Script that selects all H3 paragraphs in a Google Document, converts them to regular paragraphs, and makes the text within them bold:

function convertH3ToBoldParagraphs() {
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();
  var paragraphs = body.getParagraphs();

  for (var i = 0; i < paragraphs.length; i++) {
    var paragraph = paragraphs[i];
    if (paragraph.getHeading() == DocumentApp.ParagraphHeading.HEADING3) {
      // Get the text of the H3 paragraph
      var text = paragraph.getText();
      // Remove the H3 formatting
      paragraph.setHeading(DocumentApp.ParagraphHeading.NORMAL);
      // Replace the paragraph text with bold formatting
      paragraph.clear().appendText(text).setBold(true);
    }
  }
}

Here’s how it works:

  1. It gets all the paragraphs in the document.
  2. It iterates through each paragraph, checking if it’s an H3 paragraph.
  3. If it finds an H3 paragraph, it retrieves the text, removes the H3 formatting, and sets the text to bold.

To use this script:

  1. Open your Google Document.
  2. Click on “Extensions” > “Apps Script.”
  3. Delete any code in the script editor and replace it with the provided script.
  4. Save the script.
  5. Run the function convertH3ToBoldParagraphs from the script editor.

This will convert all H3 paragraphs to regular paragraphs with bolded text.