-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexport.js
More file actions
48 lines (44 loc) · 1.39 KB
/
export.js
File metadata and controls
48 lines (44 loc) · 1.39 KB
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 Changeset = require('ep_etherpad-lite/static/js/Changeset').default || require('ep_etherpad-lite/static/js/Changeset');
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;
};
const getInlineStyle = (header) => {
switch (header) {
case 'h1':
return 'font-size: 2.0em;line-height: 120%;';
case 'h2':
return 'font-size: 1.5em;line-height: 120%;';
case 'h3':
return 'font-size: 1.17em;line-height: 120%;';
case 'h4':
return 'line-height: 120%;';
case 'h5':
return 'font-size: 0.83em;line-height: 120%;';
case 'h6':
return 'font-size: 0.75em;line-height: 120%;';
case 'code':
return 'font-family: monospace';
}
return '';
};
// line, apool,attribLine,text
exports.getLineHTMLForExport = async (hook, context) => {
const header = _analyzeLine(context.attribLine, context.apool);
if (header) {
const inlineStyle = getInlineStyle(header);
if (context.lineContent[0] === '*') {
context.lineContent = context.lineContent.substring(1);
}
context.lineContent = `<${header} style="${inlineStyle}">${context.lineContent}</${header}>`;
}
return context.lineContent;
};