Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/106446


Change subject: Automatically open/close inline decorations around bidi runs.
......................................................................

Automatically open/close inline decorations around bidi runs.

Change-Id: I69c0be501b4e1663d2f1364048a24c2db273d244
---
M lib/index.js
1 file changed, 22 insertions(+), 13 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
 refs/changes/46/106446/1

diff --git a/lib/index.js b/lib/index.js
index 24ef4e7..4e71b0e 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -175,18 +175,25 @@
        });
 
        var stack = [];
-       var emitDecoration = function(d) {
+       var emitDecoration = function(d, opts) {
                switch (d.type) {
                case 'start-inline':
-                       stack.push(d);
-                       this._writeRaw(d.value);
-                       this._writeRaw(d.delimiter || '{');
-                       break;
                case 'end-inline':
-                       console.assert(stack.length, this.decorations);
-                       console.assert(stack[stack.length-1].value === d.value);
-                       stack.pop();
-                       this._writeRaw(d.delimiter || '}');
+                       var isStart = /^start-/.test(d.type) ^ (!!opts.invert);
+                       if (isStart) {
+                               if (opts.updateStack) {
+                                       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();
+                               }
+                               this._writeRaw(d.delimiter || '}');
+                       }
                        break;
                case 'start-block':
                case 'end-block':
@@ -200,7 +207,8 @@
        var runs = p.countRuns(), pos, i, j, d;
        for (i=j=pos=0; i < runs; i++) {
                var run = p.getVisualRun(i);
-               // XXX open any decorations on stack
+               // open any decorations on stack
+               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++) {
@@ -212,17 +220,18 @@
                        // write text up to this decoration
                        this._writeRaw(texEscape(text.slice(pos, d.pos)));
                        pos = d.pos;
-                       emitDecoration(d);
+                       emitDecoration(d, { updateStack: true });
                }
                // emit any trailing text
                this._writeRaw(texEscape(text.slice(pos, runEnd)));
                pos = runEnd;
-               // XXX close any decorations on the stack
+               // close any decorations on the stack
+               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);
+               emitDecoration(d, { updateStack: true });
        }
        console.assert(stack.length===0, this.decorations, text);
        // done; clear all the buffers

-- 
To view, visit https://gerrit.wikimedia.org/r/106446
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I69c0be501b4e1663d2f1364048a24c2db273d244
Gerrit-PatchSet: 1
Gerrit-Project: 
mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to