This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f0872db0 Simplify remark plugin to use only string replacement
2f0872db0 is described below

commit 2f0872db097c639683372e69eadbe9d71d3e7df9
Author: James Bognar <[email protected]>
AuthorDate: Tue Sep 23 09:30:06 2025 -0400

    Simplify remark plugin to use only string replacement
    
    - Remove redundant AST traversal approach
    - String replacement on file.contents handles all cases comprehensively
    - More reliable and performant than complex node traversal
    - Eliminates potential conflicts between multiple replacement methods
---
 .../src/plugins/remark-version-replacer.js         | 63 ++--------------------
 1 file changed, 5 insertions(+), 58 deletions(-)

diff --git a/juneau-docs-poc/src/plugins/remark-version-replacer.js 
b/juneau-docs-poc/src/plugins/remark-version-replacer.js
index 7891c825a..a3fc3e814 100644
--- a/juneau-docs-poc/src/plugins/remark-version-replacer.js
+++ b/juneau-docs-poc/src/plugins/remark-version-replacer.js
@@ -11,10 +11,10 @@
  * specific language governing permissions and limitations under the License.
  */
 
-const { visit } = require('unist-util-visit');
+// No AST traversal needed - we use string replacement instead
 
 /**
- * Simple string replacement function as fallback
+ * Simple string replacement function that handles all placeholder replacements
  */
 function replaceInString(content, version, apiDocsUrl) {
   return content
@@ -24,71 +24,18 @@ function replaceInString(content, version, apiDocsUrl) {
 
 /**
  * Remark plugin to replace version and API docs placeholders with actual 
values.
- * This works inside code blocks and anywhere else in the markdown.
+ * Simple string replacement approach that works on the entire file content.
  */
 function remarkVersionReplacer(options = {}) {
   const version = options.version || '9.0.1';
   const apiDocsUrl = options.apiDocsUrl || '../apidocs';
   
   return (tree, file) => {
-    // First, do a string-level replacement on the entire file content
+    // Replace placeholders in the entire file content before parsing
     if (file.contents) {
       file.contents = replaceInString(file.contents, version, apiDocsUrl);
     }
-    // Process all nodes that might contain text content
-    visit(tree, (node) => {
-      // Handle text nodes
-      if (node.type === 'text' && node.value) {
-        node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
-        node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
-      }
-      
-      // Handle code nodes
-      if (node.type === 'code' && node.value) {
-        node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
-        node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
-      }
-      
-      // Handle inline code nodes
-      if (node.type === 'inlineCode' && node.value) {
-        node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
-        node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
-      }
-      
-      // Handle link nodes
-      if (node.type === 'link' && node.url) {
-        node.url = node.url.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
-      }
-      
-      // Handle HTML/JSX nodes (like our custom components)
-      if (node.type === 'html' && node.value) {
-        node.value = node.value.replace(/\{\{JUNEAU_VERSION\}\}/g, version);
-        node.value = node.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
-      }
-      
-      // Handle MDX JSX elements
-      if (node.type === 'mdxJsxTextElement' || node.type === 
'mdxJsxFlowElement') {
-        // Process children of JSX elements
-        if (node.children) {
-          node.children.forEach(child => {
-            if (child.type === 'text' && child.value) {
-              child.value = child.value.replace(/\{\{JUNEAU_VERSION\}\}/g, 
version);
-              child.value = child.value.replace(/\{\{API_DOCS\}\}/g, 
apiDocsUrl);
-            }
-          });
-        }
-        
-        // Process attributes
-        if (node.attributes) {
-          node.attributes.forEach(attr => {
-            if (attr.value && typeof attr.value === 'string') {
-              attr.value = attr.value.replace(/\{\{JUNEAU_VERSION\}\}/g, 
version);
-              attr.value = attr.value.replace(/\{\{API_DOCS\}\}/g, apiDocsUrl);
-            }
-          });
-        }
-      }
-    });
+    // No need for AST traversal since string replacement handles all cases
   };
 }
 

Reply via email to