7
7
end
8
8
9
9
local OPTIONS = {
10
- image_directory = " ." ,
11
- relativize = false
12
- }
10
+ image_directory = " ." ,
11
+ }
13
12
14
13
local SPECIAL_CLASSES = {
15
14
[" lilypond" ] = true ,
@@ -45,30 +44,12 @@ local function wrap_fragment(src)
45
44
)
46
45
end
47
46
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 )
67
48
local fullname = name .. " .png"
68
- with_temporary_directory (
49
+ return fullname , with_temporary_directory (
69
50
" lilypond-lua-XXXXX" ,
70
51
function (tmp_dir )
71
- pandoc .system .with_working_directory (
52
+ return pandoc .system .with_working_directory (
72
53
tmp_dir ,
73
54
function ()
74
55
pandoc .pipe (
@@ -80,20 +61,14 @@ local function generate_image(name, input, dpi, whither)
80
61
},
81
62
input
82
63
)
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
84
68
end
85
69
)
86
70
end
87
71
)
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 " , " " )
97
72
end
98
73
99
74
local function process_lilypond (elem , inline )
@@ -105,18 +80,11 @@ local function process_lilypond(elem, inline)
105
80
local dpi = elem .attributes [" ly-resolution" ]
106
81
local name = elem .attributes [" ly-name" ] or pandoc .sha1 (code )
107
82
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 )
115
86
116
87
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
120
88
-- The "fig:" prefix causes this image to be rendered as a proper figure
121
89
-- in HTML ouput (this is a rather ugly pandoc feature and may be replaced
122
90
-- by something more elegant in the future).
@@ -154,9 +122,6 @@ local function meta_transformer(md)
154
122
OPTIONS .image_directory = dir_conf
155
123
and pandoc .utils .stringify (dir_conf )
156
124
or OPTIONS .image_directory
157
- OPTIONS .relativize = ly_block .relativize
158
- or OPTIONS .relativize
159
-
160
125
md .lilypond = nil
161
126
return md
162
127
end
0 commit comments