Skip to content

Commit 928d10e

Browse files
committed
Fix broken linenum
1 parent cb24147 commit 928d10e

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

PseudoCode.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* TODO:
55
* * demo
66
* * Support color
7-
* * Support TeX comment
87
**/
98

109
var ParseError = require('./src/ParseError');

src/Lexer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ var atomRegex = {
6666
ordinary: /^[^\\{}$&#%_\s]+/,
6767
math: mathPattern ///^\$.*\$/,
6868
};
69-
var commentRegex = /^%.*/
69+
var commentRegex = /^%.*/;
7070
var whitespaceRegex = /^\s+/;
7171

7272
Lexer.prototype._skip = function(len) {
7373
this._pos += len;
7474
this._remain = this._remain.slice(len);
75-
}
75+
};
7676

7777
/* Get the next atom */
7878
Lexer.prototype._next = function() {
79+
var anyWhitespace = false;
7980
while (1) {
8081
// Skip whitespace (one or more)
8182
var whitespaceMatch = whitespaceRegex.exec(this._remain);
8283
if (whitespaceMatch) {
84+
anyWhitespace = true;
8385
var whitespaceLen = whitespaceMatch[0].length;
8486
this._skip(whitespaceLen);
8587
}
@@ -118,7 +120,7 @@ Lexer.prototype._next = function() {
118120
this._nextAtom = {
119121
type: type, /* special, func, open, close, ordinary, math */
120122
text: usefulText, /* the text value of the atom */
121-
whitespace: whitespaceLen > 0 /* any whitespace before the atom */
123+
whitespace: anyWhitespace /* any whitespace before the atom */
122124
};
123125

124126
this._pos += matchText.length;

src/Renderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ HTMLBuilder.prototype.write = function(html) {
309309
HTMLBuilder.prototype.toMarkup = function() {
310310
this._flushText();
311311
var html = this._body.join('');
312-
return html;
312+
return html.trim();
313313
};
314314

315315
HTMLBuilder.prototype.toDOM = function() {
@@ -485,9 +485,9 @@ Renderer.prototype._newLine = function() {
485485
this._html.beginP('ps-line ps-code', this._globalTextStyle.toCSS());
486486
if (this._options.lineNumber) {
487487
this._html.beginSpan('ps-linenum', {
488-
'left': - ((this._blockLevel - 1)*(indentSize - 0.2)) + 'em'
488+
'left': - ((this._blockLevel - 1)*(indentSize* 1.25)) + 'em'
489489
})
490-
.putText(this._numLOC + this._options.lineNumberPunc)
490+
.putText(this._numLOC + this._options.lineNumberPunc + ' ')
491491
.endSpan();
492492
}
493493
}
@@ -534,7 +534,7 @@ Renderer.prototype._buildCommentsFromBlock = function(blockNode) {
534534
var commentNode = children.shift();
535535
this._buildTree(commentNode);
536536
}
537-
}
537+
};
538538

539539
Renderer.prototype._buildTree = function(node) {
540540
var ci, child, textNode;

static/pseudocode.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
position: relative;
5353
}
5454
.ps-root .ps-algorithmic.with-linenum .ps-line.ps-code {
55-
text-indent: -2.2em;
55+
text-indent: -1.6em;
5656
}
5757
.ps-root .ps-algorithmic.with-linenum .ps-line.ps-code > span{
5858
text-indent: 0em;

static/test-suite.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
\STATE \uppercase{uppercase,} \lowercase{LOWERCASE.}
3737
\ENDPROCEDURE
3838
\PROCEDURE{Test-Colors}{}
39+
% feature not implemented
3940
\ENDPROCEDURE
4041
\end{algorithmic}
4142
\end{algorithm}
@@ -119,6 +120,7 @@
119120
\ENDIF
120121
\ENDPROCEDURE
121122
\PROCEDURE{Partition}{$A, p, r$}
123+
\STATE someting
122124
\STATE $x = A[r]$
123125
\STATE $i = p - 1$
124126
\FOR{$j = p$ \TO $r - 1$}
@@ -145,7 +147,7 @@
145147
});
146148
var testExamples = document.getElementById("test-examples").textContent;
147149
pseudocode.render(testExamples, document.body, {
148-
lineNumber: false,
150+
lineNumber: true,
149151
noEnd: false
150152
});
151153
</script>

0 commit comments

Comments
 (0)