mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Insert hyperlink: Add a few more variables for the link template: _SOURCE_FILENAME_, _DEST_FILENAME_ and _ANCHOR_
This commit is contained in:
parent
e190bdaf21
commit
8ef42dafc5
@ -898,7 +898,7 @@ class Boss(QObject):
|
|||||||
self.commit_all_editors_to_container()
|
self.commit_all_editors_to_container()
|
||||||
d = InsertLink(current_container(), edname, initial_text=ed.get_smart_selection(), parent=self.gui)
|
d = InsertLink(current_container(), edname, initial_text=ed.get_smart_selection(), parent=self.gui)
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
ed.insert_hyperlink(d.href, d.text, template=d.template)
|
ed.insert_hyperlink(d.href, d.text, template=d.rendered_template)
|
||||||
elif action[0] == 'insert_tag':
|
elif action[0] == 'insert_tag':
|
||||||
d = InsertTag(parent=self.gui)
|
d = InsertTag(parent=self.gui)
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
|
@ -675,6 +675,13 @@ class InsertLink(Dialog):
|
|||||||
tl.addRow(_('Tem&plate:'), t)
|
tl.addRow(_('Tem&plate:'), t)
|
||||||
from calibre.gui2.tweak_book.editor.smarts.html import DEFAULT_LINK_TEMPLATE
|
from calibre.gui2.tweak_book.editor.smarts.html import DEFAULT_LINK_TEMPLATE
|
||||||
t.setText(tprefs.get('insert-hyperlink-template', None) or DEFAULT_LINK_TEMPLATE)
|
t.setText(tprefs.get('insert-hyperlink-template', None) or DEFAULT_LINK_TEMPLATE)
|
||||||
|
t.setToolTip('<p>' + _('''
|
||||||
|
The template to use for generating the link. In addition to {0} and {1}
|
||||||
|
you can also use {2}, {3} and {4} variables
|
||||||
|
in the template, they will be replaced by the source filename, the destination
|
||||||
|
filename and the anchor, respectively.
|
||||||
|
''').format(
|
||||||
|
'_TITLE_', '_TARGET', '_SOURCE_FILENAME_', '_DEST_FILENAME_', '_ANCHOR_'))
|
||||||
|
|
||||||
l.addWidget(self.bb)
|
l.addWidget(self.bb)
|
||||||
|
|
||||||
@ -740,6 +747,22 @@ class InsertLink(Dialog):
|
|||||||
def template(self):
|
def template(self):
|
||||||
return self.template_edit.text().strip() or None
|
return self.template_edit.text().strip() or None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rendered_template(self):
|
||||||
|
ans = self.template
|
||||||
|
if ans:
|
||||||
|
target = self.href
|
||||||
|
frag = target.partition('#')[-1]
|
||||||
|
if target.startswith('#'):
|
||||||
|
target = ''
|
||||||
|
else:
|
||||||
|
target = target.split('#', 1)[0]
|
||||||
|
target = self.container.href_to_name(target)
|
||||||
|
ans = ans.replace('_SOURCE_FILENAME_', self.source_name)
|
||||||
|
ans = ans.replace('_DEST_FILENAME_', target)
|
||||||
|
ans = ans.replace('_ANCHOR_', frag)
|
||||||
|
return ans
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def test(cls):
|
def test(cls):
|
||||||
import sys
|
import sys
|
||||||
|
Loading…
x
Reference in New Issue
Block a user