How to eliminate blank lines in Google Docs using automation

I’m working with some text in Google Docs that has bullet points all on one line like this:

○ item 1○ item 2○ item 3

I want to automatically convert this into a proper bulleted list where each item is on its own line without extra spacing between them.

I tried using Google Apps Script to split the text at each bullet character and add line breaks:

function processText() {
    var document = DocumentApp.getActiveDocument();
    var content = document.getBody();
    content.replaceText('○ ', '\n');
}

This works to separate the lines, but when I select all the text and apply bullet formatting, only the first line gets a bullet point. I think the issue is that ‘\n’ doesn’t create the same kind of line break as pressing Enter manually.

Then I tried using ‘\r\n’ instead:

function processText() {
    var document = DocumentApp.getActiveDocument();
    var content = document.getBody();
    content.replaceText('○ ', '\r\n');
}

But this creates unwanted empty lines between each item, and I can’t figure out how to remove those blank lines afterward. How can I properly format this text so that each item appears on its own line and can be formatted as a bulleted list?

Had this exact problem when automating document cleanup at work. Google Apps Script handles line breaks weirdly compared to manual formatting. Don’t mess with line break characters - use replaceText to clean up your bullets, then split and rebuild:

function formatBullets() {
    var doc = DocumentApp.getActiveDocument();
    var body = doc.getBody();
    var content = body.getText();
    
    // Remove existing bullets and split
    var cleanText = content.replace(/○\s*/g, '|SPLIT|');
    var items = cleanText.split('|SPLIT|').filter(item => item.trim());
    
    // Clear and rebuild
    body.clear();
    items.forEach(item => {
        body.appendParagraph(item.trim()).setListId(DocumentApp.getUi().createBulletedList());
    });
}

Using a temporary delimiter instead of line breaks avoids all the paragraph formatting headaches and gives you clean bullets without extra spacing.

Use \n\n instead of \n - that’ll give you proper paragraph breaks in Google Docs. Just dealt with this same issue last week and double line breaks fixed it perfectly without any weird spacing.

I ran into the same thing with Google Docs automation a few months ago. The issue is that replaceText() doesn’t handle paragraph breaks right when you’re dealing with bullets. Don’t use replaceText with line breaks - create actual paragraph elements instead. Here’s what fixed it for me:

function processText() {
    var doc = DocumentApp.getActiveDocument();
    var body = doc.getBody();
    var text = body.getText();
    
    // Split by bullet points
    var items = text.split('○ ').filter(item => item.trim() !== '');
    
    body.clear();
    
    items.forEach(function(item) {
        var paragraph = body.appendParagraph(item.trim());
        paragraph.setBullet(DocumentApp.GlyphType.BULLET);
    });
}

This skips the line break problem completely by making proper paragraph elements and adding bullet formatting directly. Use appendParagraph() instead of messing around with text and line breaks.