Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pseudocode-js
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jeffrey Phillips Freeman
pseudocode-js
Commits
654e935a
Commit
654e935a
authored
10 years ago
by
Tate, Hongliang Tian
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
PseudoCode.js
+32
-16
32 additions, 16 deletions
PseudoCode.js
css/PseudoCode.css
+0
-1
0 additions, 1 deletion
css/PseudoCode.css
test-suite.html
+45
-6
45 additions, 6 deletions
test-suite.html
with
77 additions
and
23 deletions
PseudoCode.js
+
32
−
16
View file @
654e935a
...
...
@@ -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
(
outer
TextStyl
e
)
{
function
TextStyle
(
outer
FontSiz
e
)
{
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
;
...
...
This diff is collapsed.
Click to expand it.
css/PseudoCode.css
+
0
−
1
View file @
654e935a
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
static
.html
→
test-suite
.html
+
45
−
6
View file @
654e935a
...
...
@@ -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
,
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment