From 9e0f8a10647ecd4512b10fabc3469c9adc683fca Mon Sep 17 00:00:00 2001
From: "Tate, Hongliang Tian" <tatetian@gmail.com>
Date: Wed, 11 Mar 2015 13:13:45 +0800
Subject: [PATCH] Add support for Tex-style comment

---
 src/Lexer.js           | 28 ++++++++++++++++++++++------
 static/test-suite.html |  3 ++-
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/Lexer.js b/src/Lexer.js
index 31a9d46..15525b0 100644
--- a/src/Lexer.js
+++ b/src/Lexer.js
@@ -63,16 +63,32 @@ var atomRegex = {
     open: /^\{/,
     close: /^\}/,
     ordinary: /^[^\\{}$&#%_\s]+/,
-    math: mathPattern ///^\$.*\$/
+    math: mathPattern ///^\$.*\$/,
 };
-var whitespaceRegex = /^\s*/;
+var commentRegex = /^%.*/
+var whitespaceRegex = /^\s+/;
+
+Lexer.prototype._skip = function(len) {
+    this._pos += len;
+    this._remain = this._remain.slice(len);
+}
 
 /* Get the next atom */
 Lexer.prototype._next = function() {
-    // Skip whitespace (zero or more)
-    var whitespaceLen = whitespaceRegex.exec(this._remain)[0].length;
-    this._pos += whitespaceLen;
-    this._remain = this._remain.slice(whitespaceLen);
+    while (1) {
+        // Skip whitespace (one or more)
+        var whitespaceMatch = whitespaceRegex.exec(this._remain);
+        if (whitespaceMatch) {
+            var whitespaceLen = whitespaceMatch[0].length;
+            this._skip(whitespaceLen);
+        }
+
+        // Skip comment
+        var commentMatch = commentRegex.exec(this._remain);
+        if (!commentMatch) break;
+        var commentLen = commentMatch[0].length;
+        this._skip(commentLen);
+    }
 
     // Remember the current atom
     this._currentAtom = this._nextAtom;
diff --git a/static/test-suite.html b/static/test-suite.html
index 109342b..57bc8be 100644
--- a/static/test-suite.html
+++ b/static/test-suite.html
@@ -104,8 +104,9 @@
         \end{algorithmic}
         \end{algorithm}
     </pre>
-    <!-- Chapter 7, Introduction to Algorithms (3rd edition)-->
     <pre id="test-examples" style="display:none">
+        % This quicksort algorithm is extracted from Chapter 7, Introduction 
+        % to Algorithms (3rd edition)
         \begin{algorithm}
         \caption{Quicksort}
         \begin{algorithmic}
-- 
GitLab