From 2e18bd90ae417ff994c6b06274973ca466889abc Mon Sep 17 00:00:00 2001
From: "Tate, Hongliang Tian" <tatetian@gmail.com>
Date: Tue, 17 Mar 2015 14:27:56 +0800
Subject: [PATCH] Add options to reset caption counter

---
 src/Renderer.js        | 12 +++++++-----
 static/test-suite.html |  1 +
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/Renderer.js b/src/Renderer.js
index 4ecee03..add8309 100644
--- a/src/Renderer.js
+++ b/src/Renderer.js
@@ -145,7 +145,7 @@ TextEnvironment.prototype._renderCloseText = function(node) {
                             node.children, newTextStyle);
     if (node.whitespace) this._html.putText(' ');
     this._html.putSpan(closeTextEnv.renderToHTML());
-}
+};
 
 TextEnvironment.prototype.renderToHTML = function() {
     this._html = new HTMLBuilder();
@@ -209,7 +209,7 @@ TextEnvironment.prototype.renderToHTML = function() {
             // \CALL{funcName}{funcArgs}
             // ==>
             // funcName(funcArgs)
-            this._html.beginSpan('ps-funcname').putText(text).endSpan()
+            this._html.beginSpan('ps-funcname').putText(text).endSpan();
             this._html.write('(');
             var argsTextNode = node.children[0];
             this._renderCloseText(argsTextNode);
@@ -413,6 +413,8 @@ function RendererOptions(options) {
     this.lineNumberPunc = options.lineNumberPunc || ':';
     this.lineNumber = options.lineNumber !== undefined ? options.lineNumber : false;
     this.noEnd = options.noEnd !== undefined ? options.noEnd : false;
+    if (options.captionCount !== undefined)
+        Renderer.captionCount = options.captionCount;
 }
 
 RendererOptions.prototype._parseEmVal = function(emVal) {
@@ -438,7 +440,7 @@ function Renderer(parser, options) {
 }
 
 /*  The global counter for the numbering of the algorithm environment */
-Renderer._captionCount = 0;
+Renderer.captionCount = 0;
 
 Renderer.prototype.toMarkup = function() {
     var html = this._html = new HTMLBuilder();
@@ -567,7 +569,7 @@ Renderer.prototype._buildTree = function(node) {
             child = node.children[ci];
             if (child.type !== 'caption') continue;
             lastCaptionNode = child;
-            Renderer._captionCount++;
+            Renderer.captionCount++;
         }
         // Then, build the header for algorithm
         if (lastCaptionNode) {
@@ -748,7 +750,7 @@ Renderer.prototype._buildTree = function(node) {
         break;
     case 'caption':
         this._newLine();
-        this._typeKeyword('Algorithm ' + Renderer._captionCount + ' ');
+        this._typeKeyword('Algorithm ' + Renderer.captionCount + ' ');
         textNode = node.children[0];
         this._buildTree(textNode);
         break;
diff --git a/static/test-suite.html b/static/test-suite.html
index 2c0ca28..252729b 100644
--- a/static/test-suite.html
+++ b/static/test-suite.html
@@ -137,6 +137,7 @@
         });
         var testExamples = document.getElementById("test-examples").textContent;
         pseudocode.render(testExamples, document.body, {
+            captionCount: 0,
             lineNumber: true,
             noEnd: false
         });
-- 
GitLab