I have the following code
if(this.window.getSelection) {
  var r开发者_开发问答ange = this.range;
  var contents = range.extractContents();
  console.log(contents);
  return contents.textContent;
}
contents gives me a document fragment. When I check the text content of that fragment it collapses the newlines in my selection into a single string.
How do I preserve the formatting of the string?
you can use contents.innerHTML if your contents is a html element, or contents.html() if it is a jQuery object.
ps: is this.window.getSelection not supposed to be this.window.getSelection()?
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论