jenkins-bot has submitted this change and it was merged.
Change subject: Allow env/line/paragraph breaks in the middle of 'inline'
decorations.
......................................................................
Allow env/line/paragraph breaks in the middle of 'inline' decorations.
We simply close the inline style, do the break, and then open it again.
This allows <br/> inside of <i>, for instance.
Change-Id: Iac9e3823b94f85ec959a9d0b6cfeacda830318a3
---
M lib/index.js
1 file changed, 19 insertions(+), 17 deletions(-)
Approvals:
Cscott: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/index.js b/lib/index.js
index 80ca390..270b3a4 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -150,7 +150,7 @@
this.options = options;
this.buffer = [];
this.decorations = [];
- this.inline = 0;
+ this.stack = []; // active inline decorations
this.pos = 0;
this.newEnv = this.newLine = this.newPara = true;
this.dir = 'ltr'; // XXX
@@ -158,6 +158,7 @@
Formatter.prototype.flush = function() {
var deferred = when.defer();
this.envBreak();
+ console.assert(this.stack.length === 0); // all inline styles closed
this.stream.write('', 'utf8', function() {
deferred.resolve();
});
@@ -174,7 +175,6 @@
paraLevel: (this.dir==='ltr') ? ubidi.DEFAULT_LTR :
ubidi.DEFAULT_RTL
});
- var stack = [];
var emitDecoration = function(d, opts) {
/* jshint bitwise: false */ // xor operator is okay.
switch (d.type) {
@@ -183,15 +183,15 @@
var isStart = /^start-/.test(d.type) ^ (!!opts.invert);
if (isStart) {
if (opts.updateStack) {
- stack.push(d);
+ this.stack.push(d);
}
this._writeRaw(d.value);
this._writeRaw(d.delimiter || '{');
} else {
if (opts.updateStack) {
- console.assert(stack.length,
this.decorations);
-
console.assert(stack[stack.length-1].value === d.value);
- stack.pop();
+ console.assert(this.stack.length,
this.decorations);
+
console.assert(this.stack[this.stack.length-1].value === d.value);
+ this.stack.pop();
}
this._writeRaw(d.delimiter || '}');
}
@@ -209,7 +209,7 @@
for (i=j=pos=0; i < runs; i++) {
var run = p.getVisualRun(i);
// open any decorations on stack
- stack.forEach(function(d) { emitDecoration(d, { invert: false
}); });
+ this.stack.forEach(function(d){ emitDecoration(d, { invert:
false });});
// XXX FIX ME XXX do something with run.dir
var runEnd = run.logicalStart + run.length;
for (;; j++) {
@@ -227,14 +227,20 @@
this._writeRaw(texEscape(text.slice(pos, runEnd)));
pos = runEnd;
// close any decorations on the stack
- stack.forEach(function(d) { emitDecoration(d, { invert: true
}); });
+ this.stack.forEach(function(d) { emitDecoration(d, { invert:
true }); });
}
- // emit decorations at end
- for (; j<this.decorations.length-1; j++) {
- d = this.decorations[j];
- emitDecoration(d, { updateStack: true });
+ // emit decorations at end (not including sentinel)
+ if (j < (this.decorations.length-1)) {
+ // open any decorations on stack
+ this.stack.forEach(function(d){ emitDecoration(d, { invert:
false });});
+ // emit trailing decorations
+ for (; j < (this.decorations.length-1); j++) {
+ d = this.decorations[j];
+ emitDecoration(d, { updateStack: true });
+ }
+ // close any decorations on the stack
+ this.stack.forEach(function(d) { emitDecoration(d, { invert:
true }); });
}
- console.assert(stack.length===0, this.decorations, text);
// done; clear all the buffers
this.buffer.length = this.decorations.length = this.pos = 0;
};
@@ -249,14 +255,12 @@
};
Formatter.prototype.paragraphBreak = function() {
if (this.newPara) { return; }
- if (this.inline) { return this.write(' '); }
this.envBreak();
this._writeRaw('\n');
this.newPara = this.newLine = true;
};
Formatter.prototype.lineBreak = function() {
if (this.newLine) { return; }
- if (this.inline) { return this.write(' '); }
this.envBreak();
this._writeRaw('\\\\\n');
this.newLine = true;
@@ -265,8 +269,6 @@
d.pos = this.pos;
this.decorations.push(d);
this.newEnv = this.newLine = this.newPara = false;
- if (d.type==='start-inline') { this.inline++; }
- else if (d.type==='end-inline') { this.inline--; }
};
Formatter.prototype.write = function(text) {
if (this.newEnv || this.newLine || this.newPara) {
--
To view, visit https://gerrit.wikimedia.org/r/106447
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iac9e3823b94f85ec959a9d0b6cfeacda830318a3
Gerrit-PatchSet: 2
Gerrit-Project:
mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits