Skip to content

MarkdownItemDelegate

Base classes

Name Children Inherits
BaseMarkupDelegate
prettyqt.itemdelegates.htmlitemdelegate

⋔ Inheritance diagram

graph TD
  544275249["itemdelegates.MarkdownItemDelegate"]
  1891848998["itemdelegates.BaseMarkupDelegate"]
  4109708588["widgets.StyledItemDelegate"]
  3153451512["widgets.AbstractItemDelegateMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  3599391368["QtWidgets.QStyledItemDelegate"]
  475576970["QtWidgets.QAbstractItemDelegate"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  1891848998 --> 544275249
  4109708588 --> 1891848998
  3153451512 --> 4109708588
  3227531497 --> 3153451512
  2751680898 --> 3227531497
  2751680898 --> 3153451512
  3599391368 --> 4109708588
  475576970 --> 3599391368
  3984060476 --> 475576970
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: BaseMarkupDelegate

Delegate do display Markdown text.

Source code in prettyqt/itemdelegates/htmlitemdelegate.py
class MarkdownItemDelegate(BaseMarkupDelegate):
    """Delegate do display Markdown text."""

    ID = "markdown"

    def __init__(self, *args, mode: str = "github", **kwargs):
        super().__init__(*args, **kwargs)
        self._mode = mode

    def set_text(self, text: str):
        Feat = self.doc.MarkdownFeature  # noqa: N806
        match self._mode:
            case "no_html":
                self.doc.setMarkdown(text, Feat.MarkdownNoHTML)
            case "commonmark":
                self.doc.setMarkdown(text, Feat.MarkdownDialectCommonMark)
            case "github" | "":
                self.doc.setMarkdown(text, Feat.MarkdownDialectGitHub)
            case _:
                raise ValueError(self._mode)

    def get_markup_mode(self) -> str:
        return self._mode

    def set_markup_mode(self, mode: str):
        self._mode = mode

    markup_mode = core.Property(
        str,
        get_markup_mode,
        set_markup_mode,
        doc="Which markdown dialect to use.",
    )

:fa-brands-github: Show source on GitHub