Skip to content
Snippets Groups Projects
Commit 654e935a authored by Tate, Hongliang Tian's avatar Tate, Hongliang Tian
Browse files

Add test suite for symbols and fix a bug in sizing commands

parent 2057f568
No related branches found
No related tags found
No related merge requests found
......@@ -77,7 +77,6 @@ closely mirrors that of the grammar.
TODO:
* comment
* noend
* color{#FF0000}{text}
* line number every k lines: \begin{algorithmic}[k]
* caption without the number: \caption*{}
......@@ -359,7 +358,7 @@ Parser.prototype._parseAlgorithmicInner = function() {
while (true) {
var node;
if (!(node = this._parseCommand(CONDITION_COMMANDS)) &&
!(node = this._parseBlock())) break;
!((node = this._parseBlock()).children.length > 0)) break;
algmicNode.addChild(node);
}
......@@ -400,7 +399,7 @@ Parser.prototype._parseBlock = function() {
break;
}
return blockNode.children.length > 0 ? blockNode : null;
return blockNode;
};
Parser.prototype._parseControl = function() {
......@@ -630,10 +629,20 @@ RendererOptions.prototype._parseEmVal = function(emVal) {
color -
variant - none, small-caps
*/
function TextStyle(outerTextStyle) {
function TextStyle(outerFontSize) {
this._css = {};
this._fontSize = 1.0;
this._outerFontSize = outerTextStyle ? outerTextStyle.fontSize() : 1.0;
this._fontSize = this._outerFontSize
= outerFontSize != null ? outerFontSize : 1.0;
}
TextStyle.prototype.outerFontSize = function(size) {
if (size != null) this._outerFontSize = size;
return this._outerFontSize;
}
TextStyle.prototype.fontSize = function() {
return this._fontSize;
}
/* Update the font state by TeX command
......@@ -688,10 +697,6 @@ TextStyle.prototype._sizingScalesTable = {
Huge: 2.28
};
TextStyle.prototype.fontSize = function() {
return this._fontSize;
}
TextStyle.prototype.updateByCommand = function(cmd) {
// Font command
var cmdStyles = this._fontCommandTable[cmd];
......@@ -704,9 +709,8 @@ TextStyle.prototype.updateByCommand = function(cmd) {
// Sizing command
var fontSize = this._sizingScalesTable[cmd];
if (fontSize !== undefined) {
var scale = fontSize / this._outerFontSize;
this._css['font-size'] = scale + 'em';
this._fontSize = this._outerFontSize = fontSize;
this._outerFontSize = this._fontSize;
this._fontSize = fontSize;
return;
}
......@@ -720,6 +724,9 @@ TextStyle.prototype.toCSS = function() {
if (val == null) continue;
cssStr += attr + ':' + this._css[attr] + ';';
}
if (this._fontSize !== this._outerFontSize) {
cssStr += 'font-size:' + (this._fontSize / this._outerFontSize) + 'em;';
}
return cssStr;
};
......@@ -743,6 +750,10 @@ TextEnvironment.prototype.renderToHTML = function() {
var mathHTML = katex.renderToString(math);
this._html.putSpan(mathHTML);
break;
case 'bool':
var text = node.value.toLowerCase();
this._html.beginSpan('ps-keyword').putText(text).endSpan();
break;
case 'special':
var escapedStr = node.value;
var replace = {
......@@ -759,7 +770,7 @@ TextEnvironment.prototype.renderToHTML = function() {
this._html.putText(replaceStr);
break;
case 'close-text':
var newTextStyle = new TextStyle();
var newTextStyle = new TextStyle(this._textStyle.fontSize());
var textEnv = new TextEnvironment(node.children, newTextStyle);
this._html.putSpan(textEnv.renderToHTML());
break;
......@@ -795,7 +806,7 @@ TextEnvironment.prototype.renderToHTML = function() {
if (textNode.type !== 'close-text') continue;
var cmdName = node.value;
var innerTextStyle = new TextStyle();
var innerTextStyle = new TextStyle(this._textStyle.fontSize());
innerTextStyle.updateByCommand(cmdName);
this._html.beginSpan(null, innerTextStyle.toCSS());
var textEnv = new TextEnvironment(textNode.children, innerTextStyle);
......@@ -807,6 +818,7 @@ TextEnvironment.prototype.renderToHTML = function() {
}
}
return this._html.toMarkup();
};
......@@ -982,6 +994,9 @@ Renderer.prototype._newLine = function() {
this._openLine = true;
// For every new line, reset the relative sizing of text style
this._globalTextStyle.outerFontSize(1.0);
var indentSize = this._options.indentSize;
// if this line is for code (e.g. \STATE)
if (this._blockLevel > 0) {
......@@ -1240,7 +1255,8 @@ Renderer.prototype._buildTree = function(node) {
this._html.putSpan(textEnv.renderToHTML());
break;
case 'close-text':
var newTextStyle = new TextStyle();
var outerFontSize = this._globalTextStyle.fontSize();
var newTextStyle = new TextStyle(outerFontSize);
var textEnv = new TextEnvironment(node.children, newTextStyle);
this._html.putSpan(textEnv.renderToHTML());
break;
......
......@@ -6,7 +6,6 @@
}
.ps-root .ps-algorithm {
margin: 0.8em 0;
padding-bottom: 0.2em;
/* algorithm environment has borders; algorithmic has not */
border-top: 3px solid black;
border-bottom: 2px solid black;
......
......@@ -6,11 +6,53 @@
<script src="lib/katex/katex.min.js" type="text/javascript"></script>
<link href="css/PseudoCode.css" type="text/css" rel="stylesheet">
<script src="PseudoCode.js" type="text/javascript"></script>
<title>Hard-coded Result of PseudoCode.js</title>
<style media="screen" type="text/css">
<title>Test suite of PseudoCode.js</title>
</style>
</head>
<body>
<pre id="test0" style="display:none">
\begin{algorithmic}
\STATE \tiny tiny \normalsize normalsize
\STATE font sizings: \tiny tiny \scriptsize scriptsize \footnotesize
footnotesize \small small \normalsize normal \large large \Large Large
\LARGE LARGE \huge huge \Huge Huge \normalsize
\STATE should be normal size
\end{algorithmic}
</pre>
<pre id="test1" style="display:none">
\begin{algorithm}
\caption{Test text-style}
\begin{algorithmic}
\PROCEDURE{Test-Declarations}{}
\STATE font families: {\sffamily sffamily, \ttfamily ttfamily, \normalfont normalfont, \rmfamily rmfamily.}
\STATE font weights: {normal weight, \bfseries bold, \mdseries medium, \lfseries lighter.}
\STATE font shapes: {\itshape itshape \scshape Small-Caps \slshape slshape \upshape upshape.}
\STATE font sizings: \tiny tiny \scriptsize scriptsize \footnotesize
footnotesize \small small \normalsize normal \large large \Large Large
\LARGE LARGE \huge huge \Huge Huge \normalsize
\ENDPROCEDURE
\PROCEDURE{Test-Commands}{}
\STATE \textnormal{textnormal,} \textrm{textrm,} \textsf{textsf,} \texttt{texttt.}
\STATE \textbf{textbf,} \textmd{textmd,} \textlf{textlf.}
\STATE \textup{textup,} \textit{textit,} \textsc{textsc,} \textsl{textsl.}
\STATE \uppercase{uppercase,} \lowercase{LOWERCASE.}
\ENDPROCEDURE
\PROCEDURE{Test-Colors}{}
\ENDPROCEDURE
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Test symbols}
\begin{algorithmic}
\STATE \textbf{Specials:} \{ \} \$ \& \# \% \_
\STATE \textbf{Bool:} \AND \OR \NOT \TRUE \FALSE
\STATE \textbf{Enter:} first part of line \\ second part of line
\end{algorithmic}
\end{algorithm}
</pre>
<pre id="test2" style="display:none">
</pre>
<pre id="code" style="display:none">
\begin{algorithm}
\caption{123!}
......@@ -22,9 +64,6 @@
\STATE pre \texttt{typewriter} after
\STATE asjo aosd j asodij jdsf $y \leftarrow 1$ a js j djioas jo j
\STATE Test text-style commands:
\STATE different font-family: {\sffamily sffamily \ttfamily ttfamily \rmfamily rmfamily}
\STATE different wieghts: {normal weight \bfseries bold \mdseries medium \lfseries lighter}
\STATE different shapes: {\itshape itshape \scshape Small-Caps \slshape slshape \upshape upshape}
\STATE {normal text vs. \slshape after slshape}
\STATE \uppercase{ all is uppercase} vs. \lowercase{ ALL lOWER Case}
\STATE sizing {\tiny tiny \scriptsize scriptsize \footnotesize
......@@ -72,7 +111,7 @@
\end{algorithmic}
</pre>
<script type="text/javascript">
var code = document.getElementById("code").textContent;
var code = document.getElementById("test1").textContent;
// var html = PseudoCode.renderToString(code);
// console.log(html);
PseudoCode.render(code, document.body, {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment