From cb24147b88a435e63a219fd49b60544e8c7c0b50 Mon Sep 17 00:00:00 2001
From: "Tate, Hongliang Tian" <tatetian@gmail.com>
Date: Wed, 11 Mar 2015 14:06:36 +0800
Subject: [PATCH] Add TeX quote support

---
 src/Lexer.js           |  2 +-
 src/Parser.js          |  4 ++++
 src/Renderer.js        | 12 ++++++++++--
 static/test-suite.html | 12 ++----------
 4 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/Lexer.js b/src/Lexer.js
index 15525b0..8f6b926 100644
--- a/src/Lexer.js
+++ b/src/Lexer.js
@@ -62,6 +62,7 @@ var atomRegex = {
     func: /^\\([a-zA-Z]+)/,
     open: /^\{/,
     close: /^\}/,
+    quote: /^(`|``|'|'')/,
     ordinary: /^[^\\{}$&#%_\s]+/,
     math: mathPattern ///^\$.*\$/,
 };
@@ -119,7 +120,6 @@ Lexer.prototype._next = function() {
             text: usefulText, /* the text value of the atom */
             whitespace: whitespaceLen > 0 /* any whitespace before the atom */
         };
-        console.log('type: ' + type + ', text: ' + usefulText);
 
         this._pos += matchText.length;
         this._remain = this._remain.slice(match[0].length);
diff --git a/src/Parser.js b/src/Parser.js
index b755da1..96a2bbb 100644
--- a/src/Parser.js
+++ b/src/Parser.js
@@ -54,6 +54,7 @@
  *     <special>       :== \\ | \{ | \} | \$ | \& | \# | \% | \_
  *     <cond-symbol>   :== \AND | \OR | \NOT | \TRUE | \FALSE | \TO
  *     <text-symbol>   :== \textbackslash
+ *     <quote-symbol>  :== ` | `` | ' | ''
  *     (More LaTeX symbols can be added if necessary. See
  *     http://get-software.net/info/symbols/comprehensive/symbols-a4.pdf.)
  *     <math>          :== \( + ... + \) | $ ... $
@@ -425,6 +426,9 @@ var ACCEPTED_TOKEN_BY_ATOM = {
         tokenType: 'func',
         tokenValues: ['AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'TO']
     },
+    'quote-symbol': {
+        tokenType: 'quote'
+    },
     'sizing-dclr': {
         tokenType: 'func',
         tokenValues: ['tiny', 'scriptsize', 'footnotesize', 'small', 'normalsize',
diff --git a/src/Renderer.js b/src/Renderer.js
index e49a488..cdea760 100644
--- a/src/Renderer.js
+++ b/src/Renderer.js
@@ -187,6 +187,16 @@ TextEnvironment.prototype.renderToHTML = function() {
             var symbolValue = name2Values[text];
             this._html.putText(symbolValue);
             break;
+        case 'quote-symbol':
+            var quoteReplace = {
+                '`': '‘',
+                '``': '“',
+                '\'': '’',
+                '\'\'': '”'
+            };
+            var realQuote = quoteReplace[text];
+            this._html.putText(realQuote);
+            break;
         case 'close-text':
             var newTextStyle = new TextStyle(this._textStyle.fontSize());
             var closeTextEnv = new TextEnvironment(
@@ -406,8 +416,6 @@ RendererOptions.prototype._parseEmVal = function(emVal) {
  **/
 function Renderer(parser, options) {
     this._root = parser.parse();
-    // debug
-    console.log(this._root.toString());
     this._options = new RendererOptions(options);
     this._openLine = false;
     this._blockLevel = 0;
diff --git a/static/test-suite.html b/static/test-suite.html
index 57bc8be..34fe8ed 100644
--- a/static/test-suite.html
+++ b/static/test-suite.html
@@ -47,6 +47,7 @@
         \STATE \textbf{Bools:} \AND \OR \NOT \TRUE \FALSE
         \STATE \textbf{Carriage return:} first line \\ second line
         \STATE \textbf{Text-symbols:} \textbackslash
+        \STATE \textbf{Quote-symbols:} `single quotes', ``double quotes''
         \end{algorithmic}
         \end{algorithm}
     </pre>
@@ -89,7 +90,7 @@
         \begin{algorithmic}
         \PROCEDURE{Test-Statements}{}
             \STATE this is a normal statement
-            \PRINT \texttt{this is print statement}
+            \PRINT \texttt{`this is print statement'}
             \RETURN $retval$        
         \ENDPROCEDURE
         \PROCEDURE{Test-Comments}{} \COMMENT{comment for procedure}
@@ -113,7 +114,6 @@
         \PROCEDURE{Quicksort}{$A, p, r$}
             \IF{$p < r$} 
                 \STATE $q = $ \CALL{Partition}{$A, p, r$}
-                \COMMENT{this is comment}
                 \STATE \CALL{Quicksort}{$A, p, q - 1$}
                 \STATE \CALL{Quicksort}{$A, q + 1, r$}
             \ENDIF
@@ -133,14 +133,6 @@
         \end{algorithmic}
         \end{algorithm}
     </pre>
-    <!-- 
-        \IF{$p \lt r$} 
-            \STATE $q = $ \CALL{Partition}{$A, p, r$}
-            \STATE \CALL{Quicksort}{$A, p, q - 1$}
-            \STATE \CALL{Quicksort}{$A, q + 1, r$}
-        \ENDIF
-    
-    -->
     <script type="text/javascript">
         var testBasics = document.getElementById("test-basics").textContent;
         pseudocode.render(testBasics, document.body, {
-- 
GitLab