from PyQt6.QtWidgets import QTextBrowser from PyQt6.QtGui import QDesktopServices from ...resources import get_resource_path import logging log = logging.getLogger(__name__) class MarkdownView(QTextBrowser): def __init__(self, path): super().__init__() self.setReadOnly(True) self.filepath = get_resource_path(path) try: with open(self.filepath, "r") as file: content = file.read() self.setMarkdown(content) except FileNotFoundError: log.error(f"File not found: {self.filepath}") self.setMarkdown(f"## File not found\n`{self.filepath}`") # open links with the OS web browser self.anchorClicked.connect(QDesktopServices.openUrl) # dont follow links self.setOpenLinks(False)