From efb1a02f30658081a098095599c3fd0530bd1f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Silva?= Date: Sat, 22 Jun 2019 00:38:05 +0100 Subject: [PATCH] Use file name for link description and image caption --- uberwriter/text_view_drag_drop_handler.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/uberwriter/text_view_drag_drop_handler.py b/uberwriter/text_view_drag_drop_handler.py index 8e0adba..e45c4f7 100644 --- a/uberwriter/text_view_drag_drop_handler.py +++ b/uberwriter/text_view_drag_drop_handler.py @@ -1,5 +1,6 @@ import mimetypes import urllib +from os.path import basename from gi.repository import Gtk @@ -28,14 +29,15 @@ class DragDropHandler: if info == TARGET_URI: uris = data.get_uris() for uri in uris: + name = basename(urllib.parse.unquote_plus(uri)) mime = mimetypes.guess_type(uri) - if mime[0] is not None and mime[0].startswith('image'): - text = "![Image caption](%s)" % uri + if mime[0] is not None and mime[0].startswith('image/'): + text = "![{}]({})".format(name, uri) limit_left = 2 limit_right = 23 else: - text = "[Link description](%s)" % uri + text = "[{}]({})".format(name, uri) limit_left = 1 limit_right = 22 text_buffer.place_cursor(text_buffer.get_iter_at_mark(