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:
- Open your Google Document.
- Go to
Extensions
>Apps Script
. - Delete any code in the script editor and replace it with the code provided above.
- Save the project with a name.
- Close the Apps Script tab.
- To run the script, go back to your document, refresh the page, and then go to
Extensions
>Macros
>Manage Macros
. You should seeboldNumberedHeadings
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.