Last active
June 12, 2020 00:35
-
-
Save typesend/98ba11e202c1c39fe17ac4d7cffe9de6 to your computer and use it in GitHub Desktop.
A simple Google Apps Script for copying referenced footnotes into inline footnotes
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
function footnoteInliner() { | |
var body = DocumentApp.getActiveDocument().getBody(); | |
var searchResult = null; | |
var count = 0; | |
while (searchResult = body.findElement(DocumentApp.ElementType.FOOTNOTE, searchResult)) { | |
count++; | |
var el = searchResult.getElement(); | |
var elindex = 1 + el.getParent().asParagraph().getChildIndex(el); | |
var contents = el.getFootnoteContents().getText(); | |
var inlineText = el.getParent().asParagraph().insertText(elindex, inlineTemplate(contents)); | |
inlineText.setBackgroundColor( 1, inlineTemplate(contents).length-1 , color(count) ).setForegroundColor('#000000'); | |
} | |
if (count == 0) { | |
DocumentApp.getUi().alert('No footnotes were found in this document.'); | |
} else { | |
DocumentApp.getUi().alert('All '+count+' of your footnotes have been inlined!'); | |
} | |
} | |
function onOpen() { | |
var ui = DocumentApp.getUi(); | |
ui.createMenu('Hana Tools').addItem('Inline all footnotes', 'footnoteInliner').addToUi(); | |
} | |
function inlineTemplate(str) { | |
var result = " [[" + str + "]] "; | |
return result; | |
} | |
function color(n) { | |
var palette = ['#FACEC8','#AAEAFC','#CAE3D2','#BFC2D5']; | |
return palette[n % palette.length]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment