forked from ether/ep_comments_page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportHTML.js
53 lines (41 loc) · 1.54 KB
/
exportHTML.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
var eejs = require('ep_etherpad-lite/node/eejs/');
var _ = require('ep_etherpad-lite/static/js/underscore');
// Add the props to be supported in export
exports.exportHtmlAdditionalTagsWithData = function(hook, pad, cb){
var comments_used = findAllCommentUsedOn(pad);
var tags = transformCommentsIntoTags(comments_used);
cb(tags);
};
// Iterate over pad attributes to find only the comment ones
function findAllCommentUsedOn(pad) {
var comments_used = [];
pad.pool.eachAttrib(function(key, value){
if (key === "comment") {
comments_used.push(value);
}
});
return comments_used;
}
// Transforms an array of comment names into comment tags like ["comment", "c-1234"]
function transformCommentsIntoTags(comment_names) {
return _.map(comment_names, function(comment_name) {
return ["comment", comment_name];
});
}
// TODO: when "asyncLineHTMLForExport" hook is available on Etherpad, use it instead of "getLineHTMLForExport"
// exports.asyncLineHTMLForExport = function (hook, context, cb) {
// cb(rewriteLine);
// }
exports.getLineHTMLForExport = function (hook, context) {
rewriteLine(context);
}
function rewriteLine(context){
var lineContent = context.lineContent;
lineContent = replaceDataByClass(lineContent);
// TODO: when "asyncLineHTMLForExport" hook is available on Etherpad, return "lineContent" instead of re-setting it
context.lineContent = lineContent;
// return lineContent;
}
function replaceDataByClass(text) {
return text.replace(/data-comment=["|'](c-[0-9a-zA-Z]+)["|']/gi, "class='comment $1'");
}