Skip to content

Scoped, switchable named text styles (+ align / underline) - #7

Merged
connorferster merged 3 commits into
mainfrom
features/scoped-text-styles
Aug 13, 2026
Merged

Scoped, switchable named text styles (+ align / underline)#7
connorferster merged 3 commits into
mainfrom
features/scoped-text-styles

Conversation

@connorferster

@connorferster connorferster commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Adds named text styles and a frame-scoped _textstyle block to switch between them within report source, plus per-style align and underline — without introducing global parse-time state.

Builds on #6 (explicit list syntax), which is now merged into main; this branch is rebased on top, so the diff is text-style changes only.

Changes

  • _style.styles declares named families as sparse overrides of the default body/headings family (inherit-from-body).
  • _textstyle: <name> switches the active family for the rest of its recursion frame, inherited by descendants, reverting when the frame returns. Switching swaps the whole family (body, bullets, derived headings).
  • State is threaded as a current_style parameter through build_story and the content converters — no global mutable cursor.
  • Config merge carries user-defined extension keys (named styles).
  • align (left/center/right/justify) → ReportLab ParagraphStyle.alignment; underline (bool) via <u>…</u>.

Composition with the list syntax (#6)

_ul/_ol are intercepted in build_story with the active current_style threaded in, so bullets/numbers honour the surrounding _textstyle scope (verified: a _ul inside a fine-print scope renders at the fine-print size). report_example_4.yml uses _ul/_ol.

Testing

45 tests pass on the composed code, incl. tests/test_scoped_text_styles.py and the report_example_4.yml integration render.

Design doc: design/scoped-text-styles.md.

🤖 Generated with Claude Code

connor-sp and others added 3 commits August 13, 2026 22:14
Add named text styles and a frame-scoped `_textstyle` block to switch between
them within report source, without introducing global parse-time state.

- `_style.styles` declares named families as sparse overrides of the default
  body/headings family (inherit-from-body).
- `_textstyle: <name>` switches the active family for the rest of its recursion
  frame and is inherited by descendant frames, reverting when the frame returns.
  Switching swaps the whole family (body, bullets, and derived headings).
- State is threaded as a `current_style` parameter through build_story and the
  content converters -- no global mutable cursor.
- Config merge now carries user-defined extension keys (named `styles`) that the
  defaults have no schema for.

Includes a design doc (design/scoped-text-styles.md), an example
(Examples/Text Styles), and tests covering inheritance, whole-family heading
rescale, scoping/revert, and error cases.

Scope limits (documented): only paragraphs, headings, and lists honour the
active style; other blocks keep default styling. Names only, no index.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add two per-style formatting attributes that compose with named text styles:

- `align` (left/center/right/justify) on body, headings, and named styles, mapped
  to ReportLab's native ParagraphStyle.alignment via convert_alignment().
- `underline` (bool) applied at render time by wrapping text in <u>...</u>, since
  ParagraphStyle has no honored underline attribute. Applies to paragraphs and
  headings; bullets are not wrapped.

Both live on a shared FormatMixin so they are inherited by named styles like any
other field. Updates the example and design doc; adds tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add report_example_4.yml showcasing named text styles, _textstyle switching
(both the list-item and mapping-key forms), per-style alignment, and heading /
body underline, then render it through load_report in test_load_yaml alongside
the other example reports.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@connorferster
connorferster force-pushed the features/scoped-text-styles branch from 3b1b690 to b1b8064 Compare August 13, 2026 22:15
@connorferster
connorferster changed the base branch from main to features/explicit-list-syntax August 13, 2026 22:15
@connorferster
connorferster changed the base branch from features/explicit-list-syntax to main August 13, 2026 22:16
@connorferster
connorferster merged commit 0f8cde7 into main Aug 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants