Ver código fonte

[wip] tmp quotes

isundil 8 anos atrás
pai
commit
cb931b2879
1 arquivos alterados com 21 adições e 10 exclusões
  1. 21 10
      msgFormatter.js

+ 21 - 10
msgFormatter.js

@@ -57,7 +57,7 @@ var formatText = (function() {
         this.isStrike = this.trigger === '~' || this.trigger === '-';
 
         /** @type {boolean} */
-        this.isQuote = this.trigger === '>';
+        this.isQuote = this.trigger === '>' || this.trigger === ">";
 
         /** @type {boolean} */
         this.isEmoji = this.trigger === ':';
@@ -78,7 +78,7 @@ var formatText = (function() {
         this.prevTwin = null;
 
         /** @type {boolean|number} */
-        this.terminated = false;
+        this.terminated = this.isEol ? triggerIndex : false;
     }
 
     /** @return {boolean} */
@@ -153,6 +153,8 @@ var formatText = (function() {
                 return true;
             // else no content, should not be finished now
         }
+        if (str[i] === '\n' && this.isEol)
+            return true;
         return false;
     };
 
@@ -207,16 +209,21 @@ var formatText = (function() {
      * @return {string|null}
     **/
     MsgBranch.prototype.isNewToken = function(str, i) {
-        if (this.isCode || this.isCodeBlock || this.isEmoji)
+        if (this.isCode || this.isEmoji || this.isCodeBlock)
             return null;
-        if (!this.lastNode || this.lastNode instanceof MsgTextLeaf) {
-            var nextIsAlphadec = isAlphadec(str[i +1]);
+        if (!this.lastNode || this.lastNode.terminated || this.lastNode instanceof MsgTextLeaf) {
+            var nextIsAlphadec = isAlphadec(str[i +1])
+                ,prevIsAlphadec = isAlphadec(str[i -1]);
 
             if (str.substr(i, 3) === '```')
                 return '```';
+            if (str.substr(i, 4) === ">") // FIXME AND begining of line OR begining of QUOTED
+                return ">";
+            if (str[i] === '>') // FIXME AND begining of line OR begining of QUOTED
+                return str[i];
             if (['`', '\n'].indexOf(str[i]) !== -1)
                 return str[i];
-            if (['*', '~', '-', '_' ].indexOf(str[i]) !== -1 && (nextIsAlphadec || ['*', '`', '~', '-', '_', ':', '<'].indexOf(str[i+1]) !== -1))
+            if (['*', '~', '-', '_' ].indexOf(str[i]) !== -1 && (nextIsAlphadec || ['*', '~', '-', '_', '<', '&'].indexOf(str[i+1]) !== -1))
                 return str[i];
             if ([':', '<'].indexOf(str[i]) !== -1 && nextIsAlphadec)
                 return str[i];
@@ -323,6 +330,7 @@ var formatText = (function() {
 
         if (this._parent.checkIsCodeBlock()) {
             // TODO syntax highlight
+            // TODO line breaks
             classList.push('codeblock');
         } else if (this._parent.checkIsCode()) {
             classList.push('code');
@@ -344,15 +352,17 @@ var formatText = (function() {
     MsgBranch.prototype.outerHTML = function() {
         var html = "";
 
-        if (this.isQuote) {
+        if (this.isQuote)
             html += '<span class="quote">';
-        }
+        if (this.isEol)
+            html += '<br/>';
+
         this.subNodes.forEach(function(node) {
             html += node.outerHTML();
         });
-        if (this.isQuote) {
+
+        if (this.isQuote)
             html += '</span>';
-        }
         return html;
     };
 
@@ -410,6 +420,7 @@ var formatText = (function() {
     };
 
     MsgTree.prototype.eof = function() {
+        // FIXME merge of same block-branches (opti + quoted)
         var unterminated = this.getFirstUnterminated(this.root);
 
         if (unterminated) {