77end
88
99local OPTIONS = {
10- image_directory = " ." ,
11- relativize = false
12- }
10+ image_directory = " ." ,
11+ }
1312
1413local SPECIAL_CLASSES = {
1514 [" lilypond" ] = true ,
@@ -45,30 +44,12 @@ local function wrap_fragment(src)
4544 )
4645end
4746
48- local function get_output_directory ()
49- return PANDOC_STATE .output_file
50- and pandoc .pipe (
51- " dirname" ,
52- {PANDOC_STATE .output_file },
53- " "
54- ):gsub (" \n " , " " )
55- end
56-
57- local function resolve_relative_path (what , where )
58- return pandoc .system .with_working_directory (
59- where ,
60- function ()
61- return pandoc .pipe (" realpath" , {what }, " " ):gsub (" \n " , " " )
62- end
63- )
64- end
65-
66- local function generate_image (name , input , dpi , whither )
47+ local function generate_image (name , input , dpi )
6748 local fullname = name .. " .png"
68- with_temporary_directory (
49+ return fullname , with_temporary_directory (
6950 " lilypond-lua-XXXXX" ,
7051 function (tmp_dir )
71- pandoc .system .with_working_directory (
52+ return pandoc .system .with_working_directory (
7253 tmp_dir ,
7354 function ()
7455 pandoc .pipe (
@@ -80,20 +61,14 @@ local function generate_image(name, input, dpi, whither)
8061 },
8162 input
8263 )
83- pandoc .pipe (" cp" , {fullname , whither }, " " )
64+ local fh = io.open (fullname , ' rb' )
65+ local data = fh :read (' *all' )
66+ fh :close ()
67+ return data
8468 end
8569 )
8670 end
8771 )
88- return whither .. " /" .. fullname
89- end
90-
91- local function make_relative_path (to , from )
92- return pandoc .pipe (
93- " realpath" ,
94- {" --relative-to=" .. from , to },
95- " "
96- ):gsub (" \n " , " " )
9772end
9873
9974local function process_lilypond (elem , inline )
@@ -105,18 +80,11 @@ local function process_lilypond(elem, inline)
10580 local dpi = elem .attributes [" ly-resolution" ]
10681 local name = elem .attributes [" ly-name" ] or pandoc .sha1 (code )
10782
108- local out_dir = get_output_directory () or " ."
109- local dest = resolve_relative_path (OPTIONS .image_directory , out_dir )
110-
111- local path = generate_image (name , input , dpi , dest )
112- local img = io.open (path , " rb" )
113- pandoc .mediabag .insert (path , " image/png" , img :read (" *a" ))
114- img :close ()
83+ local image_filename , image_data = generate_image (name , input , dpi )
84+ local src = OPTIONS .image_directory .. ' /' .. image_filename
85+ pandoc .mediabag .insert (src , " image/png" , image_data )
11586
11687 local caption = elem .attributes [" ly-caption" ] or " Musical notation"
117- local src = OPTIONS .relativize
118- and make_relative_path (path , out_dir )
119- or path
12088 -- The "fig:" prefix causes this image to be rendered as a proper figure
12189 -- in HTML ouput (this is a rather ugly pandoc feature and may be replaced
12290 -- by something more elegant in the future).
@@ -154,9 +122,6 @@ local function meta_transformer(md)
154122 OPTIONS .image_directory = dir_conf
155123 and pandoc .utils .stringify (dir_conf )
156124 or OPTIONS .image_directory
157- OPTIONS .relativize = ly_block .relativize
158- or OPTIONS .relativize
159-
160125 md .lilypond = nil
161126 return md
162127end
0 commit comments