* Passing multiple options to lua-filter from CLI @ 2021-08-20 15:29 Clément Aubert [not found] ` <c025fcc7-ff39-4993-97f0-3dc8a7107724n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Clément Aubert @ 2021-08-20 15:29 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1097 bytes --] Hi, This question relates to https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 There 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, numberLines but 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. [-- Attachment #1.2: Type: text/html, Size: 1755 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <c025fcc7-ff39-4993-97f0-3dc8a7107724n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Passing multiple options to lua-filter from CLI [not found] ` <c025fcc7-ff39-4993-97f0-3dc8a7107724n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2021-08-20 15:57 ` William Lupton [not found] ` <CAEe_xxgqyK6+T3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: William Lupton @ 2021-08-20 15:57 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 2732 bytes --] 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 to > https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 > There 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, numberLines > > but 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 > <https://groups.google.com/d/msgid/pandoc-discuss/c025fcc7-ff39-4993-97f0-3dc8a7107724n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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. [-- Attachment #2: Type: text/html, Size: 10855 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAEe_xxgqyK6+T3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Passing multiple options to lua-filter from CLI [not found] ` <CAEe_xxgqyK6+T3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-08-20 16:06 ` Clément Aubert [not found] ` <CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Clément Aubert @ 2021-08-20 16:06 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 4083 bytes --] Thanks a lot for looking into it! It does not seem to produce the desired effect on my end. Could you explain how changing return {{Meta = get_default_code_class}, {Code = add_default_code_class}, {CodeBlock = add_default_code_class}} into return {{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? 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@gmail.com> > wrote: > >> Hi, >> >> This question relates to >> https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 >> There 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, numberLines >> >> but 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >> <https://groups.google.com/d/msgid/pandoc-discuss/c025fcc7-ff39-4993-97f0-3dc8a7107724n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 > <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgqyK6%2BT3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 11872 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Passing multiple options to lua-filter from CLI [not found] ` <CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-08-20 16:26 ` William Lupton [not found] ` <CAEe_xxgDzL+Qjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: William Lupton @ 2021-08-20 16:26 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 6829 bytes --] Inline... On Fri, 20 Aug 2021 at 17:06, Clément Aubert <aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > Thanks a lot for looking into it! > It does not seem to produce the desired effect on my end. > > Could you explain how changing > return {{Meta = get_default_code_class}, > {Code = add_default_code_class}, > {CodeBlock = add_default_code_class}} > into > return {{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? > Ah, well I don't think that you included this in your original message, so I thought that was the problem :). return {{Meta = get_default_code_class}, {Code = add_default_code_class}, {CodeBlock = add_default_code_class}} You are correct: the only difference is that you have Code. You could combine Code and CodeBlock into a single pass, as in: return {{Meta=get_default_code_class}, {Code=add_default_code_class, CodeBlock=add_default_code_class}} But it _does_ work for me! Maybe add some debug output? Here I'm using my own inspect-like function but the standard inspect would probably be similar. Pandoc version? I'm using 2.14.1. *% *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@gmail.com> >> wrote: >> >>> Hi, >>> >>> This question relates to >>> https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 >>> There 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, numberLines >>> >>> but 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >>> <https://groups.google.com/d/msgid/pandoc-discuss/c025fcc7-ff39-4993-97f0-3dc8a7107724n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >> <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgqyK6%2BT3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com > <https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 30176 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAEe_xxgDzL+Qjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Passing multiple options to lua-filter from CLI [not found] ` <CAEe_xxgDzL+Qjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-08-20 17:03 ` Clément Aubert [not found] ` <CAPGHSewt=nK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Clément Aubert @ 2021-08-20 17:03 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 9358 bytes --] Thanks! pandoc -v pandoc 2.14.1 Compiled with pandoc-types 1.22, texmath 0.12.3, skylighting 0.11, citeproc 0.4.1, ipynb 0.1.0.1 User data directory: /home/caubert/.local/share/pandoc with the first line (about utils), I now get Error running filter templates/filters/default-code-class.lua: templates/filters/default-code-class.lua:1: module 'utils' not found: utilsis not one of pandoc's default packages no field package.preload['utils'] no file '/usr/local/share/lua/5.3/utils.lua' no file '/usr/local/share/lua/5.3/utils/init.lua' no file '/usr/local/lib/lua/5.3/utils.lua' no file '/usr/local/lib/lua/5.3/utils/init.lua' no file './utils.lua' no file './utils/init.lua' no file '/usr/local/lib/lua/5.3/utils.so' no file '/usr/local/lib/lua/5.3/loadall.so' no file './utils.so' stack traceback: [C]: in function 'require' templates/filters/default-code-class.lua:1: in main chunk make: *** [Makefile:281: build/labs/If/index.html] Error 83 without it, I get Error running filter templates/filters/default-code-class.lua: templates/filters/default-code-class.lua:7: attempt to index a nil value (global 'utils') stack traceback: templates/filters/default-code-class.lua:7: in function 'get_default_code_class' make: *** [Makefile:281: build/labs/If/index.html] Error 83 Le ven. 20 août 2021 à 12:26, William Lupton <wlupton@broadband-forum.org> a écrit : > Inline... > > On Fri, 20 Aug 2021 at 17:06, Clément Aubert <aubert.clement@gmail.com> > wrote: > >> Thanks a lot for looking into it! >> It does not seem to produce the desired effect on my end. >> >> Could you explain how changing >> return {{Meta = get_default_code_class}, >> {Code = add_default_code_class}, >> {CodeBlock = add_default_code_class}} >> into >> return {{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? >> > > Ah, well I don't think that you included this in your original message, so > I thought that was the problem :). > > return {{Meta = get_default_code_class}, > {Code = add_default_code_class}, > {CodeBlock = add_default_code_class}} > > You are correct: the only difference is that you have Code. You could > combine Code and CodeBlock into a single pass, as in: > > return {{Meta=get_default_code_class}, > {Code=add_default_code_class, CodeBlock=add_default_code_class}} > > But it _does_ work for me! Maybe add some debug output? Here I'm using my > own inspect-like function but the standard inspect would probably be > similar. > > Pandoc version? I'm using 2.14.1. > > *% *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@gmail.com> >>> wrote: >>> >>>> Hi, >>>> >>>> This question relates to >>>> https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 >>>> There 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, numberLines >>>> >>>> but 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >>>> <https://groups.google.com/d/msgid/pandoc-discuss/c025fcc7-ff39-4993-97f0-3dc8a7107724n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >>> <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgqyK6%2BT3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com >> <https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com > <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSewt%3DnK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 31075 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAPGHSewt=nK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Passing multiple options to lua-filter from CLI [not found] ` <CAPGHSewt=nK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-08-20 17:21 ` William Lupton [not found] ` <CAEe_xxjF_GT3XXobnhGizje_U6VDcODV0ubGR0dDN=Dj_U2B3A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: William Lupton @ 2021-08-20 17:21 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 12006 bytes --] You can't use my utils because I didn't supply it! I suggested using inspect (https://github.com/kikito/inspect.lua) to get something similar. Sorry... I was just using my utils to illustrate the AST. Anyway, please can you run this in your local environment and report what you see? If you don't see the same as me then I don't know what to suggest! Filter (this has changed a little bit but not substantively): *% *cat default-code-class.lua local use_utils = false local utils = nil if use_utils then utils = require 'utils' end local default_code_classes = {} local function get_default_code_class(meta) if utils then utils.temp('meta', meta) end if meta['default-code-class'] then default_code_classes = {pandoc.utils.stringify(meta['default-code-class'])} end end local function add_default_code_class(el) if utils then utils.temp(el) end 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}} Markdown: *% *cat code.md This is `inline code`. ``` This is a code block. ``` Invocation: *% *pandoc -L default-code-class.lua code.md -M default-code-class="c numberLines" <p>This is <code class="c numberLines">inline code</code>.</p> <pre class="c numberLines"><code>This is a code block.</code></pre> On Fri, 20 Aug 2021 at 18:03, Clément Aubert <aubert.clement-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > Thanks! > > pandoc -v > pandoc 2.14.1 > Compiled with pandoc-types 1.22, texmath 0.12.3, skylighting 0.11, > citeproc 0.4.1, ipynb 0.1.0.1 > User data directory: /home/caubert/.local/share/pandoc > > with the first line (about utils), I now get > > Error running filter templates/filters/default-code-class.lua: > templates/filters/default-code-class.lua:1: module 'utils' not found: > utilsis not one of pandoc's default packages > no field package.preload['utils'] > no file '/usr/local/share/lua/5.3/utils.lua' > no file '/usr/local/share/lua/5.3/utils/init.lua' > no file '/usr/local/lib/lua/5.3/utils.lua' > no file '/usr/local/lib/lua/5.3/utils/init.lua' > no file './utils.lua' > no file './utils/init.lua' > no file '/usr/local/lib/lua/5.3/utils.so' > no file '/usr/local/lib/lua/5.3/loadall.so' > no file './utils.so' > stack traceback: > [C]: in function 'require' > templates/filters/default-code-class.lua:1: in main chunk > make: *** [Makefile:281: build/labs/If/index.html] Error 83 > > without it, I get > > Error running filter templates/filters/default-code-class.lua: > templates/filters/default-code-class.lua:7: attempt to index a nil value > (global 'utils') > stack traceback: > templates/filters/default-code-class.lua:7: in function > 'get_default_code_class' > make: *** [Makefile:281: build/labs/If/index.html] Error 83 > > > > > > Le ven. 20 août 2021 à 12:26, William Lupton <wlupton@broadband-forum.org> > a écrit : > >> Inline... >> >> On Fri, 20 Aug 2021 at 17:06, Clément Aubert <aubert.clement@gmail.com> >> wrote: >> >>> Thanks a lot for looking into it! >>> It does not seem to produce the desired effect on my end. >>> >>> Could you explain how changing >>> return {{Meta = get_default_code_class}, >>> {Code = add_default_code_class}, >>> {CodeBlock = add_default_code_class}} >>> into >>> return {{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? >>> >> >> Ah, well I don't think that you included this in your original message, >> so I thought that was the problem :). >> >> return {{Meta = get_default_code_class}, >> {Code = add_default_code_class}, >> {CodeBlock = add_default_code_class}} >> >> You are correct: the only difference is that you have Code. You could >> combine Code and CodeBlock into a single pass, as in: >> >> return {{Meta=get_default_code_class}, >> {Code=add_default_code_class, CodeBlock=add_default_code_class}} >> >> But it _does_ work for me! Maybe add some debug output? Here I'm using my >> own inspect-like function but the standard inspect would probably be >> similar. >> >> Pandoc version? I'm using 2.14.1. >> >> *% *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-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.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@gmail.com> >>>> wrote: >>>> >>>>> Hi, >>>>> >>>>> This question relates to >>>>> https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 >>>>> There 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, >>>>> numberLines >>>>> >>>>> but 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >>>>> <https://groups.google.com/d/msgid/pandoc-discuss/c025fcc7-ff39-4993-97f0-3dc8a7107724n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> -- >>>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >>>> <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgqyK6%2BT3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com >>> <https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com >> <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSewt%3DnK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ%40mail.gmail.com > <https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSewt%3DnK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxjF_GT3XXobnhGizje_U6VDcODV0ubGR0dDN%3DDj_U2B3A%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 48248 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAEe_xxjF_GT3XXobnhGizje_U6VDcODV0ubGR0dDN=Dj_U2B3A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Passing multiple options to lua-filter from CLI [not found] ` <CAEe_xxjF_GT3XXobnhGizje_U6VDcODV0ubGR0dDN=Dj_U2B3A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-08-20 18:19 ` Clément Aubert 0 siblings, 0 replies; 7+ messages in thread From: Clément Aubert @ 2021-08-20 18:19 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 13506 bytes --] I'm sorry, the issue is on my end. It works perfectly on your small example, but not on my bigger document that involves multiple other options, make file and the like. I'll investigate, but you definitely answered my question, thanks a lot! Clément. Le ven. 20 août 2021 à 13:21, William Lupton <wlupton@broadband-forum.org> a écrit : > You can't use my utils because I didn't supply it! I suggested using > inspect (https://github.com/kikito/inspect.lua) to get something similar. > Sorry... I was just using my utils to illustrate the AST. > > Anyway, please can you run this in your local environment and report what > you see? If you don't see the same as me then I don't know what to suggest! > > Filter (this has changed a little bit but not substantively): > > *% *cat default-code-class.lua > > local use_utils = false > > local utils = nil > > > if use_utils then > > utils = require 'utils' > > end > > > local default_code_classes = {} > > > local function get_default_code_class(meta) > > if utils then > > utils.temp('meta', meta) > > end > > if meta['default-code-class'] then > > default_code_classes = > > {pandoc.utils.stringify(meta['default-code-class'])} > > end > > end > > > local function add_default_code_class(el) > > if utils then > > utils.temp(el) > > end > > 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}} > > Markdown: > > *% *cat code.md > > This is `inline code`. > > > ``` > > This is a code block. > > ``` > > Invocation: > > *% *pandoc -L default-code-class.lua code.md -M default-code-class="c > numberLines" > > <p>This is <code class="c numberLines">inline code</code>.</p> > > <pre class="c numberLines"><code>This is a code block.</code></pre> > > On Fri, 20 Aug 2021 at 18:03, Clément Aubert <aubert.clement@gmail.com> > wrote: > >> Thanks! >> >> pandoc -v >> pandoc 2.14.1 >> Compiled with pandoc-types 1.22, texmath 0.12.3, skylighting 0.11, >> citeproc 0.4.1, ipynb 0.1.0.1 >> User data directory: /home/caubert/.local/share/pandoc >> >> with the first line (about utils), I now get >> >> Error running filter templates/filters/default-code-class.lua: >> templates/filters/default-code-class.lua:1: module 'utils' not found: >> utilsis not one of pandoc's default packages >> no field package.preload['utils'] >> no file '/usr/local/share/lua/5.3/utils.lua' >> no file '/usr/local/share/lua/5.3/utils/init.lua' >> no file '/usr/local/lib/lua/5.3/utils.lua' >> no file '/usr/local/lib/lua/5.3/utils/init.lua' >> no file './utils.lua' >> no file './utils/init.lua' >> no file '/usr/local/lib/lua/5.3/utils.so' >> no file '/usr/local/lib/lua/5.3/loadall.so' >> no file './utils.so' >> stack traceback: >> [C]: in function 'require' >> templates/filters/default-code-class.lua:1: in main chunk >> make: *** [Makefile:281: build/labs/If/index.html] Error 83 >> >> without it, I get >> >> Error running filter templates/filters/default-code-class.lua: >> templates/filters/default-code-class.lua:7: attempt to index a nil value >> (global 'utils') >> stack traceback: >> templates/filters/default-code-class.lua:7: in function >> 'get_default_code_class' >> make: *** [Makefile:281: build/labs/If/index.html] Error 83 >> >> >> >> >> >> Le ven. 20 août 2021 à 12:26, William Lupton <wlupton@broadband-forum.org> >> a écrit : >> >>> Inline... >>> >>> On Fri, 20 Aug 2021 at 17:06, Clément Aubert <aubert.clement@gmail.com> >>> wrote: >>> >>>> Thanks a lot for looking into it! >>>> It does not seem to produce the desired effect on my end. >>>> >>>> Could you explain how changing >>>> return {{Meta = get_default_code_class}, >>>> {Code = add_default_code_class}, >>>> {CodeBlock = add_default_code_class}} >>>> into >>>> return {{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? >>>> >>> >>> Ah, well I don't think that you included this in your original message, >>> so I thought that was the problem :). >>> >>> return {{Meta = get_default_code_class}, >>> {Code = add_default_code_class}, >>> {CodeBlock = add_default_code_class}} >>> >>> You are correct: the only difference is that you have Code. You could >>> combine Code and CodeBlock into a single pass, as in: >>> >>> return {{Meta=get_default_code_class}, >>> {Code=add_default_code_class, CodeBlock=add_default_code_class}} >>> >>> But it _does_ work for me! Maybe add some debug output? Here I'm using >>> my own inspect-like function but the standard inspect would probably be >>> similar. >>> >>> Pandoc version? I'm using 2.14.1. >>> >>> *% *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-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.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@gmail.com> >>>>> wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> This question relates to >>>>>> https://github.com/jgm/pandoc/issues/2104#issuecomment-595983954 >>>>>> There 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, >>>>>> numberLines >>>>>> >>>>>> but 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >>>>>> <https://groups.google.com/d/msgid/pandoc-discuss/c025fcc7-ff39-4993-97f0-3dc8a7107724n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> -- >>>>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 >>>>> <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgqyK6%2BT3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> -- >>>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com >>>> <https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >>> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com >>> <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgDzL%2BQjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSewt%3DnK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ%40mail.gmail.com >> <https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSewt%3DnK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxjF_GT3XXobnhGizje_U6VDcODV0ubGR0dDN%3DDj_U2B3A%40mail.gmail.com > <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxjF_GT3XXobnhGizje_U6VDcODV0ubGR0dDN%3DDj_U2B3A%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPGHSexHuj0T1n%2B-rOFjnVe5ZLw5Y_iqQEsn1yjECZSdy3e9QQ%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 47918 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-08-20 18:19 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-08-20 15:29 Passing multiple options to lua-filter from CLI Clément Aubert [not found] ` <c025fcc7-ff39-4993-97f0-3dc8a7107724n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2021-08-20 15:57 ` William Lupton [not found] ` <CAEe_xxgqyK6+T3kmb7sNUckEJrS81cwm05iCvauKOA0Z3doRcg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-08-20 16:06 ` Clément Aubert [not found] ` <CAPGHSezmvUZSEApp0fGCezjUNcqSJJCMBaLGTaPUc86tSoUS0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-08-20 16:26 ` William Lupton [not found] ` <CAEe_xxgDzL+Qjar4bGfUndO7Pq-RimWPmN5tzYSV3B6BUh0Nrg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-08-20 17:03 ` Clément Aubert [not found] ` <CAPGHSewt=nK73AHRJ4C6yMs_rdRkcXAiJXeY0MEYo1pAxX4ugQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-08-20 17:21 ` William Lupton [not found] ` <CAEe_xxjF_GT3XXobnhGizje_U6VDcODV0ubGR0dDN=Dj_U2B3A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-08-20 18:19 ` Clément Aubert
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).