Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

links to empty local anchors not working #1554

Closed
jdpurcell opened this issue Feb 20, 2014 · 5 comments
Closed

links to empty local anchors not working #1554

jdpurcell opened this issue Feb 20, 2014 · 5 comments
Milestone

Comments

@jdpurcell
Copy link

With 0.11.0 it was possible to use anchors to jump to different pages. With 0.12.x this is no longer working. I tested with the following HTML:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test</title>
</head>
<body>
<h2>Contents</h2>
<a href="#section1">Section 1</a><br>
<a href="#section2">Section 2</a><br>
<a href="#section3">Section 3</a>
<div style="height: 2000px;"></div>
<div style="page-break-after: always;"></div>
<a name="section1"></a><h2>Section 1</h2>Content...
<div style="height: 2000px;"></div>
<div style="page-break-after: always;"></div>
<a name="section2"></a><h2>Section 2</h2>Content...
<div style="height: 2000px;"></div>
<div style="page-break-after: always;"></div>
<a name="section3"></a><h2>Section 3</h2>Content...
<div style="height: 2000px;"></div>
</body>
</html>
@ashkulz ashkulz added this to the 0.12.1 milestone Feb 21, 2014
@mn4367
Copy link
Contributor

mn4367 commented Feb 21, 2014

Interesting. But your HTML is is a bit unusual. <h2 name="section2">Section 2</h2>Content... instead of <a name="section2"></a><h2>Section 2</h2>Content... works (not on OS X, that's already another issue). So it seems that linking to empty <a>-elements does no longer work (which isn't too critical IMO but nevertheless a case of regression).

@ashkulz
Copy link
Member

ashkulz commented Mar 3, 2014

I investigated this in detail, and it appears that WebKit does not generate empty anchors in the render tree. Due to this, the element location is detected as (0, 0) with size 0x0 ie. the first page. If you put it any content (even a &nbsp;) then it gets rendered properly. This may be a change in the underlying QT since the upgrade to 4.8.5.

Debugging of locations with sample page above:
ANCHOR NAME: test.html#section1
PAGE: 1 LOC:(0,0) SIZE:0x0
-------
ANCHOR NAME: test.html#section3
PAGE: 1 LOC:(0,0) SIZE:0x0
-------
ANCHOR NAME: test.html#section2
PAGE: 5 LOC:(0,6) SIZE:734x21

With a single &nbsp; inserted in section1:
ANCHOR NAME: test.html#section3
PAGE: 1 LOC:(0,0) SIZE:0x0
-------
ANCHOR NAME: test.html#section1
PAGE: 3 LOC:(0,6) SIZE:3x15
-------
ANCHOR NAME: test.html#section2
PAGE: 5 LOC:(0,6) SIZE:734x21

I'll add documentation in the upcoming 0.12.1 release that this does not work, you have to give an ID/name to the visible element for it to be linked properly.

@textractor
Copy link

I just ran into that problem and found this solution. So just to give my concrete example ... this did not work as an anchor:

<a id="123"></a>

But this did:

<p id="123"></p>

@daytonb
Copy link

daytonb commented May 7, 2015

What tool did you use to produce the debugging output you wrote in your Mar 3, 2014 comment above?

@ashkulz
Copy link
Member

ashkulz commented May 8, 2015

@daytonb: I used printf statements in the source code, didn't save the patch as it was one-off 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

5 participants