PDA

View Full Version : qlmanage and html files: How can I jump to a location/anchor in a html file




gregor.hoch
Apr 16, 2012, 01:55 AM
I am trying to use qlmanage, a terminal command to perform Quick Look actions, to open a html file and jump to a specific location in the file (anchor). In the browser, I would just use file:///[LOCATION]/test.html#jump but that does not work with qlmanage. Below is an example that works with qlmanage and some attempts to jump to the anchor, which are not working.

Note that Quick Look itself can jump to anchors in html files. When I open links from emails with anchors, quick look jumps to the correct location. Hovering over the link in an email shows this:
'x-apple-ql-file:///[LOCATION]/test.html?/[LOCATION]/#jump

Thanks!



Works

/usr/bin/qlmanage -p '~/Desktop/test.html'

Doesn't work

/usr/bin/qlmanage -p '~/Desktop/test.html#jump'
/usr/bin/qlmanage -p 'file:///[LOCATION]/test.html#jump'


Example HTML File

<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="chrome=1"></head>

<body>
<h1>Heading</h1>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p id="jump">
jump here
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>

</body>



samwich
Apr 16, 2012, 10:39 AM
To jump to an anchor in an HTML page you do not give an element an id with the anchor name. Instead you use <a name="jump">Jump here</a>

Then you can use the URL http://www.example.com/page.html#jump

http://www.w3schools.com/html/html_links.asp

gregor.hoch
Apr 16, 2012, 11:08 AM
Thanks but that's not the problem. As far as I know, only very old user agents do not support id anchors and quicklook in Mail certainly handles id anchors fine. See the discussion here:
http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id

In any case, qlmanage has the same problem with name anchors.

chown33
Apr 16, 2012, 12:43 PM
Hovering over the link in an email shows this:
'x-apple-ql-file:///[LOCATION]/test.html?/[LOCATION]/#jump

Doesn't work

/usr/bin/qlmanage -p '~/Desktop/test.html#jump'
/usr/bin/qlmanage -p 'file:///[LOCATION]/test.html#jump'


Your non-working examples don't follow the same syntax as your email example. I've hilited the difference in red.

I'm pointing this out for logical reasons, not because it works.


When I try the first example command, I get multiple warnings and errors output. They all say there's no such file. This is after creating the test.html file on my Desktop, and after running the posted command that works. (As run on Snow Leopard.)

Did you get any error messages? What did they say?


Your example HTML file is also missing a <!DOCTYPE>, and the <html> tags. My test file had them.

gregor.hoch
Apr 16, 2012, 05:19 PM
I am getting the same error message. Something like file not found.

I guess I double pasted with the highlighted syntax example. Sorry for that. But I never got 'x-apple-ql-file' to work with qlmanage anyway.

Thanks for your trials!

chown33
Apr 16, 2012, 06:24 PM
I am getting the same error message. Something like file not found.

When posting questions, it's always a good idea to mention error messages. It's an even better idea to post the actual text of the complete error message.
http://www.mikeash.com/getting_answers.html


I'll also point out that qlmanage isn't really "a terminal command to perform Quick Look actions". It's a debugging and management tool. That's what it says in its man page. It should also be obvious because the QL window that shows the preview has the word "DEBUG" in its title.

I mention this because it's quite possible you'll have to write a command-line tool in order to get what you want. To that end, you should probably start by reading the Quick Look Programming Guide.

Just because a tool can be used for X doesn't mean it was designed for X, nor that it can accomplish all possible variations on X.