forked from Mirrors/apostrophe
Merge pull request #199 from UberWriter/ft.local_paths
This PR allows uberwriter to handle seamlessly local paths in links and images, both in the inline preview, the live preview and the outputui^2
commit
c6dce3f2cb
|
@ -6,7 +6,7 @@ function fix_path (path)
|
|||
if string.starts(path, "/") then
|
||||
return path
|
||||
else
|
||||
return (os.getenv('PANDOC_PREFIX') or '') .. path
|
||||
return (pandoc.system.get_working_directory() or '') .. "/" .. path
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ class Export:
|
|||
|
||||
if export_type == "html":
|
||||
to = "html5"
|
||||
args.append("--standalone")
|
||||
args.append("--self-contained")
|
||||
args.append("--css=%s" % Theme.get_current().web_css_path)
|
||||
args.append("--mathjax")
|
||||
args.append("--lua-filter=%s" % helpers.get_script_path('relative_to_absolute.lua'))
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# END LICENSE
|
||||
|
||||
import re
|
||||
import os
|
||||
import telnetlib
|
||||
from gettext import gettext as _
|
||||
from urllib.parse import unquote
|
||||
|
@ -151,6 +152,8 @@ class InlinePreview:
|
|||
HEIGHT = 300
|
||||
|
||||
def __init__(self, text_view):
|
||||
self.settings = Settings.new()
|
||||
|
||||
self.text_view = text_view
|
||||
self.text_view.connect("button-press-event", self.on_button_press_event)
|
||||
self.text_buffer = text_view.get_buffer()
|
||||
|
@ -158,7 +161,7 @@ class InlinePreview:
|
|||
"click", self.text_buffer.get_iter_at_mark(self.text_buffer.get_insert()))
|
||||
|
||||
self.latex_converter = latex_to_PNG.LatexToPNG()
|
||||
self.characters_per_line = Settings.new().get_int("characters-per-line")
|
||||
self.characters_per_line = self.settings.get_int("characters-per-line")
|
||||
|
||||
self.popover = Gtk.Popover.new(self.text_view)
|
||||
self.popover.get_style_context().add_class("quick-preview-popup")
|
||||
|
@ -191,9 +194,15 @@ class InlinePreview:
|
|||
|
||||
def get_view_for_image(self, match):
|
||||
path = match.group("url")
|
||||
if not path.startswith(("/")):
|
||||
|
||||
if path.startswith(("https://", "http://", "www.")):
|
||||
return self.get_view_for_link(match)
|
||||
if path.startswith(("file://")):
|
||||
path = path[7:]
|
||||
if not path.startswith(("/", "file://")):
|
||||
path = os.path.join(self.settings.get_string("open-file-path"), path)
|
||||
path = unquote(path)
|
||||
|
||||
return Gtk.Image.new_from_pixbuf(
|
||||
GdkPixbuf.Pixbuf.new_from_file_at_size(path, self.WIDTH, self.HEIGHT))
|
||||
|
||||
|
|
|
@ -442,7 +442,6 @@ class MainWindow(StyledWindow):
|
|||
return
|
||||
|
||||
if filename:
|
||||
print(urllib.parse.unquote(filename))
|
||||
if filename.startswith('file://'):
|
||||
filename = urllib.parse.unquote(filename)[7:]
|
||||
self.text_view.clear()
|
||||
|
@ -520,7 +519,6 @@ class MainWindow(StyledWindow):
|
|||
def open_recent(self, _widget, data=None):
|
||||
"""open the given recent document
|
||||
"""
|
||||
print("open")
|
||||
|
||||
if data:
|
||||
if self.check_change() == Gtk.ResponseType.CANCEL:
|
||||
|
@ -631,6 +629,7 @@ class MainWindow(StyledWindow):
|
|||
if filename:
|
||||
self.filename = filename
|
||||
base_path = os.path.dirname(self.filename)
|
||||
os.chdir(base_path)
|
||||
else:
|
||||
self.filename = None
|
||||
base_path = "/"
|
||||
|
|
|
@ -2,6 +2,7 @@ import mimetypes
|
|||
import urllib
|
||||
from gettext import gettext as _
|
||||
from os.path import basename
|
||||
from uberwriter.settings import Settings
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
|
@ -14,6 +15,8 @@ class DragDropHandler:
|
|||
def __init__(self, text_view, *targets):
|
||||
super().__init__()
|
||||
|
||||
self.settings = Settings.new()
|
||||
|
||||
self.target_list = Gtk.TargetList.new([])
|
||||
if TARGET_URI in targets:
|
||||
self.target_list.add_uri_targets(TARGET_URI)
|
||||
|
@ -35,8 +38,17 @@ class DragDropHandler:
|
|||
mime = mimetypes.guess_type(uri)
|
||||
|
||||
if mime[0] is not None and mime[0].startswith('image/'):
|
||||
basepath = self.settings.get_string("open-file-path")
|
||||
basepath = urllib.parse.quote(basepath)
|
||||
|
||||
if uri.startswith("file://"):
|
||||
uri = uri[7:]
|
||||
|
||||
# for handling local URIs we need to substract the basepath
|
||||
# except when it is "/" (document not saved)
|
||||
if uri.startswith(basepath) and basepath != "/":
|
||||
uri = uri[len(basepath)+1:]
|
||||
|
||||
text = "![{}]({})".format(name, uri)
|
||||
limit_left = 2
|
||||
limit_right = len(name)
|
||||
|
@ -57,7 +69,6 @@ class DragDropHandler:
|
|||
text_buffer.delete(cursor_iter_l, cursor_iter_r)
|
||||
|
||||
if text.startswith(("http://", "https://", "www.")):
|
||||
print("web")
|
||||
text = "[{}]({})".format(_("web page"), text)
|
||||
limit_left = 1
|
||||
limit_right = len(_("web page"))
|
||||
|
|
Loading…
Reference in New Issue