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
68339aae
There was an error fetching the commit references. Please try again later.
Commit
68339aae
authored
10 years ago
by
Tate, Hongliang Tian
Browse files
Options
Downloads
Patches
Plain Diff
Add options and line number support
parent
c1466010
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PseudoCode.js
+49
-24
49 additions, 24 deletions
PseudoCode.js
static.html
+15
-3
15 additions, 3 deletions
static.html
with
64 additions
and
27 deletions
PseudoCode.js
+
49
−
24
View file @
68339aae
...
...
@@ -522,8 +522,25 @@ Parser.prototype._parseSymbol = function() {
// Builder
// ===========================================================================
function
Builder
(
parser
)
{
function
BuilderOptions
(
options
)
{
options
=
options
||
{};
this
.
indentSize
=
options
.
indentSize
?
this
.
_parseEmVal
(
options
.
indentSize
)
:
1.2
;
this
.
commentSymbol
=
options
.
commentSymbol
||
'
//
'
;
this
.
lineNumberPunc
=
options
.
lineNumberPunc
||
'
:
'
;
this
.
lineNumber
=
options
.
lineNumber
!=
null
?
options
.
lineNumber
:
false
;
}
BuilderOptions
.
prototype
.
_parseEmVal
=
function
(
emVal
)
{
var
emVal
=
emVal
.
trim
();
if
(
emVal
.
indexOf
(
'
em
'
)
!==
emVal
.
length
-
2
)
throw
'
Option unit error; no `em` found
'
;
return
Number
(
emVal
.
substring
(
0
,
emVal
.
length
-
2
));
}
function
Builder
(
parser
,
options
)
{
this
.
_root
=
parser
.
parse
();
this
.
_options
=
new
BuilderOptions
(
options
);
this
.
_blockLevel
=
0
;
console
.
log
(
this
.
_root
.
toString
());
}
...
...
@@ -554,7 +571,19 @@ Builder.prototype._endDiv = function() {
}
Builder
.
prototype
.
_beginLine
=
function
()
{
this
.
_body
.
push
(
'
<p class="ps-line" style="padding-left:
'
+
(
this
.
_blockLevel
*
1.2
)
+
'
em;"">
'
);
var
className
=
'
ps-line
'
;
if
(
this
.
_blockLevel
>
0
)
{
// this line is code
className
+=
'
ps-code
'
;
this
.
_numLOC
++
;
}
var
indent
=
this
.
_blockLevel
*
this
.
_options
.
indentSize
;
this
.
_body
.
push
(
'
<p class="
'
+
className
+
'
" style="padding-left:
'
+
indent
+
'
em;"">
'
);
if
(
this
.
_options
.
lineNumber
&&
this
.
_blockLevel
>
0
)
{
this
.
_body
.
push
(
'
<span class="ps-linenum">
'
+
this
.
_numLOC
+
this
.
_options
.
lineNumberPunc
+
'
</span>
'
);
}
}
Builder
.
prototype
.
_endLine
=
function
()
{
...
...
@@ -594,6 +623,7 @@ Builder.prototype._buildTree = function(node) {
// Then, build the header for algorithm
var
className
=
'
ps-alg
'
;
if
(
lastCaptionNode
)
className
+=
'
with-caption
'
;
if
(
this
.
_options
.
lineNumber
)
className
+=
'
with-linenum
'
;
this
.
_beginDiv
(
className
);
if
(
lastCaptionNode
)
this
.
_buildTree
(
lastCaptionNode
);
// Then, build other nodes
...
...
@@ -613,6 +643,7 @@ Builder.prototype._buildTree = function(node) {
this
.
_endLine
();
break
;
case
'
algorithmic
'
:
if
(
this
.
_options
.
lineNumber
)
this
.
_numLOC
=
0
;
this
.
_buildTreeForAllChildren
(
node
);
break
;
case
'
block
'
:
...
...
@@ -759,29 +790,23 @@ Builder.prototype._buildTree = function(node) {
// ===========================================================================
parentModule
.
PseudoCode
=
{
renderToString
:
function
(
input
)
{
// try {
var
lexer
=
new
Lexer
(
input
);
var
parser
=
new
Parser
(
lexer
);
var
builder
=
new
Builder
(
parser
);
return
builder
.
toMarkup
();
// }
// catch(e) {
// console.log(e.message);
// }
renderToString
:
function
(
input
,
options
)
{
if
(
input
==
null
)
throw
'
input cannot be empty
'
;
var
lexer
=
new
Lexer
(
input
);
var
parser
=
new
Parser
(
lexer
);
var
builder
=
new
Builder
(
parser
,
options
);
return
builder
.
toMarkup
();
},
render
:
function
(
input
,
baseDomEle
)
{
// try {
var
lexer
=
new
Lexer
(
input
);
var
parser
=
new
Parser
(
lexer
);
var
builder
=
new
Builder
(
parser
);
var
ele
=
builder
.
toDOM
();
if
(
baseDomEle
)
baseDomEle
.
appendChild
(
ele
);
return
ele
;
// }
// catch(e) {
// console.log(e.message);
// }
render
:
function
(
input
,
baseDomEle
,
options
)
{
if
(
input
==
null
||
baseDomEle
==
null
)
throw
'
argument cannot be null
'
;
var
lexer
=
new
Lexer
(
input
);
var
parser
=
new
Parser
(
lexer
);
var
builder
=
new
Builder
(
parser
,
options
);
var
ele
=
builder
.
toDOM
();
baseDomEle
.
appendChild
(
ele
);
return
ele
;
}
};
...
...
This diff is collapsed.
Click to expand it.
static.html
+
15
−
3
View file @
68339aae
...
...
@@ -19,8 +19,8 @@
border-bottom
:
2px
solid
black
;
padding-bottom
:
0.2em
;
}
.pseudo
.ps-alg.with-linenum
>
.ps-line
{
margin-left
:
1.2
em
;
.pseudo
.ps-alg.with-linenum
>
.ps-line
.ps-code
{
margin-left
:
0.8
em
;
}
.pseudo
.ps-alg.with-caption
>
.ps-line
:first-child
{
border-bottom
:
2px
solid
black
;
...
...
@@ -28,10 +28,22 @@
.pseudo
.ps-line
{
line-height
:
1.2
;
margin
:
0
0
;
position
:
relative
;
}
.pseudo
.ps-line
>
span
{
font-size
:
1.21em
;
}
.pseudo
.ps-line
>
.ps-linenum
{
font-size
:
0.8em
;
line-height
:
1em
;
position
:
absolute
;
left
:
0
;
top
:
0.6em
;
display
:
block
;
width
:
1.5em
;
text-align
:
right
;
margin-left
:
-0.5em
;
}
.pseudo
.ps-keyword
{
font-weight
:
700
;
margin
:
0
0.25em
;
...
...
@@ -153,7 +165,7 @@
var
code
=
document
.
getElementById
(
"
code
"
).
textContent
;
// var html = PseudoCode.renderToString(code);
// console.log(html);
PseudoCode
.
render
(
code
,
document
.
body
);
PseudoCode
.
render
(
code
,
document
.
body
,
{
lineNumber
:
true
}
);
</script>
</body>
</html>
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