-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
65 lines (52 loc) · 1.84 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
const eejs = require('ep_etherpad-lite/node/eejs/');
const settings = require('ep_etherpad-lite/node/utils/Settings');
const {JSDOM} = require('jsdom');
exports.padInitToolbar = (hookName, args, cb) => {
const toolbar = args.toolbar;
if (JSON.stringify(settings.toolbar).indexOf('addHyperlink') === -1) {
settings.toolbar.left.push(['addHyperlink']);
}
const button = toolbar.button({
command: 'addHyperlink',
localizationId: 'ep_embedded_hyperlinks.editbarButtons.hyperlink.title',
class: 'buttonicon buttonicon-link hyperlink-icon',
});
toolbar.registerButton('addHyperlink', button);
return cb();
};
exports.eejsBlock_body = (hook, args, cb) => {
args.content += eejs.require('ep_embedded_hyperlinks2/templates/popup.ejs', {}, module);
return cb();
};
// Add the props to be supported in export
exports.exportHtmlAdditionalTagsWithData = async (hook, pad) => {
const ret = [];
pad.pool.eachAttrib((k, v) => { if (k === 'url') ret.push([k, v]); });
return ret;
};
exports.getLineHTMLForExport = async (hook, context) => {
const elem = JSDOM.fragment(context.lineContent);
const parseNode = async (node) => {
const attrs = node.attributes;
if (attrs) {
for (let i = 0; i < attrs.length; i++) {
const attr = attrs[i];
if (attr.name === 'data-url') {
const nodeHTML = node.outerHTML.trim();
const replaceHTML = (`${nodeHTML.substring(0, nodeHTML.length - 5)}a>`)
.replace('<span data-url', '<a href');
context.lineContent = JSDOM
.fragment(`<div>${context.lineContent}</div>`).firstChild.innerHTML
.replace(nodeHTML, replaceHTML);
}
}
}
if (node.childNodes) {
node.childNodes.forEach(async (child) => {
await parseNode(child);
});
}
};
await parseNode(elem);
};