forked from Mirrors/apostrophe
convert relative paths to absolute on preview
parent
992140f99f
commit
ac1774c848
|
@ -0,0 +1,21 @@
|
||||||
|
function string.starts(String,Start)
|
||||||
|
return string.sub(String,1,string.len(Start))==Start
|
||||||
|
end
|
||||||
|
|
||||||
|
function fix_path (path)
|
||||||
|
if string.starts(path, "/") then
|
||||||
|
return path
|
||||||
|
else
|
||||||
|
return (os.getenv('PANDOC_PREFIX') or '') .. path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Link (element)
|
||||||
|
element.target = fix_path(element.target)
|
||||||
|
return element
|
||||||
|
end
|
||||||
|
|
||||||
|
function Image (element)
|
||||||
|
element.src = fix_path(element.src)
|
||||||
|
return element
|
||||||
|
end
|
|
@ -694,15 +694,22 @@ class UberwriterWindow(Window):
|
||||||
# TODO
|
# TODO
|
||||||
# Find a way to find the next header, scroll to the next header.
|
# Find a way to find the next header, scroll to the next header.
|
||||||
# TODO: provide a local version of mathjax
|
# TODO: provide a local version of mathjax
|
||||||
|
|
||||||
|
# We need to convert relative routes to absolute ones
|
||||||
|
if self.filename:
|
||||||
|
base_path = os.path.dirname(self.filename)
|
||||||
|
else:
|
||||||
|
base_path = ''
|
||||||
|
os.environ['PANDOC_PREFIX'] = base_path + '/'
|
||||||
|
|
||||||
args = ['pandoc',
|
args = ['pandoc',
|
||||||
'-s',
|
'-s',
|
||||||
'--from=markdown',
|
'--from=markdown',
|
||||||
'--to=html',
|
'--to=html5',
|
||||||
'--mathjax',
|
'--mathjax',
|
||||||
'--css=' + helpers.get_media_path('uberwriter.css'),
|
'--css=' + helpers.get_media_path('uberwriter.css'),
|
||||||
'--lua-filter=' + helpers.get_media_path('task-list.lua')]
|
'--lua-filter=' + helpers.get_script_path('relative_to_absolute.lua'),
|
||||||
print(args)
|
'--lua-filter=' + helpers.get_script_path('task-list.lua')]
|
||||||
|
|
||||||
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,12 @@ def get_media_path(media_file_name):
|
||||||
media_filename = None
|
media_filename = None
|
||||||
return media_filename
|
return media_filename
|
||||||
|
|
||||||
|
def get_script_path(script_file_name):
|
||||||
|
script_filename = get_data_file('lua', '%s' % (script_file_name,))
|
||||||
|
if not os.path.exists(script_filename):
|
||||||
|
script_filename = None
|
||||||
|
return script_filename
|
||||||
|
|
||||||
class NullHandler(logging.Handler):
|
class NullHandler(logging.Handler):
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue