From 276db93dc02232bef88451dc4b40ee8d0f7ae0fb Mon Sep 17 00:00:00 2001 From: CE Date: Fri, 25 Mar 2022 19:18:29 +0800 Subject: [PATCH 1/3] feat: render class --- pseudocode.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pseudocode.js b/pseudocode.js index d7bb00e..06663d3 100644 --- a/pseudocode.js +++ b/pseudocode.js @@ -66,4 +66,10 @@ module.exports = { } } }, + + renderClass: function(elements, options) { + for (let index = elements.length - 1; index >= 0; index--) { + this.renderElement(elements[index], options); + } + }, }; From 408e606e04b563cefabe0070bb7c2871c08b4afc Mon Sep 17 00:00:00 2001 From: Chenyu ZHANG <48207708+zcysxy@users.noreply.github.com> Date: Sat, 26 Mar 2022 11:11:47 +0800 Subject: [PATCH 2/3] fix: improve renderClass logic Co-authored-by: Saswat Padhi --- pseudocode.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pseudocode.js b/pseudocode.js index 06663d3..f6e1f0e 100644 --- a/pseudocode.js +++ b/pseudocode.js @@ -67,9 +67,10 @@ module.exports = { } }, - renderClass: function(elements, options) { - for (let index = elements.length - 1; index >= 0; index--) { - this.renderElement(elements[index], options); - } + renderClass: function(class_name, options) { + [].forEach.call( + document.getElementsByClassName(class_name), + function (el) { this.renderElement(el, options); } + ); }, }; From 17089bc36e82436fdde2cf1d40b6bfe821e5d4f9 Mon Sep 17 00:00:00 2001 From: CE Date: Sat, 26 Mar 2022 11:19:07 +0800 Subject: [PATCH 3/3] doc: add renderClass to readme --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 28dcb1f..bbcdda0 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ We assume the pseudocode to be rendered is in a `
` DOM element.
 Here is an example that illustrates a quicksort algorithm:
 
 ```html
-
+
     % This quicksort algorithm is extracted from Chapter 7, Introduction to Algorithms (3rd edition)
     \begin{algorithm}
     \caption{Quicksort}
@@ -116,7 +116,7 @@ Here is an example that illustrates a quicksort algorithm:
 
``` -#### Step 4 · Render the element using pseudocode.js +#### Step 4A · Render the element using pseudocode.js Insert the following Javascript snippet at the end of your document: ```html @@ -125,6 +125,14 @@ Insert the following Javascript snippet at the end of your document: ``` +#### Step 4B · Render the class using pseudocode.js +Insert the following Javascript snippet at the end of your document: + +```html + +``` ### Grammar There are several packages for typesetting algorithms in LaTeX, among which