Repository navigation
tree: descriptions in a second column - #29
Conversation
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>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Documentation | 3 minor |
| CodeStyle | 2 minor |
🟢 Metrics 39 complexity · 0 duplication
Metric Results Complexity 39 Duplication 0
🟢 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 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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
New Features
pyTooling.Sphinx.Tree:|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 stayvalid, and so does a
|at the line's end (empty description).|in an inline literal (``int | None``), in interpreted text (a role's text, a hyperlink), or escapedas
\|separates nothing. A substitution reference (|br|) never separates anything: docutils forbids whitespaceinside its delimiters.
Tree._ParseEntriesstores the description under the entry's keydescription(an empty string if there isnone). A line with two separators is rejected:
tree: '- a | b | c' has more than one separator ' | '; a '|' in a text is escaped as '\|'.SEPARATOR_PATTERN(the separator, with what it isn't searched in) andSEPARATOR(" – ", what aformat without columns writes between text and description).
Tree._ColumnWidth: estimates the width of the text column from the tree's left edge, as a CSS expression.pyTooling.Sphinx.Node:TreeSeparatorandTreeDescription(both derived fromnodes.inline).TreeLabelattributelevel;TreeItemattributecolumnWidth, set on the roots of a tree with descriptions.pyTooling.Sphinx.HTML:translateTreeSeparator(skips the node) andtranslateTreeDescription.pyTooling.Sphinx.NODESregisters both new nodes.--pyTooling-tree-column-gap(1.5em) and--pyTooling-tree-description-min-width(15em);--pyTooling-tree-levelonul.pytooling-tree.Example - the data model of pyEDAA.Reports' code coverage:
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 becomesambiguous.
::: reads as ReST's literal-block marker and as a scope operator, not as a column.split an entry silently.
: description): doubles the lines, loses the table look, and wouldblock a later continuation line for long entry texts.
:separator:option:\|already covers the rare clash, and one syntax keeps trees readable acrossprojects.
:header:option (column titles): not added. A header row has no place in the tree's lines; it can be added laterwithout breaking anything.
HTML and CSS
<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 byli::before/li::after, which don't depend on the row.<li>states--pyTooling-tree-column, e.g.calc(var(--pyTooling-tree-expander-width) + max(15ch, calc(1 * var(--pyTooling-tree-level) + 18ch), …)): perlevel, the indentation plus the longest text at that level, in character cells (
ch). Wide characters (emoji) count2, 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.--pyTooling-tree-depth, and.tree-labelgetsmin-width: min(100%, calc(column - depth * level)),so every description starts at the same x, whatever the depth.
display: contentsor a grid on<details>and its::details-content, which differs between browsers and breaks the closed state; measuring needs JavaScript, whichthe extension has none of. With
min-width, a text wider than estimated pushes only its own description to theright, never over it.
flex-wrap. A description without--pyTooling-tree-description-min-widthbeside its text wrapsbelow the text - no horizontal scroll. Empty descriptions are
display: none.text – descriptionin the nested bulletlist. 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 achild selector, so they reach the expanders inside a row. Trees without descriptions are written exactly as before.
pyTooling.Sphinx.Tree._BuildItemtakesdescriptionColumn.Known Issues
:ref:showing a section title is counted by itstarget name. A wide uppercase text in a proportional font may exceed its estimate, which shifts that one description
slightly to the right.
Documentation
doc/Directives/Tree.rst: new section Descriptions (separator, what isn't one, how the column is laid out andestimated), 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.
pyTooling.Sphinx.Tree: rubric Descriptions with an example.Unit Tests
tests/unit/Tree.py, testsuite Tree descriptions: description with aligned separator; without description; emptydescription;
|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, emptydescription, no separator), text and LaTeX (
text – description), and a role error inside a description reported atthe entry's line.
Related Issues and Pull-Requests
converts it to a
treeonce this is ondev.__all__ofHTML.py, theNODEStable) - the PR merged second takes the union.