Google Apps Script that converts bullet points into regular paragraphs

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? 🤖✨

  1. Access the Document: Get access to the active Google Document.
  2. Find Bullet Lists: Iterate through the elements in the document to find bullet lists.
  3. 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.