From 8e6b9f5e15d16f388fa15f88a930013a87f6c304 Mon Sep 17 00:00:00 2001
From: Ben Keen <ben.keen@gmail.com>
Date: Fri, 24 May 2013 22:11:59 -0700
Subject: [PATCH] [smarty mode] bugfixes

- escaped quotes in strings now displayed properly
- whitespace no longer affects qualifiers
- parentheses properly highlighted
---
 mode/smarty/smarty.js | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/mode/smarty/smarty.js b/mode/smarty/smarty.js
index 856f7bb3b..826c2b966 100644
--- a/mode/smarty/smarty.js
+++ b/mode/smarty/smarty.js
@@ -91,6 +91,8 @@ CodeMirror.defineMode("smarty", function(config) {
       if (ch == "$") {
         stream.eatWhile(regs.validIdentifier);
         return helpers.cont("variable-2", "variable");
+      } else if (ch == "|") {
+        return helpers.cont("operator", "pipe");
       } else if (ch == ".") {
         return helpers.cont("operator", "property");
       } else if (regs.stringChar.test(ch)) {
@@ -101,6 +103,8 @@ CodeMirror.defineMode("smarty", function(config) {
         return helpers.cont("operator", "operator");
       } else if (ch == "[" || ch == "]") {
         return helpers.cont("bracket", "bracket");
+      } else if (ch == "(" || ch == ")") {
+        return helpers.cont("bracket", "operator");
       } else if (/\d/.test(ch)) {
         stream.eatWhile(/\d/);
         return helpers.cont("number", "number");
@@ -114,6 +118,9 @@ CodeMirror.defineMode("smarty", function(config) {
             stream.eatWhile(regs.validIdentifier);
             return helpers.cont("qualifier", "modifier");
           }
+        } else if (state.last == "pipe") {
+          stream.eatWhile(regs.validIdentifier);
+          return helpers.cont("qualifier", "modifier");
         } else if (state.last == "whitespace") {
           stream.eatWhile(regs.validIdentifier);
           return helpers.cont("attribute", "modifier");
@@ -147,11 +154,15 @@ CodeMirror.defineMode("smarty", function(config) {
 
     inAttribute: function(quote) {
       return function(stream, state) {
+        var prevChar = null;
+        var currChar = null;
         while (!stream.eol()) {
-          if (stream.next() == quote) {
+          currChar = stream.peek();
+          if (stream.next() == quote && prevChar !== '\\') {
             state.tokenize = parsers.smarty;
             break;
           }
+          prevChar = currChar;
         }
         return "string";
       };
-- 
GitLab