列出项目编号不会转移到新文档

List item numbers don't transfer to new document

我正在创建一个函数,可以将用户当前选择的文本从一个文档传输到另一个文档。

大多数情况下它工作正常,但是当我尝试传输列表项时,如此 image 所示,列表项编号消失了。

转移到目标文档后,最后一张图片中的列表项现在看起来像 this

有没有办法确保号码得到转移,或者至少以有效的方式重新创建号码? 谢谢!


最小可重现示例:

function sendToDoc() {
  var currentDoc = DocumentApp.getActiveDocument().getSelection();
  
  var targetDoc = DocumentApp.openByUrl(a different documents url);
  var body = targetDoc.getBody();

  //if you are selecting some text, this function will transfer your selection into the target document

  if(currentDoc) {
    var totalElements = currentDoc.getRangeElements();
    
    //for each element in your selection

    for( var index = 0; index < totalElements.length; ++index ) {
      var element = totalElements[index].getElement().copy();
      var type = element.getType();
      
      
      //gets the element type and transfers it over to the target doc

      if( type == DocumentApp.ElementType.PARAGRAPH ){
        body.appendParagraph(element);
      }
      else if( type == DocumentApp.ElementType.TABLE){
        body.appendTable(element);
      }
      else if( type == DocumentApp.ElementType.LIST_ITEM){ //this is where the list items get transferred
        body.appendListItem(element);
      }
      else if( type == DocumentApp.ElementType.INLINE_IMAGE ){
        body.appendImage(element);
      }
      else if( type == DocumentApp.ElementType.HORIZONTAL_RULE ){
        body.appendHorizontalRule();
      }
      else {
        
      }
    }
    
  } 

GlyphType设为NUMBER:

 body
  .appendListItem(element)
  .setGlyphType(DocumentApp.GlyphType.NUMBER)