Report a bug:
If a document has justify/left/center text alignment, when using the plugin PasteHtml
, it ignores the html alignement if it is left.
For instance, I create a document using DocBuilder:
var oDocument = Api.GetDocument();
var oParaPr = oDocument.GetDefaultParaPr();
oParaPr.SetJc("both");
From the plugin API,
window.Asc.plugin.executeMethod(
"PasteHtml",
['<p style="text-align: left;">text</p>'],
function(){}
);
The inserted text is justify instead of left.
The problem comes from the file sdkjs/common/wordcopypaste.js
where the function _applyTextAlign
assumes that the default alignment of the document is left.
To fix it, I modified the function to:
var _applyTextAlign = function () {
let text_align;
if (node.style && node.align && !node.style.textAlign) {
//some editors(LO) put old attr -> align, and skip text-align
text_align = node.align;
} else {
text_align = t._getStyle(node, computedStyle, "text-align");
}
if (text_align) {
//Может приходить -webkit-right
let Jc = null;
if (-1 !== text_align.indexOf('left')) { /* Avoid assumption of left aligment */
Jc = align_Left;
}else if (-1 !== text_align.indexOf('center')) {
Jc = align_Center;
} else if (-1 !== text_align.indexOf('right')) {
Jc = align_Right;
} else if (-1 !== text_align.indexOf('justify')) {
Jc = align_Justify;
}
if (null != Jc) {
Para.Set_Align(Jc, false);
}
}
};
Best,
Document Server version: 7.4 / 7.5