Skip to content

Commit cb24147

Browse files
committed
Add TeX quote support
1 parent 9e0f8a1 commit cb24147

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/Lexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var atomRegex = {
6262
func: /^\\([a-zA-Z]+)/,
6363
open: /^\{/,
6464
close: /^\}/,
65+
quote: /^(`|``|'|'')/,
6566
ordinary: /^[^\\{}$&#%_\s]+/,
6667
math: mathPattern ///^\$.*\$/,
6768
};
@@ -119,7 +120,6 @@ Lexer.prototype._next = function() {
119120
text: usefulText, /* the text value of the atom */
120121
whitespace: whitespaceLen > 0 /* any whitespace before the atom */
121122
};
122-
console.log('type: ' + type + ', text: ' + usefulText);
123123

124124
this._pos += matchText.length;
125125
this._remain = this._remain.slice(match[0].length);

src/Parser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* <special> :== \\ | \{ | \} | \$ | \& | \# | \% | \_
5555
* <cond-symbol> :== \AND | \OR | \NOT | \TRUE | \FALSE | \TO
5656
* <text-symbol> :== \textbackslash
57+
* <quote-symbol> :== ` | `` | ' | ''
5758
* (More LaTeX symbols can be added if necessary. See
5859
* http://get-software.net/info/symbols/comprehensive/symbols-a4.pdf.)
5960
* <math> :== \( + ... + \) | $ ... $
@@ -425,6 +426,9 @@ var ACCEPTED_TOKEN_BY_ATOM = {
425426
tokenType: 'func',
426427
tokenValues: ['AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'TO']
427428
},
429+
'quote-symbol': {
430+
tokenType: 'quote'
431+
},
428432
'sizing-dclr': {
429433
tokenType: 'func',
430434
tokenValues: ['tiny', 'scriptsize', 'footnotesize', 'small', 'normalsize',

src/Renderer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ TextEnvironment.prototype.renderToHTML = function() {
187187
var symbolValue = name2Values[text];
188188
this._html.putText(symbolValue);
189189
break;
190+
case 'quote-symbol':
191+
var quoteReplace = {
192+
'`': '‘',
193+
'``': '“',
194+
'\'': '’',
195+
'\'\'': '”'
196+
};
197+
var realQuote = quoteReplace[text];
198+
this._html.putText(realQuote);
199+
break;
190200
case 'close-text':
191201
var newTextStyle = new TextStyle(this._textStyle.fontSize());
192202
var closeTextEnv = new TextEnvironment(
@@ -406,8 +416,6 @@ RendererOptions.prototype._parseEmVal = function(emVal) {
406416
**/
407417
function Renderer(parser, options) {
408418
this._root = parser.parse();
409-
// debug
410-
console.log(this._root.toString());
411419
this._options = new RendererOptions(options);
412420
this._openLine = false;
413421
this._blockLevel = 0;

static/test-suite.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
\STATE \textbf{Bools:} \AND \OR \NOT \TRUE \FALSE
4848
\STATE \textbf{Carriage return:} first line \\ second line
4949
\STATE \textbf{Text-symbols:} \textbackslash
50+
\STATE \textbf{Quote-symbols:} `single quotes', ``double quotes''
5051
\end{algorithmic}
5152
\end{algorithm}
5253
</pre>
@@ -89,7 +90,7 @@
8990
\begin{algorithmic}
9091
\PROCEDURE{Test-Statements}{}
9192
\STATE this is a normal statement
92-
\PRINT \texttt{this is print statement}
93+
\PRINT \texttt{`this is print statement'}
9394
\RETURN $retval$
9495
\ENDPROCEDURE
9596
\PROCEDURE{Test-Comments}{} \COMMENT{comment for procedure}
@@ -113,7 +114,6 @@
113114
\PROCEDURE{Quicksort}{$A, p, r$}
114115
\IF{$p < r$}
115116
\STATE $q = $ \CALL{Partition}{$A, p, r$}
116-
\COMMENT{this is comment}
117117
\STATE \CALL{Quicksort}{$A, p, q - 1$}
118118
\STATE \CALL{Quicksort}{$A, q + 1, r$}
119119
\ENDIF
@@ -133,14 +133,6 @@
133133
\end{algorithmic}
134134
\end{algorithm}
135135
</pre>
136-
<!--
137-
\IF{$p \lt r$}
138-
\STATE $q = $ \CALL{Partition}{$A, p, r$}
139-
\STATE \CALL{Quicksort}{$A, p, q - 1$}
140-
\STATE \CALL{Quicksort}{$A, q + 1, r$}
141-
\ENDIF
142-
143-
-->
144136
<script type="text/javascript">
145137
var testBasics = document.getElementById("test-basics").textContent;
146138
pseudocode.render(testBasics, document.body, {

0 commit comments

Comments
 (0)