-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.gs
80 lines (66 loc) · 2.16 KB
/
main.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function onInstall(e) {
onOpen(e)
}
function onOpen(e) {
DocumentApp.getUi()
.createAddonMenu()
.addItem('Update document', 'updateDoc')
.addItem('Configure references', 'showSidebar')
.addSeparator()
.addItem('Update lists', 'createLoF')
.addItem('Configure lists', 'showLofConfig')
.addToUi()
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent()
}
function showLofConfig() {
const html = HtmlService.createTemplateFromFile('lof-config').evaluate()
html.setWidth(280).setHeight(180)
DocumentApp.getUi().showModalDialog(html, 'Configure entity lists')
}
function showSidebar() {
const sidebar = HtmlService.createTemplateFromFile('sidebar-html').evaluate()
sidebar.setTitle('Cross Reference')
DocumentApp.getUi().showSidebar(sidebar)
}
function updateDoc() {
const document = DocumentApp.getActiveDocument()
const paragraphs = document.getBody().getParagraphs()
const footnotes = document.getFootnotes()
const settings = getSettings()
updateDocProps(settings)
const recordedNumbers = {}
const labelNameNumberMap = {}
const labProps = getProps('lab')(settings)
const getLabs = getCRUrls(isCRUrl(5))
const handleNumbering = handleLabNumber(recordedNumbers)(labelNameNumberMap)
const handleLabs = handleCRUrl(labProps)(handleNumbering)
let error = updateParagraphs(paragraphs)(getLabs)(handleLabs)
if (error) {
handleErr(error)
return 'error'
}
for (let i = 0, len = footnotes.length; i < len; i++) {
const footnoteParagraphs = footnotes[i].getFootnoteContents().getParagraphs()
const handleFNLabs = handleFootnoteLabCRUrl(labProps)(handleNumbering)
const error = updateParagraphs(footnoteParagraphs)(getLabs)(handleFNLabs)
if (error) {
handleErr(error)
return 'error'
}
}
const refProps = getProps('ref')(settings)
const getRefs = getCRUrls(isCRUrl(3))
const handleRefs = handleCRUrl(refProps)(handleRefNumber(recordedNumbers))
error = updateParagraphs(paragraphs)(getRefs)(handleRefs)
if (error) {
handleErr(error)
return 'error'
}
}
/** ALL TESTS */
function runAllTests() {
testAllSettings()
testAllText()
}