Code Guy
Code Guy

Reputation: 3198

Convert Paragraph or text element to LIST_ITEM in GAS

How can I convert an existing paragraph or text element to list item? where the cursor is placed.

if (cursor) {
    var someElement = cursor.getElement();
    //someElement is a paragraph or text element
}

Upvotes: 0

Views: 642

Answers (1)

EvSunWoodard
EvSunWoodard

Reputation: 1280

Basically you have to build a newList item out of the text, and then swap them. Should look roughly like this:

var location = body.getChildIndex(yourParagraph);

var pText = yourParagraph.getText();

var lItem = body.appendListItem();

lItem.setText(pText);

body.insertListItem(location, lItem);

You might have to fiddle with this a little. But this is the general idea you are looking for, I think.

Upvotes: 1

Related Questions