Thanks a lot for looking into it!It does not seem to produce the desired effect on my end.Could you explain how changingreturn {{Meta = get_default_code_class},
{Code = add_default_code_class},
{CodeBlock = add_default_code_class}}intoreturn {{Meta=get_default_code_class}, {CodeBlock=add_default_code_class}}(as far as I can tell, this is the only modification) is supposed to achieve the desired effect?
% cat default-code-class.lua
utils = require 'utils'
local default_code_classes = {}
function get_default_code_class(meta)
utils.temp('meta', meta)
if meta['default-code-class'] then
default_code_classes = {pandoc.utils.stringify(meta['default-code-class'])}
end
end
function add_default_code_class(el)
utils.temp(el.tag, el)
if #(el.classes) == 0 then
el.classes = default_code_classes
return el
end
end
return {{Meta=get_default_code_class},
{Code=add_default_code_class, CodeBlock=add_default_code_class}}
% LUA_PATH=../?.lua pandoc -L default-code-class.lua code.md -M default-code-class="c numberLines"
(#) meta {default-code-class: "c numberLines"}
(#) Code Code {
attr: Attr {
attributes: {}
classes: {}
identifier: ""
}
text: "inline code"
}
(#) CodeBlock CodeBlock {
attr: Attr {
attributes: {}
classes: {}
identifier: ""
}
text: "This is a code block."
}
<p>This is <code class="c numberLines">inline code</code>.</p>
<pre class="c numberLines"><code>This is a code block.</code></pre>
Thanks!--Le ven. 20 août 2021 à 11:57, William Lupton <wlupton@broadband-forum.org> a écrit :I think you need a two-pass filter, one to pick up the metadata and the other to use it (this is because Meta is called nearly last).This works (I've re-ordered your functions and declared a local variable, but this probably wasn't necessary).% cat default-code-class.lua
local default_code_classes = {}
function get_default_code_class(meta)
if meta['default-code-class'] then
default_code_classes = {pandoc.utils.stringify(meta['default-code-class'])}
end
end
function add_default_code_class(el)
if #(el.classes) == 0 then
el.classes = default_code_classes
return el
end
end
return {{Meta=get_default_code_class}, {CodeBlock=add_default_code_class}}
% pandoc -L default-code-class.lua code.md -M default-code-class="c numberLines"
<pre class="c numberLines"><code></code></pre>
--On Fri, 20 Aug 2021 at 16:29, Clément Aubert <aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:Hi,This question relates toThere is a lua filter containing``` lua
function add_default_code_class(el)
if #(el.classes) == 0 then
el.classes = default_code_classes
return el
end
end
function get_default_code_class(meta)
if meta['default-code-class'] then
default_code_classes = {pandoc.utils.stringify(meta['default-code-class'])}
end
end
```and I'm trying to tweak it so that two classes can be passed from the command-line, eg. using--lua-filter default-code-class.lua -M default-code-class=c, numberLinesbut can't find a way.Thanks!Clément.--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/c025fcc7-ff39-4993-97f0-3dc8a7107724n%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "pandoc-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pandoc-discuss/NrRuAcm1otQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgqyK6%2BT3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com.