Addon Manager: Strip some HTML tags from Markdown
This commit is contained in:
committed by
Yorik van Havre
parent
4e3467ae5e
commit
ee50a0474f
@@ -20,6 +20,7 @@
|
||||
# * <https://www.gnu.org/licenses/>. *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
import re
|
||||
|
||||
import FreeCAD
|
||||
|
||||
@@ -65,7 +66,8 @@ class WidgetReadmeBrowser(QtWidgets.QTextBrowser):
|
||||
have native markdown support. Lacking that, plaintext is displayed."""
|
||||
geometry = self.geometry()
|
||||
if hasattr(super(), "setMarkdown"):
|
||||
super().setMarkdown(md)
|
||||
|
||||
super().setMarkdown(self._clean_markdown(md))
|
||||
else:
|
||||
try:
|
||||
import markdown
|
||||
@@ -79,6 +81,16 @@ class WidgetReadmeBrowser(QtWidgets.QTextBrowser):
|
||||
)
|
||||
self.setGeometry(geometry)
|
||||
|
||||
def _clean_markdown(self, md: str):
|
||||
# Remove some HTML tags (for now just img and br, which are the most common offenders that break rendering)
|
||||
br_re = re.compile(r"<br\s*/?>")
|
||||
img_re = re.compile(r"<img\s.*?src=(?:'|\")([^'\">]+)(?:'|\").*?\/?>")
|
||||
|
||||
cleaned = br_re.sub("\n", md)
|
||||
cleaned = img_re.sub("[html tag removed]", cleaned)
|
||||
|
||||
return cleaned
|
||||
|
||||
def set_resource(self, resource_url: str, image: Optional[QtGui.QImage]):
|
||||
"""Once a resource has been fetched (or the fetch has failed), this method should be used to inform the widget
|
||||
that the resource has been loaded. Note that the incoming image is scaled to 97% of the widget width if it is
|
||||
|
||||
Reference in New Issue
Block a user