Skip to content

Instantly share code, notes, and snippets.

@typesend
Last active June 12, 2020 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typesend/98ba11e202c1c39fe17ac4d7cffe9de6 to your computer and use it in GitHub Desktop.
Save typesend/98ba11e202c1c39fe17ac4d7cffe9de6 to your computer and use it in GitHub Desktop.
A simple Google Apps Script for copying referenced footnotes into inline footnotes
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