diff --git a/PseudoCode.js b/PseudoCode.js index cb1838a88e17ec1fa1096a056a5cb001f21bc905..dc7adf1bd2dec7547e4e5a20a7570e4c14c1b147 100644 --- a/PseudoCode.js +++ b/PseudoCode.js @@ -4,7 +4,6 @@ * TODO: * * demo * * Support color - * * Support TeX comment **/ var ParseError = require('./src/ParseError'); diff --git a/src/Lexer.js b/src/Lexer.js index 8f6b926fdbc1641aca67ff1ec5d9152e044ea447..2e9d4e1bd614bef4083b1c61985e5d350270fd5d 100644 --- a/src/Lexer.js +++ b/src/Lexer.js @@ -66,20 +66,22 @@ var atomRegex = { ordinary: /^[^\\{}$&#%_\s]+/, math: mathPattern ///^\$.*\$/, }; -var commentRegex = /^%.*/ +var commentRegex = /^%.*/; var whitespaceRegex = /^\s+/; Lexer.prototype._skip = function(len) { this._pos += len; this._remain = this._remain.slice(len); -} +}; /* Get the next atom */ Lexer.prototype._next = function() { + var anyWhitespace = false; while (1) { // Skip whitespace (one or more) var whitespaceMatch = whitespaceRegex.exec(this._remain); if (whitespaceMatch) { + anyWhitespace = true; var whitespaceLen = whitespaceMatch[0].length; this._skip(whitespaceLen); } @@ -118,7 +120,7 @@ Lexer.prototype._next = function() { this._nextAtom = { type: type, /* special, func, open, close, ordinary, math */ text: usefulText, /* the text value of the atom */ - whitespace: whitespaceLen > 0 /* any whitespace before the atom */ + whitespace: anyWhitespace /* any whitespace before the atom */ }; this._pos += matchText.length; diff --git a/src/Renderer.js b/src/Renderer.js index cdea760423aeb01b469a0e584e1d64c37dd3353b..139e28a97372234e70447866f753b707621133e9 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -309,7 +309,7 @@ HTMLBuilder.prototype.write = function(html) { HTMLBuilder.prototype.toMarkup = function() { this._flushText(); var html = this._body.join(''); - return html; + return html.trim(); }; HTMLBuilder.prototype.toDOM = function() { @@ -485,9 +485,9 @@ Renderer.prototype._newLine = function() { this._html.beginP('ps-line ps-code', this._globalTextStyle.toCSS()); if (this._options.lineNumber) { this._html.beginSpan('ps-linenum', { - 'left': - ((this._blockLevel - 1)*(indentSize - 0.2)) + 'em' + 'left': - ((this._blockLevel - 1)*(indentSize* 1.25)) + 'em' }) - .putText(this._numLOC + this._options.lineNumberPunc) + .putText(this._numLOC + this._options.lineNumberPunc + ' ') .endSpan(); } } @@ -534,7 +534,7 @@ Renderer.prototype._buildCommentsFromBlock = function(blockNode) { var commentNode = children.shift(); this._buildTree(commentNode); } -} +}; Renderer.prototype._buildTree = function(node) { var ci, child, textNode; diff --git a/static/pseudocode.css b/static/pseudocode.css index 92434f123eabf7bc25ba31d64e5d41fd0b36265c..158a79dd05f10e48ac2c2072842cbca3deabdb47 100644 --- a/static/pseudocode.css +++ b/static/pseudocode.css @@ -52,7 +52,7 @@ position: relative; } .ps-root .ps-algorithmic.with-linenum .ps-line.ps-code { - text-indent: -2.2em; + text-indent: -1.6em; } .ps-root .ps-algorithmic.with-linenum .ps-line.ps-code > span{ text-indent: 0em; diff --git a/static/test-suite.html b/static/test-suite.html index 34fe8ed8d9310b443d218127399c40ea0767e41a..4531d4384cd9da7cb40cb5360e066fa5d0fa89d1 100644 --- a/static/test-suite.html +++ b/static/test-suite.html @@ -36,6 +36,7 @@ \STATE \uppercase{uppercase,} \lowercase{LOWERCASE.} \ENDPROCEDURE \PROCEDURE{Test-Colors}{} + % feature not implemented \ENDPROCEDURE \end{algorithmic} \end{algorithm} @@ -119,6 +120,7 @@ \ENDIF \ENDPROCEDURE \PROCEDURE{Partition}{$A, p, r$} + \STATE someting \STATE $x = A[r]$ \STATE $i = p - 1$ \FOR{$j = p$ \TO $r - 1$} @@ -145,7 +147,7 @@ }); var testExamples = document.getElementById("test-examples").textContent; pseudocode.render(testExamples, document.body, { - lineNumber: false, + lineNumber: true, noEnd: false }); </script>