convert relative paths to absolute on preview

gh-pages
somas95 2018-04-12 21:55:45 +02:00
parent 992140f99f
commit ac1774c848
4 changed files with 38 additions and 4 deletions

View File

@ -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

View File

@ -694,15 +694,22 @@ class UberwriterWindow(Window):
# TODO
# Find a way to find the next header, scroll to the next header.
# 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',
'-s',
'--from=markdown',
'--to=html',
'--to=html5',
'--mathjax',
'--css=' + helpers.get_media_path('uberwriter.css'),
'--lua-filter=' + helpers.get_media_path('task-list.lua')]
print(args)
'--lua-filter=' + helpers.get_script_path('relative_to_absolute.lua'),
'--lua-filter=' + helpers.get_script_path('task-list.lua')]
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

View File

@ -61,6 +61,12 @@ def get_media_path(media_file_name):
media_filename = None
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):
def emit(self, record):
pass