@uniweb/semantic-parser 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -162,7 +162,7 @@ When a group begins with headings, the parser reads one **headline stack** with
162
162
  2. **One step smaller** — the next line of the headline: the subtitle first, then further subtitle lines (`subtitle` is a string for one line, an array for several — a three-line header like name / role / affiliation fits in one headline).
163
163
  3. **Two or more steps smaller, or a step back up** — the stack ends; the rest of the run starts a new group (an item), read the same way.
164
164
 
165
- Before the title, `#>` label lines (headings carrying `role: "pretitle"`) and smaller headings ascending to a more important one all join the `pretitle`. A label line anywhere names the block it sits in; a label with no following heading labels an untitled block.
165
+ Before the title, `#>` label lines (headings carrying `role: "pretitle"`) and every smaller heading stacked above the most important one — in whatever order — join the `pretitle`. A label line anywhere names the block it sits in; a label with no following heading labels an untitled block.
166
166
 
167
167
  ### Main content vs items
168
168
 
@@ -180,7 +180,7 @@ This is the mechanism that creates repeating content groups (cards, features, FA
180
180
  Two spellings fill the `pretitle` slot:
181
181
 
182
182
  - **A `#>` label line** — a heading with `role: "pretitle"`. It names the block that starts next, at any depth, with no level arithmetic; the hash count is carried for round-tripping and means nothing.
183
- - **Position** — headings followed by a more important heading at the start of a group (H3 before H1, H6 before H5, …). Stacked smaller headings all join: `#### / ### / # Title` yields a two-line pretitle.
183
+ - **Position** — smaller headings stacked above the most important heading of a run (H3 before H1, H6 before H5, …), in any order. `#### / ### / # Title` and `## / ### / # Title` both yield a two-line pretitle.
184
184
 
185
185
  ### Banner image
186
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/semantic-parser",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Semantic parser for ProseMirror/TipTap content structures",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -232,15 +232,20 @@ function readStack(sequence, startIdx, options = {}) {
232
232
  i++;
233
233
  }
234
234
 
235
- // Ascending positional pretitle: smaller headings stacked directly above
236
- // a more important one (e.g. #### / ### / # Title) all join the pretitle.
237
- while (
238
- i + 1 < sequence.length &&
239
- sequence[i].type === "heading" &&
240
- sequence[i + 1].type === "heading" &&
241
- !isLabel(sequence[i + 1]) &&
242
- sequence[i + 1].level < sequence[i].level
243
- ) {
235
+ // Positional pretitle: the title is the FIRST occurrence of the run's most
236
+ // important level; every smaller heading stacked above it joins the
237
+ // pretitle, in whatever order they were written (#### / ### / # and
238
+ // ## / ### / # both give a two-line pretitle). An ascending-only walk
239
+ // read a descending stack as a bodiless headline followed by a bigger
240
+ // heading, which demoted the real title into the items.
241
+ let best = i;
242
+ for (let k = i; k < sequence.length; k++) {
243
+ const el = sequence[k];
244
+ if (el.type !== "heading") break;
245
+ if (isLabel(el)) continue;
246
+ if (el.level < sequence[best].level || isLabel(sequence[best])) best = k;
247
+ }
248
+ while (i < best) {
244
249
  pre.push(sequence[i]);
245
250
  i++;
246
251
  }