Bug 421163 - Internal links in markdown documents work incorrectly
Summary: Internal links in markdown documents work incorrectly
Status: RESOLVED FIXED
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: 20.04.0
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-07 17:02 UTC by Vaso
Modified: 2020-05-14 19:24 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 1.11.0


Attachments
attaching the file (213 bytes, text/markdown)
2020-05-09 21:38 UTC, Albert Astals Cid
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vaso 2020-05-07 17:02:03 UTC
SUMMARY
When click internal links in markdown document, Okular open location of this document in Dolphin.

STEPS TO REPRODUCE

Create simple MD document with such content:

------------------------>8--------------------
# TEST LINKS
1. [External link to web site](https://kde.org/)
2. [Local link to file](/etc/hosts)
3. [Internal link to chapter](#Chapter)
<div style="page-break-after: always;">
---end-of-page---
</div>
# Chapter
------------------------8<--------------------
then open it in Okular

OBSERVED RESULT
First two links open web-site and local file respectively as expected.
Third one (internal link) Okular processes as a path to directory where this document locates and launches Dolphin.

EXPECTED RESULT
Okular have to follow to the second page of the document, where the target (Chapter) locates.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Ubuntu 20.04 LTS [linux version 5.4.0-29-generic x86_64]
KDE Plasma Version: 5.18.4
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 9.3.0) on "xcb"

ADDITIONAL INFORMATION
…
Comment 1 Albert Astals Cid 2020-05-09 21:38:25 UTC
Created attachment 128313 [details]
attaching the file

Next time attach the file instead of making us do the work to create it, the 5 seconds you save us doing this work, it's 5 seconds we can invest in actually investigating the issue
Comment 2 Albert Astals Cid 2020-05-09 22:00:09 UTC
The HTML we get back from discount (the Markdown library we use) is

<h1>TEST LINKS</h1>\n\n<ol>\n<li><a href=\"https://kde.org/\">External link to web site</a></li>\n<li><a href=\"/etc/hosts\">Local link to file</a></li>\n<li><a href=\"#Chapter\">Internal link to chapter</a></li>\n</ol>\n\n\n<div style=\"page-break-after: always;\">\n---end-of-page---\n</div>\n\n\n<h1>Chapter</h1>

I'm not convinced that at this point we can actually do anything to figure out that <a href=\"#Chapter\"> refers to <h1>Chapter</h1>

I'll ask the discount author
Comment 3 Albert Astals Cid 2020-05-12 21:21:13 UTC
ok, using the MKD_TOC flag in discount gives us 

<a name=\"TEST-LINKS\"></a>\n<h1>TEST LINKS</h1>\n\n<ol>\n<li><a href=\"https://kde.org/\">External link to web site</a></li>\n<li><a href=\"/etc/hosts\">Local link to file</a></li>\n<li><a href=\"#Chapter\">Internal link to chapter</a></li>\n</ol>\n\n\n<div style=\"page-break-after: always;\">\n---end-of-page---\n</div>\n\n\n<a name=\"Chapter\"></a>\n<h1>Chapter</h1>

which gives us something to work with
Comment 4 Albert Astals Cid 2020-05-12 22:21:12 UTC
https://invent.kde.org/kde/okular/-/merge_requests/164
Comment 5 Nate Graham 2020-05-13 15:40:31 UTC
Will be fixed by https://invent.kde.org/kde/okular/-/merge_requests/164
Comment 6 Albert Astals Cid 2020-05-13 20:11:17 UTC
Git commit b1c02b7e79c8be1716ddba73d92d5792032821c6 by Albert Astals Cid.
Committed on 12/05/2020 at 22:21.
Pushed by aacid into branch 'master'.

Markdown: Support internal links

When processing the <a> elements, store in two maps those that contain
an href="#Something" and those with name="Something" then once we've
processed them all, go over the first map trying to find itself in the
second

M  +33   -10   generators/markdown/converter.cpp
M  +3    -2    generators/markdown/converter.h

https://invent.kde.org/kde/okular/commit/b1c02b7e79c8be1716ddba73d92d5792032821c6