@@ -46,7 +46,7 @@ local expansions = {
46
46
--- @field whole_file ? boolean
47
47
48
48
--- @class OrgCaptureTemplate : OrgCaptureTemplateOpts
49
- --- @field private _compile_hooks (fun (content : string ): string )[]
49
+ --- @field private _compile_hooks (fun (content : string , type : ' target ' | ' content ' ): string )[]
50
50
local Template = {}
51
51
52
52
--- @param opts OrgCaptureTemplateOpts
@@ -69,7 +69,7 @@ function Template:new(opts)
69
69
local this = {}
70
70
this .description = opts .description or ' '
71
71
this .template = opts .template or ' '
72
- this .target = self : _compile ( opts .target or ' ' )
72
+ this .target = opts .target or ' '
73
73
this .headline = opts .headline
74
74
this .properties = TemplateProperties :new (opts .properties )
75
75
this .datetree = opts .datetree
@@ -156,7 +156,7 @@ function Template:compile()
156
156
if type (content ) == ' table' then
157
157
content = table.concat (content , ' \n ' )
158
158
end
159
- content = self :_compile (content or ' ' )
159
+ content = self :_compile (content or ' ' , ' content ' )
160
160
return vim .split (content , ' \n ' , { plain = true })
161
161
end
162
162
189
189
190
190
--- @return string
191
191
function Template :get_target ()
192
- return vim .fn .resolve (vim .fn .fnamemodify (self .target , ' :p' ))
192
+ return vim .fn .resolve (vim .fn .fnamemodify (self : _compile ( self .target , ' target ' ) , ' :p' ))
193
193
end
194
194
195
195
--- @param lines string[]
@@ -210,15 +210,16 @@ end
210
210
211
211
--- @private
212
212
--- @param content string
213
+ --- @param type ' target' | ' content'
213
214
--- @return string
214
- function Template :_compile (content )
215
+ function Template :_compile (content , type )
215
216
content = self :_compile_dates (content )
216
217
content = self :_compile_expansions (content )
217
218
content = self :_compile_expressions (content )
218
219
content = self :_compile_prompts (content )
219
220
if self ._compile_hooks then
220
221
for _ , hook in ipairs (self ._compile_hooks ) do
221
- content = hook (content )
222
+ content = hook (content , type )
222
223
end
223
224
end
224
225
return content
0 commit comments