From: Thomas Walker Lynch Date: Wed, 24 Jun 2026 14:42:55 +0000 (+0000) Subject: working natural number counter, and a couple of tests X-Git-Url: https://git.reasoningtechnology.com/RT-Manuscript_locator.js?a=commitdiff_plain;h=bd30d6630b1c97a82e8ed19dff581f390269717c;p=RT-Style working natural number counter, and a couple of tests --- diff --git a/developer/authored/Manuscript.copy/Element/counter.js b/developer/authored/Manuscript.copy/Element/counter.js index 240675b..633b387 100644 --- a/developer/authored/Manuscript.copy/Element/counter.js +++ b/developer/authored/Manuscript.copy/Element/counter.js @@ -1,6 +1,4 @@ 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) { @@ -20,11 +18,11 @@ 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: '' }; } @@ -41,26 +39,27 @@ window.RT.counter_do_count = function (root_node) { 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(); } @@ -74,9 +73,15 @@ window.RT.counter_do_label = function (root_node) { 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') + }; } } }; @@ -85,8 +90,16 @@ window.RT.counter_do_read = function (root_node) { 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}]`; + } } } }; diff --git a/tester/authored/Counter/test_1.html b/tester/authored/Counter/test_1.html new file mode 100644 index 0000000..a6c4df2 --- /dev/null +++ b/tester/authored/Counter/test_1.html @@ -0,0 +1,66 @@ + + + + + + Manuscript Counter Test Bench + + + + + + + +

Primary Analysis

+

+ Observe the data in Figure . +

+ + + +

+ Detail view of the left quadrant: Figure . +

+ + +

+ Detail view of the right quadrant: Figure . +

+ + + +

+ Microscopic inspection: Figure . +

+ +
+
+ +

Secondary Analysis

+

+ Proceeding to the next major component, shown in Figure . +

+ +
+

Forward Reference Validation

+

This text proves we can accurately call back to earlier elements.

+ +
+ + + + diff --git a/tester/authored/Counter/test_2.html b/tester/authored/Counter/test_2.html new file mode 100644 index 0000000..e908237 --- /dev/null +++ b/tester/authored/Counter/test_2.html @@ -0,0 +1,70 @@ + + + + + + Manuscript Counter Test Bench 2 + + + + + + + + +
+

Executive Summary (Forward References)

+

+ This section appears before any counting occurs in the DOM. + The final equation in this document is Equation . +

+

+ Metadata Verification for label "eq-final": +

+

+
+ +

Mathematical Proofs

+ +

+ The base formulation is defined in Equation . +

+ + + +

+ Derivation step A: Equation . +

+ + +

+ Derivation step B: Equation . +

+ +
+ +

+ The concluding formulation is established in Equation . +

+ + + + +