Merge pull request #2487 from ether/html-e-hook

Better HTML Export rewrite hook allows functions to be passed instead of strings means state is saved between plugins
This commit is contained in:
John McLear 2015-01-25 00:07:34 +00:00
commit 831151cfba
2 changed files with 51 additions and 4 deletions

View file

@ -411,14 +411,28 @@ function getHTMLFromAtext(pad, atext, authorColors)
}
lists = []
var lineContentFromHook = hooks.callAllStr("getLineHTMLForExport",
{
var context = {
line: line,
lineContent: lineContent,
apool: apool,
attribLine: attribLines[i],
text: textLines[i]
}, " ", " ", "");
}
// See https://github.com/ether/etherpad-lite/issues/2486
hooks.aCallAll("asyncLineHTMLForExport", context, function(err, newLineFunction){
// For each function returned by the hook call
// Process the text based on the function
newLineFunction.forEach(function(fn){
context.lineContent = fn(context); // note the fn
});
// We now have a line that has been processed by each hook function
lineContent = context.lineContent; // modified lineContent here
});
// Old hook probably not to be used..
var lineContentFromHook = hooks.callAllStr("getLineHTMLForExport", context, " ", " ", "");
if (lineContentFromHook)
{
pieces.push(lineContentFromHook, '');