[office/klevernotes] src/logic/parser: Enable internal links to headers (like "#example") in preview

Louis Schul <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 97c1766c4256919f5cd49c2c2b7cc6535ff1bf24 by Louis Schul, on behalf of Igor Mironchik.
Committed on 17/08/2026 at 07:09.
Pushed by louis-schul into branch 'master'.

Enable internal links to headers (like "#example") in preview

BUG: 521341

M  +4    -48   src/logic/parser/renderer.cpp

https://invent.kde.org/office/klevernotes/-/commit/97c1766c4256919f5cd49c2c2b7cc6535ff1bf24

diff --git a/src/logic/parser/renderer.cpp b/src/logic/parser/renderer.cpp
index 2e254319..c366448d 100644
--- a/src/logic/parser/renderer.cpp
+++ b/src/logic/parser/renderer.cpp
@@ -98,60 +98,16 @@ void Renderer::onHeading(
 
 void Renderer::onLink(MD::Link *l)
 {
-    QString url = l->url();
-
     if (m_pluginHelper) {
-        const QString wikilinkDelim = QStringLiteral("@HEADER@");
-        if (url.contains(wikilinkDelim)) {
-            auto linkedNoteInfo = url.split(wikilinkDelim);
+        static const QString wikilinkDelim = QStringLiteral("@HEADER@");
+        if (l->url().contains(wikilinkDelim)) {
+            auto linkedNoteInfo = l->url().split(wikilinkDelim);
             linkedNoteInfo.append(l->text());
             m_pluginHelper->mapperParserUtils()->addToLinkedNoteInfos(linkedNoteInfo);
         }
     }
 
-    const auto lit = this->m_doc->labeledLinks().find(url);
-
-    if (lit != this->m_doc->labeledLinks().cend())
-        url = lit.value()->url();
-
-    if (std::find(this->m_anchors.cbegin(), this->m_anchors.cend(), url) != this->m_anchors.cend())
-        url = QStringLiteral("#") + url;
-    else if (url.startsWith(QStringLiteral("#")) && this->m_doc->labeledHeadings().find(url) == this->m_doc->labeledHeadings().cend()) {
-        auto path = static_cast<MD::Anchor *>(this->m_doc->items().at(0).get())->label();
-        const auto sp = path.lastIndexOf(QStringLiteral("/"));
-        path.remove(sp, path.length() - sp);
-        const auto p = url.indexOf(path) - 1;
-        url.remove(p, url.length() - p);
-    }
-
-    if (!m_justCollectFootnoteRefs) {
-        openStyle(l->openStyles());
-
-        m_html.push_back(QStringLiteral("<a href=\""));
-        m_html.push_back(url);
-        m_html.push_back(QStringLiteral("\">"));
-    }
-    if (l->p() && !l->p()->isEmpty()) {
-        onParagraph(l->p().get(), false);
-    } else if (!l->img()->isEmpty()) {
-        if (!m_justCollectFootnoteRefs) {
-            onImage(l->img().get());
-        }
-    } else if (!l->text().isEmpty()) {
-        if (!m_justCollectFootnoteRefs) {
-            m_html.push_back(prepareTextForHtml(l->text()));
-        }
-    } else {
-        if (!m_justCollectFootnoteRefs) {
-            m_html.push_back(prepareTextForHtml(l->url()));
-        }
-    }
-
-    if (!m_justCollectFootnoteRefs) {
-        m_html.push_back(QStringLiteral("</a>"));
-
-        closeStyle(l->closeStyles());
-    }
+    MD::details::HtmlVisitor::onLink(l);
 }
 
 void Renderer::onImage(MD::Image *i)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.