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

Cole-Greer pushed a commit to branch docs-3.7
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 25c7c87a7141939e101fe11ff1b9b9e145cdf815
Author: Cole Greer <[email protected]>
AuthorDate: Thu May 21 16:33:32 2026 -0700

    Add listingblock wrapper and render callouts as HTML conums
    
    - Wrap tab content in <div class='listingblock'><div class='content'>
      to match published structure
    - Render callout markers (<1>, <2>) as proper HTML conum elements
      with hide-when-copy spans instead of literal text
    - Preserve callouts in console tab display (separate display vs
      execution statement lists)
    - Process callouts per-line after HTML escaping
---
 .../gremlin/docs/GremlinTreeprocessor.java         | 43 +++++++++++++++++-----
 .../tinkerpop/gremlin/docs/TabbedHtmlBuilder.java  | 42 ++++++++++++++++++++-
 2 files changed, 73 insertions(+), 12 deletions(-)

diff --git 
a/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/GremlinTreeprocessor.java
 
b/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/GremlinTreeprocessor.java
index e59ccb181d..34b40a11c6 100644
--- 
a/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/GremlinTreeprocessor.java
+++ 
b/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/GremlinTreeprocessor.java
@@ -349,12 +349,12 @@ public class GremlinTreeprocessor extends Treeprocessor {
         try {
             return doBuildConsoleOutput(block, dryRun);
         } catch (final ConsoleRestartedException e) {
-            // Console was restarted — retry the entire block from scratch
+            // Console was restarted — retry the entire block on the fresh 
console
             LOG.info("Retrying block after console restart");
             try {
                 return doBuildConsoleOutput(block, dryRun);
             } catch (final ConsoleRestartedException e2) {
-                // Second failure — skip this block with a warning rather than 
failing the build
+                // Block is genuinely broken — skip it
                 LOG.warning("Block failed after retry, skipping: " + 
e2.getMessage());
                 return buildDryRunOutput(block);
             }
@@ -387,14 +387,15 @@ public class GremlinTreeprocessor extends Treeprocessor {
 
         final StringBuilder output = new StringBuilder();
         final String[] lines = source.split("\\r?\\n");
-        final List<String> statements = buildStatements(lines);
-        for (final String statement : statements) {
-            // Show each original line with prompt in output
-            for (final String displayLine : statement.split("\\r?\\n")) {
+        final List<String> displayStatements = buildDisplayStatements(lines);
+        final List<String> execStatements = buildStatements(lines);
+        for (int s = 0; s < displayStatements.size(); s++) {
+            // Show original lines with callouts for display
+            for (final String displayLine : 
displayStatements.get(s).split("\\r?\\n")) {
                 output.append(PROMPT).append(displayLine).append("\n");
             }
             if (!dryRun && getActiveExecutor() != null) {
-                final String result = executeSafely(statement);
+                final String result = executeSafely(execStatements.get(s));
                 if (result != null && !result.isEmpty()) {
                     final String[] resultLines = result.split("\\r?\\n");
                     // Skip the first line which is the echo of the command
@@ -408,8 +409,7 @@ public class GremlinTreeprocessor extends Treeprocessor {
     }
 
     /**
-     * Groups source lines into complete statements. Lines ending with a 
period, backslash,
-     * or opening brace, or followed by indented continuation lines, are 
joined.
+     * Groups source lines into complete statements for execution. Strips 
callouts.
      */
     static List<String> buildStatements(final String[] lines) {
         final List<String> statements = new ArrayList<>();
@@ -419,7 +419,6 @@ public class GremlinTreeprocessor extends Treeprocessor {
             if (current.length() == 0) {
                 current.append(cleaned);
             } else if (cleaned.length() > 0 && 
Character.isWhitespace(cleaned.charAt(0))) {
-                // Continuation line (indented)
                 current.append("\n").append(cleaned);
             } else {
                 statements.add(current.toString());
@@ -433,6 +432,30 @@ public class GremlinTreeprocessor extends Treeprocessor {
         return statements;
     }
 
+    /**
+     * Groups source lines into complete statements for display. Preserves 
callouts.
+     */
+    static List<String> buildDisplayStatements(final String[] lines) {
+        final List<String> statements = new ArrayList<>();
+        final StringBuilder current = new StringBuilder();
+        for (final String line : lines) {
+            final String stripped = stripCallouts(line);
+            if (current.length() == 0) {
+                current.append(line);
+            } else if (stripped.length() > 0 && 
Character.isWhitespace(stripped.charAt(0))) {
+                current.append("\n").append(line);
+            } else {
+                statements.add(current.toString());
+                current.setLength(0);
+                current.append(line);
+            }
+        }
+        if (current.length() > 0) {
+            statements.add(current.toString());
+        }
+        return statements;
+    }
+
     /**
      * Strips AsciiDoc callout markers (e.g. {@code <1>}, {@code <2>}) from 
the end of a line.
      */
diff --git 
a/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/TabbedHtmlBuilder.java
 
b/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/TabbedHtmlBuilder.java
index 378fc0963f..f09a2c8533 100644
--- 
a/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/TabbedHtmlBuilder.java
+++ 
b/tools/tinkerpop-docs/src/main/java/org/apache/tinkerpop/gremlin/docs/TabbedHtmlBuilder.java
@@ -127,10 +127,12 @@ public class TabbedHtmlBuilder {
             final Tab tab = tabs.get(i);
             final int tabNum = i + 1;
             html.append("    <div 
class=\"tabcontent-").append(tabNum).append("\">\n");
-            html.append("      <pre class=\"CodeRay highlight\"><code 
data-lang=\"")
+            html.append("<div class=\"listingblock\">\n<div 
class=\"content\">\n");
+            html.append("<pre class=\"CodeRay highlight\"><code data-lang=\"")
                     .append(escapeHtml(tab.getLanguage())).append("\">")
-                    .append(escapeHtml(tab.getContent()))
+                    .append(renderContent(tab.getContent()))
                     .append("</code></pre>\n");
+            html.append("</div>\n</div>\n");
             html.append("    </div>\n");
         }
 
@@ -228,4 +230,40 @@ public class TabbedHtmlBuilder {
                 .replace(">", "&gt;")
                 .replace("\"", "&quot;");
     }
+
+    /**
+     * Escapes HTML and then renders callout markers as proper conum elements.
+     * Converts escaped {@code &lt;N&gt;} patterns into HTML callout spans.
+     */
+    private static String renderContent(final String text) {
+        final String escaped = escapeHtml(text);
+        // Process line by line to handle callouts at end of lines
+        final String[] lines = escaped.split("\\n", -1);
+        final StringBuilder result = new StringBuilder();
+        for (int i = 0; i < lines.length; i++) {
+            if (i > 0) result.append("\n");
+            result.append(renderCallouts(lines[i]));
+        }
+        return result.toString();
+    }
+
+    /**
+     * Replaces trailing callout markers on a line with HTML conum elements.
+     */
+    private static String renderCallouts(final String line) {
+        // Match trailing callout markers: &lt;1&gt; or &lt;1&gt; &lt;2&gt; 
etc.
+        final java.util.regex.Matcher m = java.util.regex.Pattern
+                .compile("\\s*((&lt;\\d+&gt;\\s*)+)$").matcher(line);
+        if (!m.find()) return line;
+        final String prefix = line.substring(0, m.start());
+        final String calloutsPart = m.group(1);
+        final StringBuilder sb = new StringBuilder(prefix);
+        final java.util.regex.Matcher nums = java.util.regex.Pattern
+                .compile("&lt;(\\d+)&gt;").matcher(calloutsPart);
+        while (nums.find()) {
+            sb.append(" <span class=\"hide-when-copy\">//</span> <b 
class=\"conum invisible\">(")
+              .append(nums.group(1)).append(")</b>");
+        }
+        return sb.toString();
+    }
 }

Reply via email to