From 4bfdba263e02ab59f6374ea7dea8d633a688fee5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BAlia=20Rabello?=
<77292838+julia-rabello@users.noreply.github.com>
Date: Tue, 20 Aug 2024 18:17:33 -0300
Subject: [PATCH 1/2] feat: create script to convert html callouts to markdown
---
docs-utils/fix-callouts.js | 104 +++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 docs-utils/fix-callouts.js
diff --git a/docs-utils/fix-callouts.js b/docs-utils/fix-callouts.js
new file mode 100644
index 000000000..dae2279ec
--- /dev/null
+++ b/docs-utils/fix-callouts.js
@@ -0,0 +1,104 @@
+const fs = require('fs');
+const path = require('path');
+
+// The root folder to process
+const rootFolder = 'docs';
+
+// Maximum number of files to process simultaneously
+const MAX_CONCURRENT_FILES = 100; // Adjust this based on your system's limit
+
+// Array to keep track of currently processing files
+let activeFiles = 0;
+let fileQueue = [];
+
+// Function to process the HTML content
+function convertCallout(htmlCallout) {
+ let markdownCallout = htmlCallout.trim();
+
+ // Remove inline styles (e.g., style="color:red;")
+ markdownCallout = markdownCallout.replace(/\s*style="[^"]*"/g, '');
+
+ // Convert
and
to new lines with `>` prefix
+ markdownCallout = markdownCallout.replace(/
/g, '\n>\n> ');
+
+ // Convert
...
only if it's NOT the firstelement + let firstParagraph = true; + markdownCallout = markdownCallout.replace(/
(.*?)<\/p>/gs, (_, pContent) => {
+ pContent = pContent.trim(); // Remove any extra whitespace around the paragraph content
+
+ if (firstParagraph) {
+ firstParagraph = false;
+ return pContent;
+ }
+
+ // Ensure that any existing blank lines or spaces are cleaned up
+ return `\n> ${pContent}`;
+ });
+
+ // Clean up any excessive blank lines that may have been introduced
+ markdownCallout = markdownCallout.replace(/(\n\s*){2,}/g, '\n>\n');
+
+ // Convert basic HTML tags to markdown
+ markdownCallout = markdownCallout.replace(/(.*?)<\/strong>/g, '**$1**');
+ markdownCallout = markdownCallout.replace(/(.*?)<\/em>/g, '*$1*');
+ markdownCallout = markdownCallout.replace(/(.*?)<\/code>/g, '`$1`'); // Convert
to backticks
+ markdownCallout = markdownCallout.replace(/(.*?)<\/a>/g, '[$2]($1)');
+
+ return markdownCallout;
+}
+
+// Function to process each markdown file
+function processFile(filePath) {
+ activeFiles++;
+
+ fs.readFile(filePath, 'utf8', (err, data) => {
+ if (err) throw err;
+
+ // Replace HTML structures with corresponding markdown symbols
+ const newData = data
+ .replace(/
,
, and
(.*?)<\/ul>/gs, (match, ulContent) => {
+ return ulContent
+ .replace(/
(.*?)<\/ol>/gs, (match, olContent) => {
+ let counter = 1;
+ return olContent
+ .replace(/
(.*?)<\/code>/g, '`$1`'); // Convert
to backticks
markdownCallout = markdownCallout.replace(/(.*?)<\/a>/g, '[$2]($1)');
+ // Append '>' to new lines within the div
+ markdownCallout = markdownCallout.replace(/\n(?!>\s)/g, '\n> ');
+
return markdownCallout;
}