Guest User

Untitled

a guest
Oct 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. function test() {
  2. var targetDocId = "1A02VhxOWLUIdl8LTV1tt2S1yASDbOq77VbsUpxPa6vk";
  3. var targetDoc = DocumentApp.openById(targetDocId);
  4. var body = targetDoc.getBody();
  5. var elementContent = targetDoc.getChild(2); // a paragraph with its formating
  6. var childIndex = 0;
  7. for (var p= 0; p< targetDoc.getNumChildren(); p++) {
  8. var child = targetDoc.getChild(p);
  9. if (child.getType() == DocumentApp.ElementType.LIST_ITEM){
  10. while(child.getType() == DocumentApp.ElementType.LIST_ITEM){
  11. child = targetDoc.getChild(p)
  12. Logger.log("child = " + child.getText())
  13. childIndex = body.getChildIndex(child);
  14. Logger.log(childIndex)
  15. p++
  16. }
  17. child = targetDoc.getChild(p-2);
  18. var listId = child.getListId();
  19. if (child.getText() == '') {
  20. childIndex = childIndex -1;
  21. }
  22. Logger.log(childIndex)
  23. var newElement = child.getParent().insertListItem(childIndex, elementContent);
  24. newElement.setListId(child);
  25. var lastEmptyItem = targetDoc.getChild(childIndex +1).removeFromParent();
  26. break;
  27. }
  28.  
  29. function parToList() {
  30. var doc = DocumentApp.getActiveDocument();
  31. var body = doc.getBody();
  32. //gets the paragraph at index 1 on body -> can be changed to what you want
  33. var par = body.getChild(1);
  34. var childs = [];
  35. for (var i = 0; i<par.getNumChildren(); i++) {
  36. var child = par.getChild(0);
  37. childs.push(child);
  38. child.removeFromParent();
  39. };
  40. par.removeFromParent();
  41. //puts the list item on index 1 of body -> can be changed to the wanted position
  42. var li = body.insertListItem(1, "");
  43. childs.reverse();
  44. for (var j in childs) {
  45. var liChild = childs[j];
  46. var childType = liChild.getType();
  47. if (childType == DocumentApp.ElementType.EQUATION) {
  48. //still need to find a way to append an equation
  49. } else if (childType == DocumentApp.ElementType.INLINE_DRAWING) {
  50. //still need to find a way to append an inlineDrawing
  51. } else if (childType == DocumentApp.ElementType.INLINE_IMAGE) {
  52. li.appendInlineImage(liChild);
  53. } else if (childType == DocumentApp.ElementType.TEXT) {
  54. li.appendText(liChild);
  55. };
  56. };
  57. };
Add Comment
Please, Sign In to add comment