From 3ef87793157eb6beaf16cb41d41ceec44d4d6789 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sat, 22 Feb 2020 01:38:25 +0100 Subject: [PATCH] Fix in-article links These got broken since they were linking to just the article file as if it were still in the same folder. Apparently we did test the image links, but not the article links. --- CuraSettingsGuide.py | 2 +- QtMarkdownRenderer.py | 4 ++++ resources/qml/ArticleText.qml | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CuraSettingsGuide.py b/CuraSettingsGuide.py index 825c49c00..34d3720b3 100644 --- a/CuraSettingsGuide.py +++ b/CuraSettingsGuide.py @@ -315,7 +315,7 @@ def isArticleFile(self, filename: str) -> bool: :return: True if the file name is the file name of an existing article, or False if it isn't. """ - return os.path.exists(os.path.join(os.path.dirname(__file__), "resources", "articles", filename)) + return os.path.exists(filename) @pyqtProperty(QObject, constant=True) def containerStack(self) -> Optional[ContainerStack]: diff --git a/QtMarkdownRenderer.py b/QtMarkdownRenderer.py index a6fff2bda..d303eb8b5 100644 --- a/QtMarkdownRenderer.py +++ b/QtMarkdownRenderer.py @@ -43,6 +43,10 @@ def link(self, link, title, text): """ link = mistune.escape_link(link) link_colour = UM.Qt.Bindings.Theme.Theme.getInstance().getColor("text_link").name() + + if "://" not in link and link.endswith(".md"): # Link to a different article. + link = os.path.join(self._images_path, link) + if not title: return "{text}".format(colour=link_colour, link=link, text=text) title = mistune.escape(title, quote=True) diff --git a/resources/qml/ArticleText.qml b/resources/qml/ArticleText.qml index 6b5deadd4..650c744e3 100644 --- a/resources/qml/ArticleText.qml +++ b/resources/qml/ArticleText.qml @@ -16,7 +16,8 @@ Text { onLinkActivated: { if(manager.isArticleFile(link)) { - var article_id = link.replace(/\.[^/.]*$/, "") + var article_id = link.replace(/\.[^/.]*$/, ""); + article_id = article_id.replace(/.*\//, ""); manager.setSelectedArticleId(article_id); } else { Qt.openUrlExternally(link);