Markdown table of contents: the node added for a skipped heading level shows the wrong numeral
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 80/100
Direzione di ricerca
Inizia da MarkdownTableOfContents.rebuild_table_of_contents, dove il ciclo usa NUMERALS[level] per i nodi che crea scendendo e chiama expand() su ogni nodo esistente che attraversa. Esegui lo script di chi ha segnalato, che usa MarkdownViewer e Tree, e confronta le etichette e i messaggi Tree.NodeExpanded con l'output atteso nell'issue. Il lavoro è completo quando il nodo del livello saltato mostra il numerale corretto e ogni nodo viene espanso una sola volta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Textual's widgets.
When a document skips a heading level (# then ###), MarkdownTableOfContents.rebuild_table_of_contents adds a node for the missing level. That node is labelled with the numeral of the heading being added, not of its own level, so a level-2 node reads "Ⅲ" next to real level-2 headings that read "Ⅱ". Also, every heading under a node calls expand() on it again, so a Tree with several sub-headings posts Tree.NodeExpanded for the same node several times.
import asyncio
import textual
from textual.app import App, ComposeResult
from textual.widgets import MarkdownViewer, Tree
DOCUMENT = """\
# One
### One point one point one
#### Deeper
## Two
"""
class TocApp(App):
def compose(self) -> ComposeResult:
yield MarkdownViewer(DOCUMENT)
def on_tree_node_expanded(self, event: Tree.NodeExpanded) -> None:
self.expanded.append(str(event.node.label))
expanded: list[str] = []
def dump(node, depth=0):
for child in node.children:
print(" " * depth + str(child.label), "" if child.allow_expand else "(leaf)")
dump(child, depth + 1)
async def main() -> None:
app = TocApp()
async with app.run_test() as pilot:
await pilot.pause()
tree = app.query_one(Tree)
dump(tree.root)
print("NodeExpanded messages:", app.expanded)
print("Textual", textual.__version__)
asyncio.run(main())
Output on Textual 8.2.7 (main at 5e5b7ef is the same):
Textual 8.2.7
Ⅰ One
Ⅲ
Ⅲ One point one point one
Ⅳ Deeper (leaf)
Ⅱ Two (leaf)
NodeExpanded messages: ['Ⅰ One', 'Ⅰ One', 'Ⅲ', 'Ⅲ One point one point one', 'Ⅰ One']
Expected: the node for the missing level reads "Ⅱ", like "Ⅱ Two" beside it, and each node is expanded once: NodeExpanded messages: ['Ⅰ One', 'Ⅲ One point one point one'].
The loop in rebuild_table_of_contents uses NUMERALS[level] (the new heading's level) for the nodes it creates on the way down, and calls node.expand() and sets allow_expand on every existing node it passes. I'm happy to send a PR.
- Lingua principale
- Python
- Stelle
- 37.7k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/textual
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6790 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6787 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6782 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Textualize/textual#6778 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/textual#6777 · 1 commento ·
Tutte le issue di Textualize/textual
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mohanraj00/entelos#200 ·
I maintainer di solito rispondono entro 1 giorno
-
Dead url in mise.tomlAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
-
sweep
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
bketelsen/truenas-mcp#77 ·
I maintainer di solito rispondono entro 1 giorno
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
sandbox-quantum/switch#2163 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
openedx/xblock-lti-consumer#765 ·
I maintainer di solito rispondono entro 1 giorno