Apps Script to remove bullet format from Doc

Google Apps Script to remove bullet formatting from list items in a Google Document, you need to modify the script to not only reset the formatting of the list items but also to convert them into regular text paragraphs. Here’s how you can adjust the previously provided script:

function removeBulletFormatting() {
  var doc = DocumentApp.getActiveDocument(); // Gets the active document
  var body = doc.getBody(); // Gets the body of the document
  var numElements = body.getNumChildren(); // Gets the number of elements in the document
  
  // Iterate through all elements in the document
  for (var i = 0; i < numElements; i++) {
    var element = body.getChild(i);
    // Check if the element is a list item
    if (element.getType() === DocumentApp.ElementType.LIST_ITEM) {
      var listItem = element.asListItem();
      
      // Convert the list item to a normal text paragraph
      var text = listItem.getText(); // Get the text of the list item
      var paragraph = body.insertParagraph(i, text); // Insert a new paragraph with the list item's text before the list item
      
      // Copy text attributes from the list item to the new paragraph
      var attributes = listItem.getAttributes();
      for (var attr in attributes) {
        if (attributes[attr] !== null) { // Check if the attribute is not null
          paragraph.setAttribute(attr, attributes[attr]);
        }
      }
      
      body.removeChild(listItem); // Remove the original list item
      i--; // Adjust the index since we removed an element
      numElements--; // Adjust the total number of elements
    }
  }
}

This script goes through each element in the document, identifies the list items, and then performs the following actions for each list item:

  • Retrieves the text of the list item.
  • Inserts a new paragraph with the same text just before the original list item.
  • Copies all text attributes from the list item to the new paragraph to maintain text styling.
  • Removes the original list item from the document.

Remember, this script modifies the document structure by replacing list items with regular paragraphs, effectively removing bullet or numbering formatting. After running this script, all former list items will be regular text paragraphs, and you’ll need to manually add list formatting back if desired.