-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
88 lines (74 loc) · 2.78 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
const eejs = require('ep_etherpad-lite/node/eejs/');
const Changeset = require('ep_etherpad-lite/static/js/Changeset');
const settings = require('ep_etherpad-lite/node/utils/Settings');
exports.eejsBlock_editbarMenuLeft = (hookName, args, cb) => {
if (args.renderContext.isReadOnly) return cb();
for (const button of ['alignLeft', 'alignJustify', 'alignCenter', 'alignRight']) {
if (JSON.stringify(settings.toolbar).indexOf(button) > -1) {
return cb();
}
}
args.content += eejs.require('ep_align/templates/editbarButtons.ejs');
return cb();
};
const _analyzeLine = (alineAttrs, apool) => {
let alignment = null;
if (alineAttrs) {
const opIter = Changeset.opIterator(alineAttrs);
if (opIter.hasNext()) {
const op = opIter.next();
alignment = Changeset.opAttributeValue(op, 'align', apool);
}
}
return alignment;
};
// line, apool,attribLine,text
exports.getLineHTMLForExport = async (hookName, context) => {
const align = _analyzeLine(context.attribLine, context.apool);
if (align) {
if (context.text.indexOf('*') === 0) {
context.lineContent = context.lineContent.replace('*', '');
}
const heading = context.lineContent.match(/<h([1-6])([^>]+)?>/);
if (heading) {
if (heading.indexOf('style=') === -1) {
context.lineContent = context.lineContent.replace('>', ` style='text-align:${align}'>`);
} else {
context.lineContent = context.lineContent.replace('style=', `style='text-align:${align} `);
}
} else {
context.lineContent =
`<p style='text-align:${align}'>${context.lineContent}</p>`;
}
return context.lineContent;
}
};
exports.padInitToolbar = (hookName, args, cb) => {
const toolbar = args.toolbar;
const alignLeftButton = toolbar.button({
command: 'alignLeft',
localizationId: 'ep_align.toolbar.left.title',
class: 'buttonicon buttonicon-align-left ep_align ep_align_left',
});
const alignCenterButton = toolbar.button({
command: 'alignCenter',
localizationId: 'ep_align.toolbar.center.title',
class: 'buttonicon buttonicon-align-center ep_align ep_align_center',
});
const alignJustifyButton = toolbar.button({
command: 'alignJustify',
localizationId: 'ep_align.toolbar.justify.title',
class: 'buttonicon buttonicon-align-justify ep_align ep_align_justify',
});
const alignRightButton = toolbar.button({
command: 'alignRight',
localizationId: 'ep_align.toolbar.right.title',
class: 'buttonicon buttonicon-align-right ep_align ep_align_right',
});
toolbar.registerButton('alignLeft', alignLeftButton);
toolbar.registerButton('alignCenter', alignCenterButton);
toolbar.registerButton('alignJustify', alignJustifyButton);
toolbar.registerButton('alignRight', alignRightButton);
return cb();
};