Merge pull request #3132 from CatoTH/pdf-inline-diff-remove-extra-spaces
Remove erroneous margin around inline diff paragraphs in PDF
This commit is contained in:
commit
cd105f2271
@ -498,6 +498,7 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
*/
|
*/
|
||||||
ParseElement = function(alreadyConverted, element, currentParagraph, styles, diff_mode) {
|
ParseElement = function(alreadyConverted, element, currentParagraph, styles, diff_mode) {
|
||||||
styles = styles || [];
|
styles = styles || [];
|
||||||
|
var classes = [];
|
||||||
if (element.getAttribute) {
|
if (element.getAttribute) {
|
||||||
styles = [];
|
styles = [];
|
||||||
var nodeStyle = element.getAttribute("style");
|
var nodeStyle = element.getAttribute("style");
|
||||||
@ -509,7 +510,8 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
}
|
}
|
||||||
var nodeClass = element.getAttribute("class");
|
var nodeClass = element.getAttribute("class");
|
||||||
if (nodeClass) {
|
if (nodeClass) {
|
||||||
nodeClass.split(" ").forEach(function(nodeClass) {
|
classes = nodeClass.toLowerCase().split(" ");
|
||||||
|
classes.forEach(function(nodeClass) {
|
||||||
if (typeof(classStyles[nodeClass]) != 'undefined') {
|
if (typeof(classStyles[nodeClass]) != 'undefined') {
|
||||||
classStyles[nodeClass].forEach(function(style) {
|
classStyles[nodeClass].forEach(function(style) {
|
||||||
styles.push(style);
|
styles.push(style);
|
||||||
@ -679,7 +681,11 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
case "p":
|
case "p":
|
||||||
var pObjectToPush; //determine what to push later
|
var pObjectToPush; //determine what to push later
|
||||||
currentParagraph = create("text");
|
currentParagraph = create("text");
|
||||||
|
if (classes.indexOf("merge-before") > -1) {
|
||||||
|
currentParagraph.marginTop = 0;
|
||||||
|
} else {
|
||||||
currentParagraph.marginTop = 8;
|
currentParagraph.marginTop = 8;
|
||||||
|
}
|
||||||
currentParagraph.lineHeight = 1.25;
|
currentParagraph.lineHeight = 1.25;
|
||||||
var stackP = create("stack");
|
var stackP = create("stack");
|
||||||
stackP.stack.push(currentParagraph);
|
stackP.stack.push(currentParagraph);
|
||||||
|
@ -260,8 +260,9 @@ angular.module('OpenSlidesApp.motions', [
|
|||||||
|
|
||||||
var data = diffService.extractRangeByLineNumbers(html, line_from, line_to);
|
var data = diffService.extractRangeByLineNumbers(html, line_from, line_to);
|
||||||
|
|
||||||
html = data.outerContextStart + data.innerContextStart + data.html +
|
// Add "merge-before"-css-class if the first line begins in the middle of a paragraph. Used for PDF.
|
||||||
data.innerContextEnd + data.outerContextEnd;
|
html = diffService.addCSSClassToFirstTag(data.outerContextStart + data.innerContextStart, "merge-before") +
|
||||||
|
data.html + data.innerContextEnd + data.outerContextEnd;
|
||||||
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, line_from);
|
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, line_from);
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
@ -280,9 +281,9 @@ angular.module('OpenSlidesApp.motions', [
|
|||||||
var data = diffService.extractRangeByLineNumbers(html, maxLine, null);
|
var data = diffService.extractRangeByLineNumbers(html, maxLine, null);
|
||||||
|
|
||||||
if (data.html !== '') {
|
if (data.html !== '') {
|
||||||
html = data.outerContextStart + data.innerContextStart +
|
// Add "merge-before"-css-class if the first line begins in the middle of a paragraph. Used for PDF.
|
||||||
data.html +
|
html = diffService.addCSSClassToFirstTag(data.outerContextStart + data.innerContextStart, "merge-before") +
|
||||||
data.innerContextEnd + data.outerContextEnd;
|
data.html + data.innerContextEnd + data.outerContextEnd;
|
||||||
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, maxLine);
|
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, maxLine);
|
||||||
} else {
|
} else {
|
||||||
// Prevents empty lines at the end of the motion
|
// Prevents empty lines at the end of the motion
|
||||||
@ -763,6 +764,12 @@ angular.module('OpenSlidesApp.motions', [
|
|||||||
diff = lineNumberingService.highlightLine(diff, highlight);
|
diff = lineNumberingService.highlightLine(diff, highlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var origBeginning = data.outerContextStart + data.innerContextStart;
|
||||||
|
if (diff.toLowerCase().indexOf(origBeginning.toLowerCase()) === 0) {
|
||||||
|
// Add "merge-before"-css-class if the first line begins in the middle of a paragraph. Used for PDF.
|
||||||
|
diff = diffService.addCSSClassToFirstTag(origBeginning, "merge-before") + diff.substring(origBeginning.length);
|
||||||
|
}
|
||||||
|
|
||||||
return diff;
|
return diff;
|
||||||
},
|
},
|
||||||
getType: function(original_full_html) {
|
getType: function(original_full_html) {
|
||||||
|
@ -983,6 +983,18 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
|
|||||||
return this._serializeDom(mergedFragment);
|
return this._serializeDom(mergedFragment);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.addCSSClassToFirstTag = function (html, className) {
|
||||||
|
return html.replace(/<[a-z][^>]*>/i, function (match) {
|
||||||
|
if (match.match(/class=["'][a-z0-9 _-]*["']/i)) {
|
||||||
|
return match.replace(/class=["']([a-z0-9 _-]*)["']/i, function (match2, previousClasses) {
|
||||||
|
return "class=\"" + previousClasses + " " + className + "\"";
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return match.substring(0, match.length - 1) + " class=\"" + className + "\">";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function calculates the diff between two strings and tries to fix problems with the resulting HTML.
|
* This function calculates the diff between two strings and tries to fix problems with the resulting HTML.
|
||||||
* If lineLength and firstLineNumber is given, line numbers will be returned es well
|
* If lineLength and firstLineNumber is given, line numbers will be returned es well
|
||||||
|
@ -482,4 +482,18 @@ describe('linenumbering', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('addCSSClassToFirstTag function', function () {
|
||||||
|
it('works with plain tags', function () {
|
||||||
|
var strIn = "<ol start='2'><li>",
|
||||||
|
inserted = diffService.addCSSClassToFirstTag(strIn, "newClass");
|
||||||
|
expect(inserted).toBe("<ol start='2' class=\"newClass\"><li>")
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works with tags already having classes', function () {
|
||||||
|
var strIn = "<ol start='2' class='my-old-class'><li>",
|
||||||
|
inserted = diffService.addCSSClassToFirstTag(strIn, "newClass");
|
||||||
|
expect(inserted).toBe("<ol start='2' class=\"my-old-class newClass\"><li>")
|
||||||
|
});
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user