Apps script to select h3 paragraphs in docs that start with a number and convert them to bolded text

To create a Google Apps Script that selects H3 paragraphs in a Google Document which start with a number and then converts them to bold text, you can use the following script:

function boldNumberedHeadings() {
  // Open the active document
  var document = DocumentApp.getActiveDocument();
  var body = document.getBody();
  
  // Get all the paragraphs in the document
  var paragraphs = body.getParagraphs();
  
  for (var i = 0; i < paragraphs.length; i++) {
    var paragraph = paragraphs[i];
    
    // Check if the paragraph is a heading of type H3
    if (paragraph.getHeading() === DocumentApp.ParagraphHeading.HEADING3) {
      var text = paragraph.getText();
      
      // Check if the paragraph starts with a number
      if (/^\d/.test(text)) {
        // Set the text to bold
        paragraph.editAsText().setBold(true);
      }
    }
  }
}

To use this script, follow these steps:

  1. Open your Google Document.
  2. Go to Extensions > Apps Script.
  3. Delete any code in the script editor and replace it with the code provided above.
  4. Save the project with a name.
  5. Close the Apps Script tab.
  6. To run the script, go back to your document, refresh the page, and then go to Extensions > Macros > Manage Macros. You should see boldNumberedHeadings listed there. Run it from there, or add a shortcut to run it more easily in the future.

This script will scan through all the paragraphs in your document, and if it finds any H3 headings that start with a number, it will change the formatting of these headings to bold.