As many of you know, Google Docs is an incredibly versatile tool for creating and editing documents. But did you know you can automate and manipulate these documents with just a few lines of script? 🤖✨
- Access the Document: Get access to the active Google Document.
- Find Bullet Lists: Iterate through the elements in the document to find bullet lists.
- Convert Bullets to Regular Text: For each bullet list item, convert it into a regular paragraph.
Here’s an example script demonstrating this process:
function convertBulletsToParagraphs() {
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
const numChildren = body.getNumChildren();
for (let i = 0; i < numChildren; i++) {
const child = body.getChild(i);
// Check if the child element is a list item
if (child.getType() === DocumentApp.ElementType.LIST_ITEM) {
// Get the text from the list item
const text = child.asListItem().getText();
// Create a new paragraph with the same text
const newParagraph = body.insertParagraph(i, text);
// Apply the same attributes as the list item to the new paragraph
const attributes = child.getAttributes();
newParagraph.setAttributes(attributes);
// Remove the original list item
body.removeChild(child);
// Adjust the loop counter since we've modified the document structure
i--;
}
}
}
// Run the script
convertBulletsToParagraphs();
This script iterates through the elements of the document. When it finds a list item (bullet point), it creates a new paragraph with the same text and attributes, inserts it in the same position, and then removes the original list item.
![](https://i0.wp.com/basescripts.com/wp-content/uploads/2024/01/image-67.png?resize=1024%2C910&ssl=1)