Created
January 10, 2016 19:08
-
-
Save bennettscience/dfff14f668a245dd4b63 to your computer and use it in GitHub Desktop.
Formats a Google Document for close reading and annotation by students.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For close reading, it's important to have ordered and numbered paragraphs. | |
// This script takes the text and formats it based on paragraph breaks. | |
// More on this script at http://blog.ohheybrian.com | |
function formatArticle(){ | |
var doc = DocumentApp.getActiveDocument() | |
var body = doc.getBody(); | |
// Get the paragraphs | |
var paras = body.getParagraphs(); | |
var addTable = body.appendTable(); | |
//paragraph index | |
var pIndex = 1; | |
for(var i = 0 ; i < paras.length ; i++){ | |
var para = paras[i]; | |
var paraStr = para.editAsText().getText(); | |
// if there is string content in paragraph | |
if(paraStr.length){ | |
// Add a row to the table | |
var tr = addTable.appendTableRow(); | |
// Number the rows and align the number to the right | |
var td1 = tr.appendTableCell(pIndex); | |
td1.getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.RIGHT); | |
// Add the article paragraph and move on | |
var td2 = tr.appendTableCell(paraStr); | |
pIndex ++; | |
} | |
// Remove the copied paragraph from the original text | |
para.removeFromParent(); | |
} | |
// Remove the table border and resize columns for larger margins | |
var style = {} | |
style[DocumentApp.Attribute.BORDER_WIDTH] = 0; | |
addTable.setColumnWidth(0, 45).setColumnWidth(1, 450).setAttributes(style) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment