diff --git a/PseudoCode.js b/PseudoCode.js index b1582756df4e059b3dfe25750230fd6247478615..1c3809f7bee49a1706ec731e45a407d5e5c0db38 100644 --- a/PseudoCode.js +++ b/PseudoCode.js @@ -1,14 +1,6 @@ /* - -Pseudocode formater that uses a TeX-style grammar - -As stated in the manual of Algorithms package, `Because the mechanisms used to -build the various algorithmic structures make it difficult to` use the most -intuitive grammar in ... we shall NOT strictly follow the format of our TeX -counterpart. Some details are improved to make it more natural. - -The TeX-style pseudocode language (follows **algoritmic** environment) represented -in a context-free grammar: +The TeX-style pseudocode language (follows **algoritmic** environment) +represented in a context-free grammar: <pseudo> :== ( <algorithm> | <algorithmic> )[0..n] @@ -851,7 +843,6 @@ TextEnvironment.prototype.renderToHTML = function() { } } - return this._html.toMarkup(); }; diff --git a/README.md b/README.md index a5f1dd208faa16d63b60c1c8231e771e6f341c77..dceea6576ac2ef37aeac40aa0201f65167656fb7 100644 --- a/README.md +++ b/README.md @@ -1 +1,59 @@ -# PseudoCode.js +# PseudoCode.js - Beautiful pseudocode for the Web + +PseudoCode.js is a JavaScript library that renders pseudocode beautifully to +HTML. The grammar of pseudocode specified by PseudoCode.js +resembles that of Tex/LaTeX and its algorithm packages. TeX allows simple +construction of math formulas. And LaTeX users who are already familiar with +the algorithm packages can easily adopt PseduoCode.js. + +## Demo + +## Usage +Download PseudoCodo.js and KaTeX, and host them on your server. KaTeX is +required as PseudoCode.js relies on KaTeX to render TeX's math formulas. +And then include the these `js` and `css` files in your HTML files as +follows: + +```html +<link rel="stylesheet" href="//path/to/katex/katex.min.css"> +<script src="//path/to/katex/katex.min.js"></script> +<link rel="stylesheet" href="//path/to/pseudocode/pseudocode.min.css"> +<script src="//path/to/pseudocode/pseudocode.min.js"></script> +``` + +Assume your to-be-renderd pseudocode is in an `<pre>` DOM element: +```html +<pre id="hello-world-code" style="display:hidden;"> +\begin{algorithmc} +\PRINT \texttt{'hello world'} +\end{algorithmc} +</pre> +``` + +To render the above code as a HTML element and append to a parent DOM element, +call `PseudoCode.render`: +```js +var code = document.getElementById("hello-world-code").textContent; +var parentEl = document.body; +var options = {lineNumber: true}; +PseudoCode.render(code, parentEl, options); +``` + +To generate a string of rendered HTML, call `PseudoCode.renderToString`: +```js +var code = document.getElementById("hello-world-code").textContent; +var options = {lineNumber: true}; +var htmlStr = PseudoCode.renderToString(code, options); +console.log(htmlStr); +``` + +## Features + + +## TeX suport +Pseudocode.js is by no means a full-featured TeX implementation in JavaScript. +It only support a subset of TeX/LaTeX commands that are supposed to be +more likely to be used in an algorithm environtment. + +## Acknowledgement +Pseudocode.js is powered by KaTeX to render math expressions.