Allow xref buttons to have "internal" links

still assume external (open in new tab) by default
This commit is contained in:
Lance Edgar 2023-01-04 00:09:35 -06:00
parent c7537e7994
commit ab80aedb63

View file

@ -2644,17 +2644,33 @@ class MasterView(View):
return normal return normal
def make_xref_button(self, **kwargs): def make_xref_button(self, **kwargs):
"""
Make and return a HTML ``<b-button>`` literal, for display in
the cross-reference helper panel.
:param url: URL for the link.
:param text: Label for the button.
:param internal: Boolean indicating if the link is internal to
the site. This is false by default, meaning the link is
assumed to be external, which affects the icon and causes
button click to open link in a new tab.
"""
# nb. unfortunately HTML.tag() calls its first arg 'tag' and # nb. unfortunately HTML.tag() calls its first arg 'tag' and
# so we can't pass a kwarg with that name...so instead we # so we can't pass a kwarg with that name...so instead we
# patch that into place manually # patch that into place manually
button = HTML.tag('b-button', type='is-primary', btn_kw = dict(type='is-primary',
href=kwargs['url'], target='_blank', href=kwargs['url'],
icon_pack='fas', icon_left='external-link-alt', icon_pack='fas',
c=kwargs['text']) c=kwargs['text'])
if kwargs.get('internal'):
btn_kw['icon_left'] = 'eye'
else:
btn_kw['icon_left'] = 'external-link-alt'
btn_kw['target'] = '_blank'
button = HTML.tag('b-button', **btn_kw)
button = six.text_type(button) button = six.text_type(button)
button = button.replace('target="_blank"', button = button.replace('<b-button ',
'target="_blank" tag="a"') '<b-button tag="a"')
button = HTML.literal(button) button = HTML.literal(button)
return button return button