forked from dariok/officeEntityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.js
50 lines (44 loc) · 1.45 KB
/
entity.js
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
Office.initialize = function ( reason ) {
// Checks for the DOM to load using the jQuery ready function.
$( document ).ready(
function () {
// void
}
);
};
function insertLink ( link ) {
/*+Office.context.document.getSelectedDataAsync(
Office.CoercionType.Ooxml,
function (result) {console.log (result)});*/
// get the selected data as HTML
Office.context.document.getSelectedDataAsync(
Office.CoercionType.Html,
function ( result ) {
if ( result.status == "succeeded" ) {
// the selected data as HTML, i.e. incl. formatting
var res = $( result.value );
// there should be exactly one p in there that contains the selected text
// it is a p due to schema constraints
var ret = res.find( 'p' );
// the selected text is inside spans that correspond to Word's "runs" (w:r)
// @style contains all styling information and needs to be kept
var text = ret.html();
//we simply wrap the contents of that p in an html:a and write it back
var ref = '<a href="' + link + '" style="text-decoration:none">' + text + '</a>';
Office.context.document.setSelectedDataAsync(
ref,
{ coercionType: Office.CoercionType.Html },
function ( asyncResult ) {
console.log( asyncResult.status );
}
);
}
}
);
}
function process ( data ) {
console.log(data);
var result = { results: [] };
evalResult(result, data);
return result.results;
}