diff --git a/src/Lexer.js b/src/Lexer.js index 15525b07532c94671b0d0cbd49a87bf57952a9e2..8f6b926fdbc1641aca67ff1ec5d9152e044ea447 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 b755da150971c5b299c8f766df793973f133cad5..96a2bbb7bf055934576641f4db05021fb98659c0 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 e49a48899d03807238e90bcd282c4d955a7004d9..cdea760423aeb01b469a0e584e1d64c37dd3353b 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 57bc8be214e84f2dd36f4ceeb1768865ef72d46a..34fe8ed8d9310b443d218127399c40ea0767e41a 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, {