textual icon indicating copy to clipboard operation
textual copied to clipboard

Content.from_markup rejects explicit [/@click] closing tag accepted by Rich

Open Timotty opened this issue 1 month ago • 1 comments

Have you checked closed issues? Yes. Searched open and closed issues and PRs for @click, MarkupError, closing tags, and meta tags. #4248 concerns malformed opening/action syntax, and #6155/#6157 concern incomplete closing tags; neither reproduces this case.

Have you checked against the most recent version of Textual? Yes: PyPI currently lists 8.2.8. Reproduced with Textual 8.2.8 installed editable from current main, commit 5e5b7ef58b8c5572c13a3ff9027d756623661495.

The bug

An explicit closing tag [/@click] is accepted by Rich but raises MarkupError in Textual's content parser. The automatic closing tag [/] and explicit [/@click=] both work in Textual.

Complete minimal example

from rich.text import Text
from textual.content import Content

markup = "[@click=app.bell]bell[/@click]"
print("Rich:", Text.from_markup(markup).plain)
try:
    print("Textual:", Content.from_markup(markup).plain)
except Exception as error:
    print("Textual:", type(error).__name__, str(error))
print("Textual automatic close:", Content.from_markup("[@click=app.bell]bell[/]").plain)

Actual output:

Rich: bell
Textual: MarkupError closing tag '[/@click]' does not match any open tag
Textual automatic close: bell

Expected behavior

If named meta closing tags are intended to follow Rich's syntax, [/@click] should close [@click=app.bell] and produce bell. If this is an intentional difference, documenting it would clarify which syntax is supported.

Investigation and proposed direction

In src/textual/style.py:232-235, Style.markup_tag normalizes the opening meta tag to @click=. In src/textual/style.py:337-350, the bare closing tag normalizes to @click. The equality check in src/textual/markup.py:416-429 therefore fails.

Could @willmcgugan confirm whether supporting the bare meta closing name is desirable? A focused normalization change with regression tests for the three closing forms could address this. No PR has been opened pending approval under the project's AI policy.

Environment

  • Windows, CPython 3.14.6
  • Textual 8.2.8 (editable, main commit above)
  • Rich 15.0.0
  • Reproduction uses pure API calls; no terminal rendering required.

Disclosure: this report and its reproduction were prepared and verified with AI assistance (OpenCode, GPT-5.6 Sol).

Timotty avatar Oct 11 '26 09:10 Timotty

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This project is developed and maintained by Will McGugan. Consider sponsoring Will's work on this project (and others).

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Oct 11 '26 09:10 github-actions[bot]