Skip to content

[BUG] Changing Background style via code does not propagate properly into Markdown Widget #6235

@Zaloog

Description

@Zaloog

The bug

Changing the background of a Markdown Widget dynamically via code is not changing the background of all Markdown Segments accordingly. Also see example screenshot, where the code segment is still the previous color.

Changing the background via tcss works properly.

MRE:

from textual.app import App, ComposeResult
from textual.widgets import Markdown, Select

EXAMPLE_MARKDOWN = """\
# Markdown Viewer

This is an example of Textual's `MarkdownViewer` widget.


## Features

Markdown syntax and extensions are supported.

- Typography *emphasis*, **strong**, `inline code` etc.
- Headers

## Tables

Tables are displayed in a DataTable widget.

| Name            | Type   | Default | Description                        |
| --------------- | ------ | ------- | ---------------------------------- |
| `show_header`   | `bool` | `True`  | Show the table header              |
| `fixed_rows`    | `int`  | `0`     | Number of fixed rows               |


## Code Blocks

Code blocks are syntax highlighted.


"""


class MarkdownExampleApp(App):
    def compose(self) -> ComposeResult:
        yield Select.from_values(["red", "green", "blue"])
        markdown_viewer = Markdown(EXAMPLE_MARKDOWN)
        yield markdown_viewer

    def on_select_changed(self, event: Select.Changed):
        self.query_one(Markdown).styles.background = event.value

if __name__ == "__main__":
    app = MarkdownExampleApp()
    app.run()
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions