browser: minor fixes

This commit is contained in:
dece 2021-04-16 19:30:14 +02:00
parent 6bc4dbcc5d
commit bce65a1472
4 changed files with 8 additions and 5 deletions

View file

@ -7,7 +7,7 @@ from bebop.tofu import load_cert_stash, save_cert_stash
def main(): def main():
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
argparser.add_argument("url", default=None) argparser.add_argument("url", nargs="?", default=None)
args = argparser.parse_args() args = argparser.parse_args()
if args.url: if args.url:

View file

@ -295,9 +295,11 @@ class Browser:
def handle_digit_input(self, init_char: int): def handle_digit_input(self, init_char: int):
"""Focus command-line to select the link ID to follow.""" """Focus command-line to select the link ID to follow."""
if not self.page_pad or self.page_pad.current_page.links is None: if self.page_pad.current_page is None:
return return
links = self.page_pad.current_page.links links = self.page_pad.current_page.links
if links is None:
return
err, val = self.command_line.focus_for_link_navigation(init_char, links) err, val = self.command_line.focus_for_link_navigation(init_char, links)
if err == 0: if err == 0:
self.open_link(links, val) # type: ignore self.open_link(links, val) # type: ignore
@ -411,7 +413,7 @@ class Browser:
"""Add the current URL as bookmark.""" """Add the current URL as bookmark."""
if not self.current_url: if not self.current_url:
return return
self.set_status("Title?") self.set_status("Bookmark title?")
current_title = self.page_pad.current_page.title or "" current_title = self.page_pad.current_page.title or ""
title = self.command_line.focus(">", prefix=current_title) title = self.command_line.focus(">", prefix=current_title)
if title: if title:

View file

@ -57,7 +57,7 @@ ParsedGemtext = namedtuple("ParsedGemtext", ("elements", "links", "title"))
def parse_gemtext(text: str) -> ParsedGemtext: def parse_gemtext(text: str) -> ParsedGemtext:
"""Parse a string of Gemtext into a list of elements.""" """Parse a string of Gemtext into a list of elements."""
elements = [] elements = []
links = Links links = Links()
last_link_id = 0 last_link_id = 0
title = "" title = ""
preformatted = None preformatted = None
@ -80,6 +80,7 @@ def parse_gemtext(text: str) -> ParsedGemtext:
match_dict = match.groupdict() match_dict = match.groupdict()
url, text = match_dict["url"], match_dict.get("text", "") url, text = match_dict["url"], match_dict.get("text", "")
last_link_id += 1 last_link_id += 1
links[last_link_id] = url
elements.append(Link(url, text, last_link_id)) elements.append(Link(url, text, last_link_id))
continue continue

View file

@ -145,7 +145,7 @@ def format_preformatted(preformatted: Preformatted, context: dict):
def format_blockquote(blockquote: Blockquote, context: dict): def format_blockquote(blockquote: Blockquote, context: dict):
"""Return metalines for this blockquote.""" """Return metalines for this blockquote."""
lines = wrap_words(blockquote.text, context["width"]) lines = wrap_words(blockquote.text, context["width"], indent=2)
return [({"type": LineType.BLOCKQUOTE}, line) for line in lines] return [({"type": LineType.BLOCKQUOTE}, line) for line in lines]