HTML export: Await async hook completion before processing results
parent
661a89355f
commit
45bee54aa0
|
@ -33,13 +33,13 @@ async function getPadHTML(pad, revNum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert atext to html
|
// convert atext to html
|
||||||
return getHTMLFromAtext(pad, atext);
|
return await getHTMLFromAtext(pad, atext);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getPadHTML = getPadHTML;
|
exports.getPadHTML = getPadHTML;
|
||||||
exports.getHTMLFromAtext = getHTMLFromAtext;
|
exports.getHTMLFromAtext = getHTMLFromAtext;
|
||||||
|
|
||||||
function getHTMLFromAtext(pad, atext, authorColors)
|
async function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
{
|
{
|
||||||
var apool = pad.apool();
|
var apool = pad.apool();
|
||||||
var textLines = atext.text.slice(0, -1).split('\n');
|
var textLines = atext.text.slice(0, -1).split('\n');
|
||||||
|
@ -48,22 +48,23 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
|
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
|
||||||
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
|
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
|
||||||
|
|
||||||
// prepare tags stored as ['tag', true] to be exported
|
await Promise.all([
|
||||||
hooks.aCallAll("exportHtmlAdditionalTags", pad, function(err, newProps){
|
// prepare tags stored as ['tag', true] to be exported
|
||||||
newProps.forEach(function (propName, i) {
|
hooks.aCallAll('exportHtmlAdditionalTags', pad).then((newProps) => {
|
||||||
tags.push(propName);
|
newProps.forEach((prop) => {
|
||||||
props.push(propName);
|
tags.push(prop);
|
||||||
});
|
props.push(prop);
|
||||||
});
|
});
|
||||||
|
}),
|
||||||
// prepare tags stored as ['tag', 'value'] to be exported. This will generate HTML
|
// prepare tags stored as ['tag', 'value'] to be exported. This will generate HTML with tags
|
||||||
// with tags like <span data-tag="value">
|
// like <span data-tag="value">
|
||||||
hooks.aCallAll("exportHtmlAdditionalTagsWithData", pad, function(err, newProps){
|
hooks.aCallAll('exportHtmlAdditionalTagsWithData', pad).then((newProps) => {
|
||||||
newProps.forEach(function (propName, i) {
|
newProps.forEach((prop) => {
|
||||||
tags.push('span data-' + propName[0] + '="' + propName[1] + '"');
|
tags.push(`span data-${prop[0]}="${prop[1]}"`);
|
||||||
props.push(propName);
|
props.push(prop);
|
||||||
});
|
});
|
||||||
});
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
// holds a map of used styling attributes (*1, *2, etc) in the apool
|
// holds a map of used styling attributes (*1, *2, etc) in the apool
|
||||||
// and maps them to an index in props
|
// and maps them to an index in props
|
||||||
|
@ -336,7 +337,7 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
{
|
{
|
||||||
nextLine = _analyzeLine(textLines[i + 1], attribLines[i + 1], apool);
|
nextLine = _analyzeLine(textLines[i + 1], attribLines[i + 1], apool);
|
||||||
}
|
}
|
||||||
hooks.aCallAll('getLineHTMLForExport', context);
|
await hooks.aCallAll('getLineHTMLForExport', context);
|
||||||
//To create list parent elements
|
//To create list parent elements
|
||||||
if ((!prevLine || prevLine.listLevel !== line.listLevel) || (prevLine && line.listTypeName !== prevLine.listTypeName))
|
if ((!prevLine || prevLine.listLevel !== line.listLevel) || (prevLine && line.listTypeName !== prevLine.listTypeName))
|
||||||
{
|
{
|
||||||
|
@ -476,8 +477,8 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
padId: pad.id
|
padId: pad.id
|
||||||
};
|
};
|
||||||
|
|
||||||
hooks.aCallAll("getLineHTMLForExport", context);
|
await hooks.aCallAll('getLineHTMLForExport', context);
|
||||||
pieces.push(context.lineContent, "<br>");
|
pieces.push(context.lineContent, '<br>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ PadDiff.prototype.getHtml = async function() {
|
||||||
let authorColors = await this._pad.getAllAuthorColors();
|
let authorColors = await this._pad.getAllAuthorColors();
|
||||||
|
|
||||||
// convert the atext to html
|
// convert the atext to html
|
||||||
this._html = exportHtml.getHTMLFromAtext(this._pad, atext, authorColors);
|
this._html = await exportHtml.getHTMLFromAtext(this._pad, atext, authorColors);
|
||||||
|
|
||||||
return this._html;
|
return this._html;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue