Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pseudocode-js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
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
We are moving to Forgejo!
You are on a read-only GitLab instance.
Show more breadcrumbs
Jeffrey Phillips Freeman
pseudocode-js
Commits
b477fd11
Commit
b477fd11
authored
10 years ago
by
Tate, Hongliang Tian
Browse files
Options
Downloads
Patches
Plain Diff
Add font command support
parent
cb8dc7fd
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
+44
-17
44 additions, 17 deletions
PseudoCode.js
css/PseudoCode.css
+8
-4
8 additions, 4 deletions
css/PseudoCode.css
static.html
+4
-1
4 additions, 1 deletion
static.html
with
56 additions
and
22 deletions
PseudoCode.js
+
44
−
17
View file @
b477fd11
...
@@ -77,9 +77,8 @@ closely mirrors that of the grammar.
...
@@ -77,9 +77,8 @@ closely mirrors that of the grammar.
TODO:
TODO:
* comment
* comment
* fonts: \bf, \textbf{} ...
* size: \large, ...
* noend
* noend
* color{#FF0000}{text}
* line number every k lines: \begin{algorithmic}[k]
* line number every k lines: \begin{algorithmic}[k]
* caption without the number: \caption*{}
* caption without the number: \caption*{}
* rename: e.g. require --> input, ensure --> output
* rename: e.g. require --> input, ensure --> output
...
@@ -587,10 +586,15 @@ Parser.prototype._parseSymbol = function() {
...
@@ -587,10 +586,15 @@ Parser.prototype._parseSymbol = function() {
else
if
(
text
=
this
.
_lexer
.
accept
(
'
func
'
,
else
if
(
text
=
this
.
_lexer
.
accept
(
'
func
'
,
[
'
rmfamily
'
,
'
sffamily
'
,
'
ttfamily
'
,
[
'
rmfamily
'
,
'
sffamily
'
,
'
ttfamily
'
,
'
upshape
'
,
'
itshape
'
,
'
slshape
'
,
'
scshape
'
,
'
upshape
'
,
'
itshape
'
,
'
slshape
'
,
'
scshape
'
,
'
bfseries
'
,
'
mdseries
'
,
'
lfseries
'
,
'
bfseries
'
,
'
mdseries
'
,
'
lfseries
'
]))
{
'
uppercase
'
,
'
lowercase
'
]))
{
return
new
ParseNode
(
'
font-dclr
'
,
text
);
return
new
ParseNode
(
'
font-dclr
'
,
text
);
}
}
else
if
(
text
=
this
.
_lexer
.
accept
(
'
func
'
,
[
'
textnormal
'
,
'
textrm
'
,
'
textsf
'
,
'
texttt
'
,
'
textup
'
,
'
textit
'
,
'
textsl
'
,
'
textsc
'
,
'
uppercase
'
,
'
lowercase
'
,
'
textbf
'
,
'
textmd
'
,
'
textlf
'
]))
{
return
new
ParseNode
(
'
font-cmd
'
,
text
);
}
return
null
;
return
null
;
}
}
...
@@ -635,8 +639,9 @@ function TextStyle(outerTextStyle) {
...
@@ -635,8 +639,9 @@ function TextStyle(outerTextStyle) {
cmd - the name of TeX command that alters current font
cmd - the name of TeX command that alters current font
*/
*/
TextStyle
.
prototype
.
_fontCommandTable
=
{
TextStyle
.
prototype
.
_fontCommandTable
=
{
// -------------- declaration --------------
// font-family
// font-family
rmfamily
:
{
'
font-family
'
:
'
KaTeX_Main
'
},
rmfamily
:
{
'
font-family
'
:
'
KaTeX_Main
'
},
sffamily
:
{
'
font-family
'
:
'
KaTeX_SansSerif
'
},
sffamily
:
{
'
font-family
'
:
'
KaTeX_SansSerif
'
},
ttfamily
:
{
'
font-family
'
:
'
KaTeX_Typewriter
'
},
ttfamily
:
{
'
font-family
'
:
'
KaTeX_Typewriter
'
},
// weight
// weight
...
@@ -648,6 +653,20 @@ TextStyle.prototype._fontCommandTable = {
...
@@ -648,6 +653,20 @@ TextStyle.prototype._fontCommandTable = {
itshape
:
{
'
font-style
'
:
'
italic
'
,
'
font-variant
'
:
'
normal
'
},
itshape
:
{
'
font-style
'
:
'
italic
'
,
'
font-variant
'
:
'
normal
'
},
scshape
:
{
'
font-style
'
:
'
normal
'
,
'
font-variant
'
:
'
small-caps
'
},
scshape
:
{
'
font-style
'
:
'
normal
'
,
'
font-variant
'
:
'
small-caps
'
},
slshape
:
{
'
font-style
'
:
'
oblique
'
,
'
font-variant
'
:
'
normal
'
},
slshape
:
{
'
font-style
'
:
'
oblique
'
,
'
font-variant
'
:
'
normal
'
},
// -------------- command --------------
// font-family
textrm
:
{
'
font-family
'
:
'
KaTeX_Main
'
},
textsf
:
{
'
font-family
'
:
'
KaTeX_SansSerif
'
},
texttt
:
{
'
font-family
'
:
'
KaTeX_Typewriter
'
},
// weight
textbf
:
{
'
font-weight
'
:
'
bold
'
},
textmd
:
{
'
font-weight
'
:
'
medium
'
},
textlf
:
{
'
font-weight
'
:
'
lighter
'
},
// shape
textup
:
{
'
font-style
'
:
'
normal
'
,
'
font-variant
'
:
'
normal
'
},
textit
:
{
'
font-style
'
:
'
italic
'
,
'
font-variant
'
:
'
normal
'
},
textsc
:
{
'
font-style
'
:
'
normal
'
,
'
font-variant
'
:
'
small-caps
'
},
textsl
:
{
'
font-style
'
:
'
oblique
'
,
'
font-variant
'
:
'
normal
'
},
// case
// case
uppercase
:
{
'
text-transform
'
:
'
uppercase
'
},
uppercase
:
{
'
text-transform
'
:
'
uppercase
'
},
lowercase
:
{
'
text-transform
'
:
'
lowercase
'
}
lowercase
:
{
'
text-transform
'
:
'
lowercase
'
}
...
@@ -701,15 +720,9 @@ TextStyle.prototype.toCSS = function() {
...
@@ -701,15 +720,9 @@ TextStyle.prototype.toCSS = function() {
return
cssStr
;
return
cssStr
;
};
};
function
TextEnvironment
(
nodes
,
open
,
outerT
extStyle
)
{
function
TextEnvironment
(
nodes
,
t
extStyle
)
{
this
.
_nodes
=
nodes
;
this
.
_nodes
=
nodes
;
this
.
_outerTextStyle
=
outerTextStyle
;
this
.
_textStyle
=
textStyle
;
// For an close text environment, text-style changes should only take
// effect inside the environment. Thus, we should NOT modify
// `outerTextStyle`. In contrast, for an open text environment, we make all
// the updates on outerTextStyle directly.
this
.
_textStyle
=
open
?
outerTextStyle
:
new
TextStyle
(
outerTextStyle
);
}
}
TextEnvironment
.
prototype
.
renderToHTML
=
function
()
{
TextEnvironment
.
prototype
.
renderToHTML
=
function
()
{
...
@@ -743,7 +756,8 @@ TextEnvironment.prototype.renderToHTML = function() {
...
@@ -743,7 +756,8 @@ TextEnvironment.prototype.renderToHTML = function() {
this
.
_html
.
putText
(
replaceStr
);
this
.
_html
.
putText
(
replaceStr
);
break
;
break
;
case
'
close-text
'
:
case
'
close-text
'
:
var
textEnv
=
new
TextEnvironment
(
node
.
children
,
false
,
this
.
_textStyle
);
var
newTextStyle
=
new
TextStyle
();
var
textEnv
=
new
TextEnvironment
(
node
.
children
,
newTextStyle
);
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
break
;
break
;
// There are two kinds of typestyle commands:
// There are two kinds of typestyle commands:
...
@@ -769,7 +783,19 @@ TextEnvironment.prototype.renderToHTML = function() {
...
@@ -769,7 +783,19 @@ TextEnvironment.prototype.renderToHTML = function() {
var
cmdName
=
node
.
value
;
var
cmdName
=
node
.
value
;
this
.
_textStyle
.
updateByCommand
(
cmdName
);
this
.
_textStyle
.
updateByCommand
(
cmdName
);
this
.
_html
.
beginSpan
(
null
,
this
.
_textStyle
.
toCSS
());
this
.
_html
.
beginSpan
(
null
,
this
.
_textStyle
.
toCSS
());
var
textEnv
=
new
TextEnvironment
(
this
.
_nodes
,
true
,
this
.
_textStyle
);
var
textEnv
=
new
TextEnvironment
(
this
.
_nodes
,
this
.
_textStyle
);
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
this
.
_html
.
endSpan
();
break
;
case
'
font-cmd
'
:
var
textNode
=
this
.
_nodes
[
0
];
if
(
textNode
.
type
!==
'
close-text
'
)
continue
;
var
cmdName
=
node
.
value
;
var
innerTextStyle
=
new
TextStyle
();
innerTextStyle
.
updateByCommand
(
cmdName
);
this
.
_html
.
beginSpan
(
null
,
innerTextStyle
.
toCSS
());
var
textEnv
=
new
TextEnvironment
(
textNode
.
children
,
innerTextStyle
);
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
this
.
_html
.
endSpan
();
this
.
_html
.
endSpan
();
break
;
break
;
...
@@ -1201,11 +1227,12 @@ Renderer.prototype._buildTree = function(node) {
...
@@ -1201,11 +1227,12 @@ Renderer.prototype._buildTree = function(node) {
break
;
break
;
// ------------------- Text -------------------
// ------------------- Text -------------------
case
'
open-text
'
:
case
'
open-text
'
:
var
textEnv
=
new
TextEnvironment
(
node
.
children
,
true
,
this
.
_globalTextStyle
);
var
textEnv
=
new
TextEnvironment
(
node
.
children
,
this
.
_globalTextStyle
);
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
break
;
break
;
case
'
close-text
'
:
case
'
close-text
'
:
var
textEnv
=
new
TextEnvironment
(
node
.
children
,
false
,
this
.
_globalTextStyle
);
var
newTextStyle
=
new
TextStyle
();
var
textEnv
=
new
TextEnvironment
(
node
.
children
,
newTextStyle
);
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
this
.
_html
.
putSpan
(
textEnv
.
renderToHTML
());
break
;
break
;
default
:
default
:
...
...
This diff is collapsed.
Click to expand it.
css/PseudoCode.css
+
8
−
4
View file @
b477fd11
...
@@ -22,15 +22,19 @@
...
@@ -22,15 +22,19 @@
margin
:
0
;
padding
:
0
;
margin
:
0
;
padding
:
0
;
line-height
:
1.2
;
line-height
:
1.2
;
}
}
.ps-root
.ps-line
>
span
{
}
.ps-root
.ps-funcname
{
.ps-root
.ps-funcname
{
font-family
:
serif
;
font-family
:
serif
;
font-weight
:
normal
;
font-variant
:
small-caps
;
font-variant
:
small-caps
;
font-style
:
normal
;
text-transform
:
none
;
}
}
/* keyword */
.ps-root
.ps-keyword
{
.ps-root
.ps-keyword
{
font-weight
:
700
;
font-family
:
KaTeX_Main
;
font-weight
:
bold
;
font-variant
:
normal
;
font-style
:
normal
;
text-transform
:
none
;
margin
:
0
0.25em
;
margin
:
0
0.25em
;
}
}
.ps-root
.ps-keyword
:first-child
{
.ps-root
.ps-keyword
:first-child
{
...
...
This diff is collapsed.
Click to expand it.
static.html
+
4
−
1
View file @
b477fd11
...
@@ -18,16 +18,19 @@
...
@@ -18,16 +18,19 @@
\begin{algorithmic}
\begin{algorithmic}
\REQUIRE {asd}{jios}{adf} jioasdfjioas aijosfaisjo asjdf asjoi asdfasdf jo asdjd j asdjo $n \geq 0$
\REQUIRE {asd}{jios}{adf} jioasdfjioas aijosfaisjo asjdf asjoi asdfasdf jo asdjd j asdjo $n \geq 0$
\ENSURE $y = x^n$
\ENSURE $y = x^n$
\STATE pre \textbf{bold text} after
\STATE pre \texttt{typewriter} after
\STATE asjo aosd j asodij jdsf $y \leftarrow 1$ a js j djioas jo j
\STATE asjo aosd j asodij jdsf $y \leftarrow 1$ a js j djioas jo j
\STATE Test text-style commands:
\STATE Test text-style commands:
\STATE different font-family: {\sffamily sffamily \ttfamily ttfamily \rmfamily rmfamily}
\STATE different font-family: {\sffamily sffamily \ttfamily ttfamily \rmfamily rmfamily}
\STATE different wieghts: {normal weight \bfseries bold \mdseries medium \lfseries lighter}
\STATE different wieghts: {normal weight \bfseries bold \mdseries medium \lfseries lighter}
\STATE different shapes: {\itshape itshape \scshape Small-Caps \slshape slshape \upshape upshape}
\STATE different shapes: {\itshape itshape \scshape Small-Caps \slshape slshape \upshape upshape}
\STATE {normal text vs. \slshape after slshape}
\STATE {normal text vs. \slshape after slshape}
\STATE
{
\uppercase all is uppercase} vs.
{
\lowercase ALL lOWER Case}
\STATE \uppercase
{
all is uppercase} vs. \lowercase
{
ALL lOWER Case}
\STATE sizing {\tiny tiny \scriptsize scriptsize \footnotesize
\STATE sizing {\tiny tiny \scriptsize scriptsize \footnotesize
footnotesize \small small \normalsize normal \large large \Large Large
footnotesize \small small \normalsize normal \large large \Large Large
\LARGE LARGE \huge huge \Huge Huge}
\LARGE LARGE \huge huge \Huge Huge}
\STATE from here, everything is \ttfamily ttfamily
\STATE $X \leftarrow x$
\STATE $X \leftarrow x$
\STATE $N \leftarrow n$
\STATE $N \leftarrow n$
\WHILE{$N \neq 0$}
\WHILE{$N \neq 0$}
...
...
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