-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
48 lines (43 loc) · 1.5 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
'use strict';
const eejs = require('ep_etherpad-lite/node/eejs/');
const Changeset = require('ep_etherpad-lite/static/js/Changeset');
exports.eejsBlock_editbarMenuLeft = (hookName, args, cb) => {
args.content += eejs.require('ep_headings2/templates/editbarButtons.ejs');
return cb();
};
// Include CSS for HTML export
exports.stylesForExport = () => (
// These should be consistent with client CSS.
'h1{font-size: 2.5em;}\n' +
'h2{font-size: 1.8em;}\n' +
'h3{font-size: 1.5em;}\n' +
'h4{font-size: 1.2em;}\n' +
'code{font-family: RobotoMono;}\n');
const _analyzeLine = (alineAttrs, apool) => {
let header = null;
if (alineAttrs) {
const opIter = Changeset.opIterator(alineAttrs);
if (opIter.hasNext()) {
const op = opIter.next();
header = Changeset.opAttributeValue(op, 'heading', apool);
}
}
return header;
};
// line, apool,attribLine,text
exports.getLineHTMLForExport = async (hookName, context) => {
const header = _analyzeLine(context.attribLine, context.apool);
if (header) {
if (context.text.indexOf('*') === 0) {
context.lineContent = context.lineContent.replace('*', '');
}
const paragraph = context.lineContent.match(/<p([^>]+)?>/);
if (paragraph) {
context.lineContent = context.lineContent.replace('<p', `<${header} `);
context.lineContent = context.lineContent.replace('</p>', `</${header}>`);
} else {
context.lineContent = `<${header}>${context.lineContent}</${header}>`;
}
return context.lineContent;
}
};