Treat the item's permalink as a regular link
Also fix some string formatting along the way.
This commit is contained in:
@@ -155,16 +155,15 @@ class SubmissionPage(Page):
|
|||||||
self.term.flash()
|
self.term.flash()
|
||||||
|
|
||||||
def open_submission_or_permalink_or_mentioned_link(self, data):
|
def open_submission_or_permalink_or_mentioned_link(self, data):
|
||||||
links_in_data = []
|
links = [{'text': 'Permalink', 'href': data['permalink']}]
|
||||||
if data['html']:
|
if data['html']:
|
||||||
links_in_data = self.get_links_in_html(data['html'])
|
links += self.get_links_in_html(data['html'])
|
||||||
|
if len(links) > 1:
|
||||||
if links_in_data:
|
self.prompt_user_and_open_selected_link(links)
|
||||||
self.prompt_user_and_open_selected_link(data, links_in_data)
|
|
||||||
elif 'url_full' in data and data['url_full']:
|
elif 'url_full' in data and data['url_full']:
|
||||||
self.term.open_link(data['url_full'])
|
self.term.open_link(data['url_full'])
|
||||||
else:
|
else:
|
||||||
self.term.open_browser(data['permalink'])
|
self.term.open_link(data['permalink'])
|
||||||
|
|
||||||
def get_links_in_html(self, html):
|
def get_links_in_html(self, html):
|
||||||
links = []
|
links = []
|
||||||
@@ -176,19 +175,19 @@ class SubmissionPage(Page):
|
|||||||
links.append(link)
|
links.append(link)
|
||||||
return links
|
return links
|
||||||
|
|
||||||
def prompt_user_and_open_selected_link(self, data, links):
|
def prompt_user_and_open_selected_link(self, links):
|
||||||
text = 'Open link:\n'
|
text = 'Open link:\n'
|
||||||
text += ('[1] Permalink to this %s\n' % (data['type'].lower(),))
|
for i, link in enumerate(links[:9]):
|
||||||
for i, link in enumerate(links[:8]):
|
capped_link_text = (link['text'] if len(link['text']) <= 20
|
||||||
text += '[%s] [%s](%s)\n' % (i + 2, link['text'], link['href'])
|
else link['text'][:19] + '…')
|
||||||
|
text += '[{}] [{}]({})\n'.format(
|
||||||
|
i+1, capped_link_text, link['href'])
|
||||||
try:
|
try:
|
||||||
choice = int(chr(self.term.show_notification(text)))
|
choice = int(chr(self.term.show_notification(text)))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
if choice == 1:
|
if choice <= len(links):
|
||||||
self.term.open_browser(data['permalink'])
|
self.term.open_link(links[choice - 1]['href'])
|
||||||
elif choice - 2 < len(links):
|
|
||||||
self.term.open_link(links[choice - 2]['href'])
|
|
||||||
|
|
||||||
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_PAGER'))
|
@SubmissionController.register(Command('SUBMISSION_OPEN_IN_PAGER'))
|
||||||
def open_pager(self):
|
def open_pager(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user