-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRefExtract.js
More file actions
28 lines (25 loc) · 976 Bytes
/
Copy pathRefExtract.js
File metadata and controls
28 lines (25 loc) · 976 Bytes
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
javascript: var name = prompt("future name of this <ref>?");
/* place cursor inside an inline reference before clicking */
var wpTextbox = document.getElementById("wpTextbox1");
var selectionStart = wpTextbox.selectionStart;
var indexEndRef = wpTextbox.value.indexOf("</ref>", selectionStart);
var indexStartRef = wpTextbox.value.lastIndexOf("<ref>", indexEndRef);
if (indexEndRef == -1 || indexStartRef == -1) {
alert("please place cursor inside the ref tags");
} else {
var lengthSourceEnd = indexEndRef + "</ref>".length - indexStartRef;
var wholeSource = wpTextbox.value.substr(indexStartRef, lengthSourceEnd);
var ref = wholeSource
.replace("<ref>", '<ref name="' + name + '">')
.split("\n")
.join("<br />");
wpTextbox.value = wpTextbox.value.replace(
wholeSource,
'<ref name="' + name + '"/>'
);
if (prompt("", ref) != null) {
wpTextbox.selectionStart = selectionStart;
wpTextbox.selectionEnd = selectionStart;
}
}
void 0;