Google Docs – Apply Headers to Single Line After Pasting as Plain Text

formattinggoogle docstext formatting

The issue: https://youtu.be/OXS3wTR7YJw

  1. Make notes in "Notes" (better for offline)
  2. Paste into Google Doc
  3. Apply a header
  4. Sh!t the whole thing is formatted now

Related but not the same: Create documents with plain text formatting in Google Docs

Best Answer

The issue is that Notes uses carriage return (\r) as new lines whereas Google Docs and Windows use a combination of carriage return and new line (\r\n)

The following code in Apps Scripts will break the paragraphs apart:

function replaceSoftReturns() {
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();
  var newParagraphs = body.getText().split("\r");
  body.clear();
  newParagraphs.forEach(function(txt){body.appendParagraph(txt)})
}