|
| 1 | +# Design: Explicit list syntax (`_ul` / `_ol`) |
| 2 | + |
| 3 | +Status: prototype |
| 4 | +Branch: `features/explicit-list-syntax` (off `main`) |
| 5 | + |
| 6 | +## Problem |
| 7 | + |
| 8 | +A YAML list under a heading is structurally identical whether the author means |
| 9 | +"several paragraphs" or "an unordered list". Today YMPrint guesses from the list's |
| 10 | +*contents*: |
| 11 | + |
| 12 | +- a **pure** list of strings → `convert_ul` → bullets |
| 13 | +- a **mixed** list (strings + block/subsection dicts) → each string becomes a |
| 14 | + paragraph |
| 15 | + |
| 16 | +So the same `heading:\n - >prose` renders as a bullet or a paragraph depending on |
| 17 | +what else is in the list. A single wrapped paragraph under a heading silently comes |
| 18 | +out as a one-item bullet list (observed under "Alignment and named styles" in the |
| 19 | +text-styles example). |
| 20 | + |
| 21 | +The ambiguity is **structural** — YAML gives identical structure to both intents — |
| 22 | +so no heuristic can resolve it. One of the two meanings must be made explicit. |
| 23 | + |
| 24 | +## Decision |
| 25 | + |
| 26 | +Make **bullets explicit** and let a bare list mean "a sequence of content items". |
| 27 | + |
| 28 | +- A YAML list is always a *sequence of blocks*: strings become paragraphs, mappings |
| 29 | + become subsections (heading + content), in order. It is never auto-bulleted. |
| 30 | +- Unordered lists are written with the **`_ul`** block; ordered lists with **`_ol`**. |
| 31 | +- The implicit detections (`check_for_nested_lists` → bullets, and the |
| 32 | + dict-with-integer-keys → numbered list) are retired from dispatch. The check |
| 33 | + functions remain (still unit-tested) but no longer drive `build_story`. |
| 34 | + |
| 35 | +This yields a single rule with no guessing: *a list is content in order; bullets and |
| 36 | +numbers are named constructs.* |
| 37 | + |
| 38 | +### Rejected alternative |
| 39 | + |
| 40 | +Making **paragraphs** explicit (`_p`) instead would avoid breaking existing bullet |
| 41 | +lists, but it keeps the surprising default (bare list = bullets) and only adds an |
| 42 | +escape hatch beside the ambiguity rather than removing it. |
| 43 | + |
| 44 | +## Syntax |
| 45 | + |
| 46 | +```yaml |
| 47 | +Findings: |
| 48 | + - The inspection covered three areas. # paragraph |
| 49 | + - _ul: # unordered list |
| 50 | + - The handrail is loose on the north stair. |
| 51 | + - Two ceiling tiles are water-stained. |
| 52 | + - - a nested sub-point # nested list → sub-bullets |
| 53 | + - another sub-point |
| 54 | + - Recommended actions: # subsection heading |
| 55 | + _ol: # ordered list |
| 56 | + - Re-secure the handrail. |
| 57 | + - Replace the stained tiles. |
| 58 | +``` |
| 59 | +
|
| 60 | +- `_ul` value is a list; nested lists produce sub-bullets (unchanged `convert_ul`). |
| 61 | +- `_ol` value is a list; numbering is automatic by position; nested lists produce |
| 62 | + nested numbering. (`convert_ol` also still accepts a mapping for back-compat.) |
| 63 | +- Both may be written as a list item (`- _ul: [...]`) or as the value of a heading |
| 64 | + key (`heading:\n _ul: [...]`). Suffixes are allowed for uniqueness in a mapping |
| 65 | + (`_ul_left`, `_ol_steps`), consistent with other block codes. |
| 66 | + |
| 67 | +## Implementation |
| 68 | + |
| 69 | +`_ul` / `_ol` are intercepted **directly in `build_story`**, not registered in the |
| 70 | +block registry. Two reasons: |
| 71 | + |
| 72 | +1. They are structural (they change how a list is interpreted), sitting naturally |
| 73 | + beside the list-dispatch logic. |
| 74 | +2. It keeps them **forward-compatible with scoped text styles**: `build_story` is |
| 75 | + where a `current_style` parameter lives (on the `features/scoped-text-styles` |
| 76 | + branch), so intercepting here lets `_ul`/`_ol` pass the active style into |
| 77 | + `convert_ul`/`convert_ol`. Routing them through the generic block registry — |
| 78 | + whose converters do not receive the active style — would make bullets ignore the |
| 79 | + surrounding `_textstyle` scope. (On this `main`-based branch there is no |
| 80 | + `current_style` yet; the interception point is chosen so the two features compose |
| 81 | + cleanly when merged.) |
| 82 | + |
| 83 | +| File | Change | |
| 84 | +| --- | --- | |
| 85 | +| `story_builder.py` | Intercept `_ul`/`_ol` (list-item and heading-value forms, with suffixes) → `convert_ul`/`convert_ol`. Replace the implicit bullet/ordered dispatch: a bare list/mapping now always recurses (strings → paragraphs, mappings → subsections). | |
| 86 | +| `content_converters.py` | `convert_ol` accepts a **list** (positional numbering; nested lists nest) as well as a mapping (back-compat). | |
| 87 | +| test data / examples | Migrate bare-list bullets and integer-keyed ordered lists to `_ul` / `_ol`. Genuine multi-paragraph lists (e.g. report 2 "third topic") are left as lists and now render as paragraphs — the intended fix. | |
| 88 | + |
| 89 | +## Backward compatibility |
| 90 | + |
| 91 | +This is a **breaking** content change (consistent with the pre-1.0 status and the |
| 92 | +earlier multi-page-template change): existing documents that relied on bare lists for |
| 93 | +bullets, or integer-keyed mappings for numbered lists, must adopt `_ul` / `_ol`. |
| 94 | + |
| 95 | +## Open questions |
| 96 | + |
| 97 | +- Should `_ol` support an explicit `start:` offset or custom markers (a/i/…)? |
| 98 | +- Should list items be allowed to contain blocks (e.g. an image inside a bullet)? |
| 99 | +- When merged with scoped text styles, thread `current_style` into the `_ul`/`_ol` |
| 100 | + interception so bullets honour the active family. |
0 commit comments