Skip to content

Text

Text shows the latest markdown of its source.

import dachshund
from dachshund.widgets import Text

with dachshund.row():
    dachshund.add(Text("changelog", title="Release Notes"))
dachshund.emit("changelog", value="**v1.2** fixed the thing.")

dachshund.widgets.text.text.Text dataclass

Text(name, *, source='', title=None, actions=list(), action_args=dict(), persist=False, y='value')

Bases: PersistableWidget

The latest markdown of its source, rendered to sanitized HTML.

Raw HTML in the markdown is escaped, and only http, https and mailto links are kept.

Example

with dachshund.row():
    dachshund.add(Text("changelog", title="Release Notes"))
dachshund.emit("changelog", value="**v1.2** fixed the thing.")

Options

  • y (str) - The field read. Defaults to "value".
  • persist (bool) - Keeps the latest text across restarts. Needs the dashboard's storage. Defaults to False.

y class-attribute instance-attribute

y = 'value'

kept class-attribute instance-attribute

kept = field(default=None, init=False, repr=False, compare=False)

type class-attribute

type = 'text'

op class-attribute

op = 'replace'

script class-attribute

script = Path(__file__).parent / 'text.js'

style class-attribute

style = Path(__file__).parent / 'text.css'

render

render(events)

The most recent markdown of y, rendered to HTML.

A persisting widget reads its own kept text instead, since that covers more than whatever events are still around to re-read.

Source code in dachshund/widgets/text/text.py
45
46
47
48
49
50
51
52
53
54
55
56
def render(self, events: Sequence[Event]) -> dict[str, Any]:
    """The most recent markdown of `y`, rendered to HTML.

    A persisting widget reads its own kept text instead, since that
    covers more than whatever events are still around to re-read.
    """
    if self.persist:
        text = self.kept["value"] if self.kept else None
    else:
        text = self._read(events[-1]) if events else None

    return {"html": render_markdown(text) if text is not None else None}

accumulate

accumulate(event)

Keep the latest markdown of y.

Source code in dachshund/widgets/text/text.py
58
59
60
61
62
63
64
65
def accumulate(self, event: Event) -> None:
    """Keep the latest markdown of `y`."""
    text = self._read(event)

    if text is None:
        return

    self.kept = {"value": text}

snapshot

snapshot()

The kept text.

Source code in dachshund/widgets/text/text.py
67
68
69
def snapshot(self) -> dict[str, Any]:
    """The kept text."""
    return self.kept or {}

restore

restore(data)

Pick up where the last persisted snapshot left off.

Source code in dachshund/widgets/text/text.py
71
72
73
def restore(self, data: dict[str, Any]) -> None:
    """Pick up where the last persisted snapshot left off."""
    self.kept = data