-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboldKey.gs
More file actions
34 lines (33 loc) · 1.13 KB
/
Copy pathboldKey.gs
File metadata and controls
34 lines (33 loc) · 1.13 KB
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
/*
Bold the key of each definition
A key is any phrase that is followed by the string ' - '
Goes through each paragraph (line) and search for the string and set the key to bold
*/
function boldKey() {
var body = DocumentApp.getActiveDocument().getBody();
var numParas = body.getNumChildren();
for (var i = 0; i < numParas; ++i) {
var element = body.getChild(i).findText('.* - ');
if (element != null && element.isPartial()) {
var text = element.getElement().editAsText();
var start = element.getStartOffset();
var finish = element.getEndOffsetInclusive() - 3;
text.setBold(start, finish, true);
}
}
/* ----- This does not work since it treats the whole document as one element
var element = body.findText('.* - ');
if (element != null) {
var text = element.getElement().editAsText();
var start = element.getStartOffset();
var finish = element.getEndOffsetInclusive() - 3;
text.setBold(start, finish, true);
element = body.findText('.* - ', element);
}
*/
}
function onOpen() {
DocumentApp.getUi().createMenu('Scripts')
.addItem('Bold Key', 'boldKey')
.addToUi();
}