diff --git a/PseudoCode.js b/PseudoCode.js index 89d540c51ae5150e8053db3dd6490402b80d620c..8030736e9c7971cc5d7e9e929a471ed1016afea2 100644 --- a/PseudoCode.js +++ b/PseudoCode.js @@ -72,17 +72,16 @@ recursive descent parser is **simplity** for the structure of resulting program closely mirrors that of the grammar. TODO: - * command name case-insensitive * comment + * fonts: \bf, \textbf{} ... + * size: \large, ... + * command name case-insensitive * noend * line number every k lines: \begin{algorithmic}[k] * caption without the number: \caption*{} - * excaped char: \\, - * fonts: \bf, \textbf{} ... - * size: \large, ... * rename: e.g. require --> input, ensure --> output * elimiate the default space (smaller than a ' ' char) between spans - * + * double quotes */ (function(parentModule, katex) { // rely on KaTex to process TeX math @@ -640,9 +639,12 @@ Builder.prototype._endDiv = function() { Builder.prototype._beginBlock = function() { if (this._openLine) this._endLine(); - var extraCss = ' ps-outer-block'; - this._body.push('<div class="ps-block' + extraCss + - '" style="margin-left:' + this._options.indentSize + 'em;">'); + + var extraIndentForFirstBlock = + this._options.lineNumber && this._blockLevel == 0 ? 0.6 : 0; + var blockIndent = this._options.indentSize + extraIndentForFirstBlock; + this._body.push('<div class="ps-block" style="margin-left:' + + blockIndent+ 'em;">'); this._blockLevel++; } @@ -667,19 +669,14 @@ Builder.prototype._beginLine = function() { this._body.push('<p class="ps-line ps-code">'); if (this._options.lineNumber) { this._body.push('<span class="ps-linenum" ' + - 'style="left:-' + ( ( this._blockLevel - 1 ) * (indentSize + 0.3)) + + 'style="left:-' + ( ( this._blockLevel - 1 ) * (indentSize - 0.2)) + 'em;">' + this._numLOC + this._options.lineNumberPunc + '</span>'); - this._body.push('<span class="ps-line-content" style="margin-left:' + - ( /*( this._blockLevel - 1 ) * indentSize*/ 0 )+ 'em;">'); } - else - this._body.push('<span class="ps-line-content">'); } // if this line is for pre-conditions (e.g. \REQUIRE) else { this._body.push('<p class="ps-line" style="text-indent:' + (-indentSize) + 'em;padding-left: ' + indentSize +'em;">'); - this._body.push('<span class="ps-line-content">'); } } diff --git a/css/PseudoCode.css b/css/PseudoCode.css index 9d35a65c14956fe719c97512491b621a74dab331..1a3e603a799e541f87345ebb54d0c0c271ff9c59 100644 --- a/css/PseudoCode.css +++ b/css/PseudoCode.css @@ -14,15 +14,13 @@ .pseudo .ps-algorithm.with-caption > .ps-line:first-child { border-bottom: 2px solid black; } +.pseudo .katex { + text-indent: 0; +} .pseudo .ps-line { margin: 0; padding: 0; } -/* line-content is where indent is added to */ -.pseudo .ps-line-content { - line-height: 1.452; - text-indent: 0em; -} -.pseudo .ps-line-content > span { +.pseudo .ps-line > span { font-size: 1.21em; line-height: 1.2; } @@ -42,11 +40,14 @@ .pseudo .ps-linenum { font-size: 0.8em; line-height: 1em; - width: 2em; + width: 1.6em; text-align: right; display: inline-block; position: relative; } .pseudo .ps-algorithmic.with-linenum .ps-line.ps-code { - text-indent: -1.8em; + text-indent: -2.2em; +} +.pseudo .ps-algorithmic.with-linenum .ps-line.ps-code > span{ + text-indent: 0em; } diff --git a/static.html b/static.html index 798b5d2654e40e01d13a27280652900d952bcde3..dfeff481626e75b98c6b62772aa03ef590d58a0b 100644 --- a/static.html +++ b/static.html @@ -30,6 +30,8 @@ \STATE $N \leftarrow N - 1$ \STATE \{\}\$\&\\\#\%\_ \STATE {a {b c} a}{a a} + \PRINT 'hellow world!' + \RETURN 1 \ENDIF \ENDWHILE \end{algorithmic} @@ -56,8 +58,7 @@ // var html = PseudoCode.renderToString(code); // console.log(html); PseudoCode.render(code, document.body, { - - lineNumber: true + lineNumber: false }); </script> </body>