window.RT = window.RT || {};
-
-// Dictionary for cross-referencing, strictly within the RT namespace.
window.RT.dict_label = {};
window.RT.counter_do_count = function (root_node) {
initial_val = 1;
}
- // We start one integer below the initial value so the
- // first increment lands precisely on the initial value.
counters_state[name] = {
stack: [initial_val - 1],
separator: node.getAttribute('separator') || '.',
+ style: node.getAttribute('style') || 'Natural',
+ initial: initial_val,
current_count_str: ''
};
}
state.stack[state.stack.length - 1] += 1;
state.current_count_str = state.stack.join(state.separator);
- // Stamp the count onto the increment node for immediate layout
node.setAttribute('data-count', state.current_count_str);
node.innerHTML = state.current_count_str;
}
} else if (tag === 'rt-counter-label') {
const name = node.getAttribute('name');
if (name && counters_state[name]) {
- // Stamp the most recent count onto the label node for the next pass
- node.setAttribute('data-count', counters_state[name].current_count_str);
+ const state = counters_state[name];
+ // Stamp all relevant metadata for the labeling phase
+ node.setAttribute('data-count', state.current_count_str);
+ node.setAttribute('data-style', state.style);
+ node.setAttribute('data-separator', state.separator);
+ node.setAttribute('data-initial', state.initial);
}
}
- // Evaluate children sequentially
let child = node.firstElementChild;
while (child) {
walk(child);
child = child.nextElementSibling;
}
- // Retreat up the hierarchy
if (pushed_name) {
counters_state[pushed_name].stack.pop();
}
const labels = root_node.querySelectorAll('rt-counter-label');
for (let i = 0; i < labels.length; i++) {
const lbl = labels[i].getAttribute('label');
- const count = labels[i].getAttribute('data-count');
- if (lbl && count !== null) {
- window.RT.dict_label[lbl] = count;
+ if (lbl) {
+ // Store a complete property object instead of just a string
+ window.RT.dict_label[lbl] = {
+ count: labels[i].getAttribute('data-count'),
+ name: labels[i].getAttribute('name'),
+ style: labels[i].getAttribute('data-style'),
+ separator: labels[i].getAttribute('data-separator'),
+ initial: labels[i].getAttribute('data-initial')
+ };
}
}
};
const reads = root_node.querySelectorAll('rt-counter-read');
for (let i = 0; i < reads.length; i++) {
const label = reads[i].getAttribute('label');
+ // Default to 'count' if no key is provided
+ const key = reads[i].getAttribute('key') || 'count';
+
if (label && window.RT.dict_label[label]) {
- reads[i].innerHTML = window.RT.dict_label[label];
+ const value = window.RT.dict_label[label][key];
+ if (value !== undefined && value !== null) {
+ reads[i].innerHTML = value;
+ } else {
+ reads[i].innerHTML = `[Missing key: ${key}]`;
+ }
}
}
};
--- /dev/null
+<!-- differs from test0.html only in that many arguments are left to default -->
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Manuscript Counter Test Bench</title>
+ <script src="RT-Style_locator.js"></script>
+ <script>
+ window.RT.load('Layout/article_tech_ref');
+ </script>
+</head>
+<body>
+
+ <rt-counter-init name="figure"></rt-counter-init>
+
+ <h1>Primary Analysis</h1>
+ <p>
+ Observe the data in Figure <rt-counter-inc name="figure"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="figure" label="fig-primary"></rt-counter-label>
+
+ <rt-counter-indent name="figure">
+ <p>
+ Detail view of the left quadrant: Figure <rt-counter-inc name="figure"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="figure" label="fig-sub-left"></rt-counter-label>
+
+ <p>
+ Detail view of the right quadrant: Figure <rt-counter-inc name="figure"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="figure" label="fig-sub-right"></rt-counter-label>
+
+ <rt-counter-indent name="figure">
+ <p>
+ Microscopic inspection: Figure <rt-counter-inc name="figure"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="figure" label="fig-micro"></rt-counter-label>
+ </rt-counter-indent>
+ </rt-counter-indent>
+
+ <h1>Secondary Analysis</h1>
+ <p>
+ Proceeding to the next major component, shown in Figure <rt-counter-inc name="figure"></rt-counter-inc>.
+ </p>
+
+ <div class="reference-box">
+ <h2>Forward Reference Validation</h2>
+ <p>This text proves we can accurately call back to earlier elements.</p>
+ <ul>
+ <li>The primary analysis was Figure <rt-counter-read label="fig-primary"></rt-counter-read>.</li>
+ <li>The left quadrant was Figure <rt-counter-read label="fig-sub-left"></rt-counter-read>.</li>
+ <li>The microscopic view was Figure <rt-counter-read label="fig-micro"></rt-counter-read>.</li>
+ </ul>
+ </div>
+
+ <script>
+ // Insert the three layout functions here
+ // ... (counter_do_count, counter_do_label, counter_do_read) ...
+
+ // Execute the layout pipeline
+ window.RT.counter_do_count(document.body);
+ window.RT.counter_do_label(document.body);
+ window.RT.counter_do_read(document.body);
+ </script>
+</body>
+</html>
--- /dev/null
+<!-- shows forward referencing and read of other keys -->
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Manuscript Counter Test Bench 2</title>
+ <script src="RT-Style_locator.js"></script>
+ <script>
+ window.RT.load('Layout/article_tech_ref');
+ </script>
+ <style>
+ /* Test specific styles for visibility */
+ rt-counter-inc { font-weight: bold; color: #0056b3; }
+ rt-counter-read { font-weight: bold; color: #d9534f; }
+ .executive-summary { border: 2px solid #333; padding: 15px; margin-bottom: 30px; background: #fafafa;}
+ </style>
+</head>
+<body>
+
+ <rt-counter-init name="equation" style="roman" initial="1" separator="-"></rt-counter-init>
+
+ <div class="executive-summary">
+ <h2>Executive Summary (Forward References)</h2>
+ <p>
+ This section appears before any counting occurs in the DOM.
+ The final equation in this document is Equation <rt-counter-read label="eq-final" key="count"></rt-counter-read>.
+ </p>
+ <p>
+ <strong>Metadata Verification for label "eq-final":</strong>
+ <ul>
+ <li>Name parameter: <rt-counter-read label="eq-final" key="name"></rt-counter-read></li>
+ <li>Style parameter: <rt-counter-read label="eq-final" key="style"></rt-counter-read></li>
+ <li>Separator parameter: <rt-counter-read label="eq-final" key="separator"></rt-counter-read></li>
+ <li>Initial parameter: <rt-counter-read label="eq-final" key="initial"></rt-counter-read></li>
+ </ul>
+ </p>
+ </div>
+
+ <h1>Mathematical Proofs</h1>
+
+ <p>
+ The base formulation is defined in Equation <rt-counter-inc name="equation"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="equation" label="eq-base"></rt-counter-label>
+
+ <rt-counter-indent name="equation">
+ <p>
+ Derivation step A: Equation <rt-counter-inc name="equation"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="equation" label="eq-deriv-a"></rt-counter-label>
+
+ <p>
+ Derivation step B: Equation <rt-counter-inc name="equation"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="equation" label="eq-deriv-b"></rt-counter-label>
+ </rt-counter-indent>
+
+ <p>
+ The concluding formulation is established in Equation <rt-counter-inc name="equation"></rt-counter-inc>.
+ </p>
+ <rt-counter-label name="equation" label="eq-final"></rt-counter-label>
+
+ <script>
+ // Assuming Element/counter.js has been upgraded with the new functions
+ window.RT.counter_do_count(document.body);
+ window.RT.counter_do_label(document.body);
+ window.RT.counter_do_read(document.body);
+ </script>
+</body>
+</html>