Skip to content

tree: descriptions in a second column - #29

Merged
Paebbels merged 3 commits into
devfrom
claude/tree-description-column
Oct 9, 2026
Merged

Paebbels merged 3 commits into
devfrom
claude/tree-description-column

Conversation

@pytooling-claude

Copy link
Copy Markdown

New Features

  • pyTooling.Sphinx.Tree:
    • An entry may have a description: a | between spaces separates it from the entry's text, e.g.
      - Directory | e.g. myPackage/ . The description is inline ReST, like the text. Entries without one stay
      valid, and so does a | at the line's end (empty description).
    • A | in an inline literal (``int | None``), in interpreted text (a role's text, a hyperlink), or escaped
      as \| separates nothing. A substitution reference (|br|) never separates anything: docutils forbids whitespace
      inside its delimiters.
    • Tree._ParseEntries stores the description under the entry's key description (an empty string if there is
      none). A line with two separators is rejected: tree: '- a | b | c' has more than one separator ' | '; a '|' in a text is escaped as '\|'.
    • New constants SEPARATOR_PATTERN (the separator, with what it isn't searched in) and SEPARATOR (" – ", what a
      format without columns writes between text and description).
    • New Tree._ColumnWidth: estimates the width of the text column from the tree's left edge, as a CSS expression.
  • pyTooling.Sphinx.Node:
    • New nodes TreeSeparator and TreeDescription (both derived from nodes.inline).
    • TreeLabel attribute level; TreeItem attribute columnWidth, set on the roots of a tree with descriptions.
  • pyTooling.Sphinx.HTML: translateTreeSeparator (skips the node) and translateTreeDescription.
  • pyTooling.Sphinx.NODES registers both new nodes.
  • Stylesheet: new custom properties --pyTooling-tree-column-gap (1.5em) and
    --pyTooling-tree-description-min-width (15em); --pyTooling-tree-level on ul.pytooling-tree.

Example - the data model of pyEDAA.Reports' code coverage:

.. tree::

   - CoverageSummary         | the report
     - Directory             | e.g. ``myPackage/``
       - File                | e.g. ``myPackage/Shapes.py``
     - Package

Syntax

| (a pipe between spaces): it reads as a table column in the source, the separators can be aligned with spaces,
and its only clash in inline ReST, the substitution reference, is impossible by docutils' own rule (no whitespace
after the opening or before the closing |). Literals and roles are skipped, and \| is ReST's own escape.

Rejected:

  • --: ReST prose uses it as a dash (smartquotes turns it into an en dash), so a description containing one becomes
    ambiguous.
  • ::: reads as ReST's literal-block marker and as a scope operator, not as a column.
  • Two or more spaces (as in a hand-drawn code block or a ReST simple table): invisible; a stray double space would
    split an entry silently.
  • An indented continuation line or field list ( : description): doubles the lines, loses the table look, and would
    block a later continuation line for long entry texts.
  • A configurable :separator: option: \| already covers the rare clash, and one syntax keeps trees readable across
    projects.
  • A :header: option (column titles): not added. A header row has no place in the tree's lines; it can be added later
    without breaking anything.
  • An option switching the column on: the first entry with a description switches it on.

HTML and CSS

  • A tree with descriptions writes each entry as <span class="tree-row"> (flex, wrapping) holding
    <span class="tree-label"> (expander, icon, text) and <span class="tree-description">. The row sits inside the
    <summary> for an entry with children, so folding works as before. The lines are still drawn by li::before /
    li::after, which don't depend on the row.
  • The root <li> states --pyTooling-tree-column, e.g.
    calc(var(--pyTooling-tree-expander-width) + max(15ch, calc(1 * var(--pyTooling-tree-level) + 18ch), …)): per
    level, the indentation plus the longest text at that level, in character cells (ch). Wide characters (emoji) count
    2, combining and format characters (e.g. U+FE0F) 0, and an icon adds one cell for its gap. The browser evaluates
    max() with the stylesheet's own indentation, so a project overriding the indentation stays aligned.
  • Each row states --pyTooling-tree-depth, and .tree-label gets min-width: min(100%, calc(column - depth * level)),
    so every description starts at the same x, whatever the depth.
  • Not exact by design: CSS grid/subgrid would need display: contents or a grid on <details> and its
    ::details-content, which differs between browsers and breaks the closed state; measuring needs JavaScript, which
    the extension has none of. With min-width, a text wider than estimated pushes only its own description to the
    right, never over it.
  • Narrow screens: flex-wrap. A description without --pyTooling-tree-description-min-width beside its text wraps
    below the text - no horizontal scroll. Empty descriptions are display: none.
  • Other formats (LaTeX, text, …) have no visitors and write the base-classes: text – description in the nested bullet
    list. HTML skips the TreeSeparator, so no hidden dash ends up in the page.

Changes

  • pyTooling.Sphinx.HTML: the expander rules use a descendant selector (summary span.tree-collapsed) instead of a
    child selector, so they reach the expanders inside a row. Trees without descriptions are written exactly as before.
  • pyTooling.Sphinx.Tree._BuildItem takes descriptionColumn.

Known Issues

  • The text column is estimated from the source, not measured: a :ref: showing a section title is counted by its
    target name. A wide uppercase text in a proportional font may exceed its estimate, which shifts that one description
    slightly to the right.
  • An entry's line can't be continued on the next line, so long descriptions mean long source lines.
  • A description wrapping below its label (narrow screens) leaves a small gap in the vertical line to the first child.

Documentation

  • doc/Directives/Tree.rst: new section Descriptions (separator, what isn't one, how the column is laid out and
    estimated), with the code coverage data model as a rendered example. The styling table lists the two new
    properties, HTML and other formats explains the en dash, and Errors lists the new message.
  • Module doc-string of pyTooling.Sphinx.Tree: rubric Descriptions with an example.

Unit Tests

  • tests/unit/Tree.py, testsuite Tree descriptions: description with aligned separator; without description; empty
    description; | in a literal, a role, a hyperlink, escaped, and next to a substitution reference (no separators);
    | declared as a marker; nesting with mixed entries; two separators rejected; description without text rejected;
    _ColumnWidth (per level, emoji and variation selector, description not counted).
  • tests/unit/Extension.py, testsuite Trees with descriptions in a document: HTML (rows, depth, column width, empty
    description, no separator), text and LaTeX (text – description), and a role error inside a description reported at
    the entry's line.

Related Issues and Pull-Requests

claude-code and others added 3 commits October 9, 2026 14:23
An entry's line may hold a description behind a '|' with whitespace before and whitespace or the line's end after it,
e.g. '- Directory   | e.g. ``myPackage/``'. A '|' in an inline literal, in interpreted text or escaped as '\|' is
no separator, and a substitution reference never is one. The description is stored under key 'description' of the
entry, an empty string if there is none; a line with two separators is rejected.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
If an entry has a description, every entry's label ends with a TreeDescription - empty for an entry without one -,
behind a TreeSeparator if it has one. HTML draws each entry as a row of two columns; the root items state the width
of the first column as '--pyTooling-tree-column', each row its level as '--pyTooling-tree-depth', and the first column
of a row is that many levels narrower, so all descriptions start at the same horizontal position. The directive
estimates the column per level in character cells ('ch'); the browser takes the maximum with CSS max(), using the
stylesheet's indentation. A text wider than estimated pushes its own description, and a description narrower than
'--pyTooling-tree-description-min-width' wraps below its text.

Every other format writes the base-classes: 'text – description' in a nested bullet list. HTML skips the separator.

Trees without descriptions are written as before. The expander rules reach into the row.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
Section 'Descriptions' of the tree directive's page: the separator, what isn't one, how the column is laid out and
estimated, and the code coverage data model as a rendered example. The styling table lists the two new properties,
the error list the message for two separators.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 9, 2026 14:27
@pytooling-claude pytooling-claude Bot added Documentation Improvements or additions to documentation Enhancement New feature or request labels Oct 9, 2026
@codacy-production

codacy-production Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 5 minor

Alerts:
⚠ 5 issues (≤ 0 issues of at least minor severity)

Results:
5 new issues

Category Results
Documentation 3 minor
CodeStyle 2 minor

View in Codacy

🟢 Metrics 39 complexity · 0 duplication

Metric Results
Complexity 39
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.42% coverage variation

Metric Results
Coverage variation ✅ +0.42% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3e0ab57) 3007 2397 79.71%
Head commit (b89e221) 3070 (+63) 2460 (+63) 80.13% (+0.42%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#29) 79 79 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.49%. Comparing base (3e0ab57) to head (b89e221).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #29      +/-   ##
==========================================
+ Coverage   77.02%   77.49%   +0.47%     
==========================================
  Files          19       19              
  Lines        3007     3070      +63     
  Branches      437      448      +11     
==========================================
+ Hits         2316     2379      +63     
  Misses        610      610              
  Partials       81       81              
Flag Coverage Δ
unittests 77.49% <100.00%> (+0.47%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants