https://bugs.kde.org/show_bug.cgi?id=521341

            Bug ID: 521341
           Summary: Enable internal links to headers (like "#example") in
                    preview
    Classification: Applications
           Product: KleverNotes
      Version First 1.3.1
       Reported In:
          Platform: Other
                OS: All
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: Markdown parser
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

DESCRIPTION
GitHub in Markdown often use internal links to headings, like [internal
link](#example), that should point to heading "# Example". Method "void
Renderer::onLink(MD::Link *l)" was copy-pasted from older md4qt library, and
there were issue, so such links doesn't work in KleverNotes now.

In your code you have

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);
    }

That should be modified to 

    } else if (url.startsWith(QStringLiteral("#"))) {
        const auto it = this->m_doc->labeledHeadings().find(url);

        if (it == this->m_doc->labeledHeadings().cend()) {
            auto path = static_cast<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);
        } else {
            url = (*it)->label();
        }
    }

Look at missing 

        } else {
            url = (*it)->label();
        }

This add on fixes internal links in Web preview.

Or even better, don't fully copy-paste, but reuse code like:

void Renderer::onLink(MD::Link *l)
{
   // Do you stuff here
   // Possibly do return....

   MD::details::HtmlVisitor::onLink(l);
}

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to