Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test() {
- var targetDocId = "1A02VhxOWLUIdl8LTV1tt2S1yASDbOq77VbsUpxPa6vk";
- var targetDoc = DocumentApp.openById(targetDocId);
- var body = targetDoc.getBody();
- var elementContent = targetDoc.getChild(2); // a paragraph with its formating
- var childIndex = 0;
- for (var p= 0; p< targetDoc.getNumChildren(); p++) {
- var child = targetDoc.getChild(p);
- if (child.getType() == DocumentApp.ElementType.LIST_ITEM){
- while(child.getType() == DocumentApp.ElementType.LIST_ITEM){
- child = targetDoc.getChild(p)
- Logger.log("child = " + child.getText())
- childIndex = body.getChildIndex(child);
- Logger.log(childIndex)
- p++
- }
- child = targetDoc.getChild(p-2);
- var listId = child.getListId();
- if (child.getText() == '') {
- childIndex = childIndex -1;
- }
- Logger.log(childIndex)
- var newElement = child.getParent().insertListItem(childIndex, elementContent);
- newElement.setListId(child);
- var lastEmptyItem = targetDoc.getChild(childIndex +1).removeFromParent();
- break;
- }
- function parToList() {
- var doc = DocumentApp.getActiveDocument();
- var body = doc.getBody();
- //gets the paragraph at index 1 on body -> can be changed to what you want
- var par = body.getChild(1);
- var childs = [];
- for (var i = 0; i<par.getNumChildren(); i++) {
- var child = par.getChild(0);
- childs.push(child);
- child.removeFromParent();
- };
- par.removeFromParent();
- //puts the list item on index 1 of body -> can be changed to the wanted position
- var li = body.insertListItem(1, "");
- childs.reverse();
- for (var j in childs) {
- var liChild = childs[j];
- var childType = liChild.getType();
- if (childType == DocumentApp.ElementType.EQUATION) {
- //still need to find a way to append an equation
- } else if (childType == DocumentApp.ElementType.INLINE_DRAWING) {
- //still need to find a way to append an inlineDrawing
- } else if (childType == DocumentApp.ElementType.INLINE_IMAGE) {
- li.appendInlineImage(liChild);
- } else if (childType == DocumentApp.ElementType.TEXT) {
- li.appendText(liChild);
- };
- };
- };
Add Comment
Please, Sign In to add comment