Format List items with Apps Script

Google Apps Script that finds list items in a Google Document, resets their formatting to mimic “Normal” text style while maintaining them as list items (but without bullet or numbering formatting), and ensures they are properly indented, you can follow these steps. Since Google Docs inherently treats list items differently from normal text, direct conversion while keeping them as “list items” without any list formatting can be a bit tricky. However, you can adjust their formatting to make them appear more like normal text within the constraints of list formatting.

Here’s a script that targets list items, resets their formatting to a predefined “normal” style, and adjusts indentation to make them look properly formatted:

This script sets a custom formatting for list items to make them appear as “normal” text. However, due to the nature of Google Docs, list items will still be part of a list. The script resets font style attributes and adjusts indentation without changing the list item to normal text paragraphs, meeting the requirement to keep them indented and look proper as normal.

Remember, the specific values for FONT_SIZE, LINE_SPACING, and indentation (setIndentStart, setIndentFirstLine) can be adjusted according to your document’s default “normal” text style.




function formatListItemsAsNormal() {
  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

  // Define the "normal" text formatting you want to apply
  var normalTextStyle = {
    FONT_FAMILY: DocumentApp.FontFamily.ARIAL,
    FONT_SIZE: 14,
    BOLD: false,
    ITALIC: false,
    UNDERLINE: false,
    FOREGROUND_COLOR: '#000000', // Black color
    LINE_SPACING: 1.5
  };

  // Convert the normalTextStyle object to the format expected by setAttributes
  var attributes = {};
  attributes[DocumentApp.Attribute.FONT_FAMILY] = normalTextStyle.FONT_FAMILY;
  attributes[DocumentApp.Attribute.FONT_SIZE] = normalTextStyle.FONT_SIZE;
  attributes[DocumentApp.Attribute.BOLD] = normalTextStyle.BOLD;
  attributes[DocumentApp.Attribute.ITALIC] = normalTextStyle.ITALIC;
  attributes[DocumentApp.Attribute.UNDERLINE] = normalTextStyle.UNDERLINE;
  attributes[DocumentApp.Attribute.FOREGROUND_COLOR] = normalTextStyle.FOREGROUND_COLOR;
  attributes[DocumentApp.Attribute.LINE_SPACING] = normalTextStyle.LINE_SPACING;

  // 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();

      // Apply the "normal" text formatting to the list item
      listItem.setAttributes(attributes);

      // Adjust indentation to mimic normal text appearance
      // Note: Indentation adjustments are relative and may need tuning based on document defaults
      listItem.setIndentStart(0); // Sets the start indent (in points)
      listItem.setIndentFirstLine(0); // Sets the first line indent (in points)
    }
  }
}