Repository navigation
Export highlights: export backlinks to markdown - #14233
Conversation
| end | ||
|
|
||
| -- Check if it is a link to a local file | ||
| local linked_filename = link_url:gsub("^file:(//)?", "") -- remove local file protocol if any |
There was a problem hiding this comment.
I think I've seen file:path without the // (ie. file:/mnt/onboard/), may be in other contexts/browsers, so it feels good if we could support file:///mnt/... and file:/mnt/... even if some URI specs say // is required.
So the presence of (//)? in the original code, which seems to have been removed.
There was a problem hiding this comment.
Will do (the removed regexp doesn't work anyway).
| if pn_xp then | ||
| caller_callback = function(ui) | ||
| ui.link:addCurrentLocationToStack() | ||
| if ui.rolling then | ||
| ui.rolling:onGotoXPointer(pn_xp, pn_xp) | ||
| else | ||
| pn_xp = tonumber(pn_xp) | ||
| if pn_xp then | ||
| ui.paging:onGotoPage(pn_xp) | ||
| end | ||
| end | ||
| end | ||
| else | ||
| linked_filename = ffiutil.joinPath(self.document_dir, linked_filename) -- get full path |
There was a problem hiding this comment.
No need for this joinPath in the case of ?pn_xp ?
There was a problem hiding this comment.
You've supported relative links:
koreader/frontend/apps/reader/modules/readerlink.lua
Lines 126 to 128 in d0abd59
Exporter adds full paths (
book.file):There was a problem hiding this comment.
You've supported relative links:
OK to keep supporting relative links.
But I can imagine a user/script using your new trick/api and creating local links in home made HTML files using relative links, href="other.pdf?pn_xp=12".
(Your exporter may not be the only thing ending up using this new pn_xp feature you're adding, so it would be good to keep supporting relative links in this case.)
There was a problem hiding this comment.
I was going to distinguish abs/rel paths by the leading slash, but allowing various number of slashes in the prefix file:///, how can we do this?
There was a problem hiding this comment.
Dunno if the following is correct, but after 30s of thinking:
file:mnt/everest (impossible with proper file://) => relative
file:/mnt/everest (impossible with proper file://) => absolute
file://mnt/everest (having // means it's proper file://) => relative
file:///mnt/everest (having // means it's proper file://) => absolute
There was a problem hiding this comment.
The first two seem wrong but if they occur in the wild I suppose it doesn't hurt.
| else | ||
| UIManager:show(InfoMessage:new{ | ||
| text = T(_("Link to unsupported local file:\n%1"), BD.url(link_url)), | ||
| }) |
There was a problem hiding this comment.
This different and more informative message ("unsupported local file") is gone? Users will get the more generic and less informative Invalid or external link ?
There was a problem hiding this comment.
ReaderUI will show "File is not supported".
| covers_fullscreen = true, -- hint for UIManager:_repaint() | ||
| document = document, | ||
| reloading = self.reloading, | ||
| caller_callback = self.caller_callback, |
There was a problem hiding this comment.
May be another more explicite name ? caller_callback works when we call a function, but here, we will instantiate an object, so a more precise name like after_open_callback or post_postReaderReady_callback :) would be clearer.
There was a problem hiding this comment.
I'm good with after_open_callback.
| linked_filename = ffiutil.joinPath(self.document_dir, linked_filename) -- get full path | ||
| if anchor then | ||
| local count | ||
| pn_xp, count = anchor:gsub("^?pn_xp=", "") -- page number or xpointer |
There was a problem hiding this comment.
Are we all OK with this syntax ?
No real better idea.
I would have gone with a #something, but it would not be a real HTML id= (might be good to also support id=, but with EPUBs with multiple fragments, there may be multiple ids with the same name, so no obvious solution.
Are we ok with the name pn_xp (koreader technical) ? Or should it be generic/abstracted as ?pos= ?
Just asking for discussion, as we are defining some "external api" for the future we won't be able to change without breaking some other app or user scripts that will use it :)
There was a problem hiding this comment.
Or should it be generic/abstracted as
?pos=?
Totally agree with that.
I followed the code name, but in the md file it definitely should be more readable.
I'm okay with pos.
There was a problem hiding this comment.
Could you choose the formatting for highlights in Blockquotes? It looks better aesthetically...
|
Changes: |
| if linked_filename:find("?") then -- remove any query string (including any following anchor) | ||
| linked_filename, anchor = linked_filename:match("^(.-)(%?.*)$") | ||
| elseif linked_filename:find("#") then -- remove any anchor | ||
| linked_filename, anchor = linked_filename:match("^(.-)(#.*)$") | ||
| end |
There was a problem hiding this comment.
So, document.epub#pos=blah will work as well as document.epub?pos=blah.
Dunno if we should allowing that, or not and just handle ?pos= (so #pos=blah could go to the first <div id="pos=blah"> in the epub if one day we want to support that).
There was a problem hiding this comment.
Changes: handle bookmark position in the query string only, not in #.
|
Could you choose the formatting for highlights in Blockquotes? It looks better aesthetically... |
Setting:

Highlight in the book:

Exported markdown document:

Closes #12955.
This change is