* Inserting attributes into elements @ 2023-06-13 20:37 H [not found] ` <76a72c07-6699-d243-ae20-64808682ec9e-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-13 20:37 UTC (permalink / raw) To: Pandoc Mailing List Continuing my quest to write a custom filter, I now ran into a need to add attributes to different types of tags as exemplified below: - In header tags such as <h2>, I need to add "style=color: #112233;" so it becomes <h2 style="color: #112233;">. - I analogously also need to add style information to <image> tags. In my filter I tried: style_h2 = if (el.level == 2) then local attr = el.attributes attr.insert = style_h2 end but ended up with the below in my html output: <h2 data-insert=" style="text-transform: uppercase; color: #cc002b;""> Clearly not the correct way. Can I add the style information as above in a filter, in the pandoc function as I am going through my document block-by-block and modifying the document structure as needed? I already adding <div> with various style information as I iterate over the blocks and that works fine but now I need to modify existing tags. I guess I could do it similarly to below but then it applies to all eg H2: function Header(el) -- remove header identifier for all levels el.identifier = '' -- convert level 1 and 2 to upper case if (el.level == 1) or (el.level == 2) then return el:walk { Str = function(el) return pandoc.Str(text.upper(el.text)) end } else return el end end How to do it on individual H2 in a filter? Thanks. -- 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/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com. ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <76a72c07-6699-d243-ae20-64808682ec9e-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <76a72c07-6699-d243-ae20-64808682ec9e-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-13 21:00 ` 'William Lupton' via pandoc-discuss [not found] ` <CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6+4SztxQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: 'William Lupton' via pandoc-discuss @ 2023-06-13 21:00 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 2724 bytes --] As far as I know, you can't add 'style' attributes. But you can embed CSS via header-includes. You'll find an example of this if you search the manual for 'header-includes' (and you can use a filter to set the variable; I think Albert gave an example of how to do this a few weeks ago). On Tue, 13 Jun 2023, 21:37 H, <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > Continuing my quest to write a custom filter, I now ran into a need to add > attributes to different types of tags as exemplified below: > > - In header tags such as <h2>, I need to add "style=color: #112233;" so it > becomes <h2 style="color: #112233;">. > > - I analogously also need to add style information to <image> tags. > > In my filter I tried: > > style_h2 = > > if (el.level == 2) then > local attr = el.attributes > attr.insert = style_h2 > end > > but ended up with the below in my html output: > > <h2 > data-insert=" style="text-transform: uppercase; color: > #cc002b;""> > > Clearly not the correct way. Can I add the style information as above in a > filter, in the pandoc function as I am going through my document > block-by-block and modifying the document structure as needed? I already > adding <div> with various style information as I iterate over the blocks > and that works fine but now I need to modify existing tags. > > I guess I could do it similarly to below but then it applies to all eg H2: > > function Header(el) > -- remove header identifier for all levels > el.identifier = '' > > -- convert level 1 and 2 to upper case > if (el.level == 1) or (el.level == 2) then > return el:walk { > Str = function(el) > return pandoc.Str(text.upper(el.text)) > end > } > else > return el > end > end > > How to do it on individual H2 in a filter? > > Thanks. > > -- > 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/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6%2B4SztxQA%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 3885 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6+4SztxQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6+4SztxQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2023-06-13 21:16 ` H [not found] ` <F6DC033A-83F1-48E8-9947-A372BB0366E7-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-13 21:16 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 3459 bytes --] On June 13, 2023 5:00:19 PM EDT, 'William Lupton' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: >As far as I know, you can't add 'style' attributes. But you can embed >CSS >via header-includes. You'll find an example of this if you search the >manual for 'header-includes' (and you can use a filter to set the >variable; >I think Albert gave an example of how to do this a few weeks ago). > >On Tue, 13 Jun 2023, 21:37 H, <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > >> Continuing my quest to write a custom filter, I now ran into a need >to add >> attributes to different types of tags as exemplified below: >> >> - In header tags such as <h2>, I need to add "style=color: #112233;" >so it >> becomes <h2 style="color: #112233;">. >> >> - I analogously also need to add style information to <image> tags. >> >> In my filter I tried: >> >> style_h2 = >> >> if (el.level == 2) then >> local attr = el.attributes >> attr.insert = style_h2 >> end >> >> but ended up with the below in my html output: >> >> <h2 >> data-insert=" style="text-transform: uppercase; color: >> #cc002b;""> >> >> Clearly not the correct way. Can I add the style information as above >in a >> filter, in the pandoc function as I am going through my document >> block-by-block and modifying the document structure as needed? I >already >> adding <div> with various style information as I iterate over the >blocks >> and that works fine but now I need to modify existing tags. >> >> I guess I could do it similarly to below but then it applies to all >eg H2: >> >> function Header(el) >> -- remove header identifier for all levels >> el.identifier = '' >> >> -- convert level 1 and 2 to upper case >> if (el.level == 1) or (el.level == 2) then >> return el:walk { >> Str = function(el) >> return pandoc.Str(text.upper(el.text)) >> end >> } >> else >> return el >> end >> end >> >> How to do it on individual H2 in a filter? >> >> Thanks. >> >> -- >> 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/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >To view this discussion on the web visit >https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6%2B4SztxQA%40mail.gmail.com. I need to stay away from css since the software the output is used in does not allow css info to be added. -- 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/F6DC033A-83F1-48E8-9947-A372BB0366E7%40meddatainc.com. [-- Attachment #2: Type: text/html, Size: 4532 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <F6DC033A-83F1-48E8-9947-A372BB0366E7-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <F6DC033A-83F1-48E8-9947-A372BB0366E7-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-13 21:19 ` H [not found] ` <90C7A30F-C0FA-49D8-B0CD-6521B58113F1-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-13 21:19 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 3680 bytes --] On June 13, 2023 5:16:32 PM EDT, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: >On June 13, 2023 5:00:19 PM EDT, 'William Lupton' via pandoc-discuss ><pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: >>As far as I know, you can't add 'style' attributes. But you can embed >>CSS >>via header-includes. You'll find an example of this if you search the >>manual for 'header-includes' (and you can use a filter to set the >>variable; >>I think Albert gave an example of how to do this a few weeks ago). >> >>On Tue, 13 Jun 2023, 21:37 H, <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: >> >>> Continuing my quest to write a custom filter, I now ran into a need >>to add >>> attributes to different types of tags as exemplified below: >>> >>> - In header tags such as <h2>, I need to add "style=color: #112233;" >>so it >>> becomes <h2 style="color: #112233;">. >>> >>> - I analogously also need to add style information to <image> tags. >>> >>> In my filter I tried: >>> >>> style_h2 = >>> >>> if (el.level == 2) then >>> local attr = el.attributes >>> attr.insert = style_h2 >>> end >>> >>> but ended up with the below in my html output: >>> >>> <h2 >>> data-insert=" style="text-transform: uppercase; color: >>> #cc002b;""> >>> >>> Clearly not the correct way. Can I add the style information as >above >>in a >>> filter, in the pandoc function as I am going through my document >>> block-by-block and modifying the document structure as needed? I >>already >>> adding <div> with various style information as I iterate over the >>blocks >>> and that works fine but now I need to modify existing tags. >>> >>> I guess I could do it similarly to below but then it applies to all >>eg H2: >>> >>> function Header(el) >>> -- remove header identifier for all levels >>> el.identifier = '' >>> >>> -- convert level 1 and 2 to upper case >>> if (el.level == 1) or (el.level == 2) then >>> return el:walk { >>> Str = function(el) >>> return pandoc.Str(text.upper(el.text)) >>> end >>> } >>> else >>> return el >>> end >>> end >>> >>> How to do it on individual H2 in a filter? >>> >>> Thanks. >>> >>> -- >>> 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/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>To view this discussion on the web visit >>https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6%2B4SztxQA%40mail.gmail.com. > >I need to stay away from css since the software the output is used in >does not allow css info to be added. Can I "rewrite" a tag in the filter? -- 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/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.com. [-- Attachment #2: Type: text/html, Size: 4878 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <90C7A30F-C0FA-49D8-B0CD-6521B58113F1-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <90C7A30F-C0FA-49D8-B0CD-6521B58113F1-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-13 21:27 ` Bastien DUMONT 2023-06-13 21:38 ` 'William Lupton' via pandoc-discuss 2023-06-13 22:05 ` H 0 siblings, 2 replies; 18+ messages in thread From: Bastien DUMONT @ 2023-06-13 21:27 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw You call “insert” as if it were a method of “attr”, but attr is a key-value table. The correct way to add an attribute is: if (el.level == 2) then local attr = el.attributes attr.style = 'color: #112233;' end Le Tuesday 13 June 2023 à 05:19:14PM, H a écrit : > On June 13, 2023 5:16:32 PM EDT, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > > On June 13, 2023 5:00:19 PM EDT, 'William Lupton' via pandoc-discuss > <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: > > As far as I know, you can't add 'style' attributes. But you can embed > CSS via header-includes. You'll find an example of this if you search > the manual for 'header-includes' (and you can use a filter to set the > variable; I think Albert gave an example of how to do this a few weeks > ago). > > On Tue, 13 Jun 2023, 21:37 H, <[1]agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > > Continuing my quest to write a custom filter, I now ran into a need > to add attributes to different types of tags as exemplified below: > > - In header tags such as <h2>, I need to add "style=color: #112233; > " so it becomes <h2 style="color: #112233;">. > > - I analogously also need to add style information to <image> tags. > > In my filter I tried: > > style_h2 = > > if (el.level == 2) then > local attr = el.attributes > attr.insert = style_h2 > end > > but ended up with the below in my html output: > > <h2 > data-insert=" style="text-transform: uppercase; color: # > cc002b;""> > > Clearly not the correct way. Can I add the style information as > above in a filter, in the pandoc function as I am going through my > document block-by-block and modifying the document structure as > needed? I already adding <div> with various style information as I > iterate over the blocks and that works fine but now I need to > modify existing tags. > > I guess I could do it similarly to below but then it applies to all > eg H2: > > function Header(el) > -- remove header identifier for all levels > el.identifier = '' > > -- convert level 1 and 2 to upper case > if (el.level == 1) or (el.level == 2) then > return el:walk { > Str = function(el) > return pandoc.Str(text.upper(el.text)) > end > } > else > return el > end > end > > How to do it on individual H2 in a filter? > > Thanks. > > -- > 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 [2]pandoc-discuss+unsubscribe@googlegroups.com. > To view this discussion on the web visit [3]https:// > groups.google.com/d/msgid/pandoc-discuss/ > 76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com. > > > I need to stay away from css since the software the output is used in does > not allow css info to be added. > > > Can I "rewrite" a tag in the filter? > > -- > 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 [4]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [5]https://groups.google.com/d/msgid/ > pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.com. > > References: > > [1] mailto:agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org > [2] mailto:pandoc-discuss%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [3] https://groups.google.com/d/msgid/pandoc-discuss/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com > [4] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [5] https://groups.google.com/d/msgid/pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.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/ZIjfUqabWGUWcZz2%40localhost. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Inserting attributes into elements 2023-06-13 21:27 ` Bastien DUMONT @ 2023-06-13 21:38 ` 'William Lupton' via pandoc-discuss [not found] ` <CAEe_xxj=P-e03Z6A4BbbqyCAdiCgpxs3cGR8WH_P590Q+bQkWg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2023-06-13 22:05 ` H 1 sibling, 1 reply; 18+ messages in thread From: 'William Lupton' via pandoc-discuss @ 2023-06-13 21:38 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 6119 bytes --] sorry; i was wrong when i said that i thought that you can't add style attributes (i should have checked) of course the style attributes _are_ CSS, but i guess that this is ok for you what do you mean by 'rewriting' a tag? On Tue, 13 Jun 2023 at 22:27, Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> wrote: > You call “insert” as if it were a method of “attr”, but attr is a > key-value table. The correct way to add an attribute is: > > if (el.level == 2) then > local attr = el.attributes > attr.style = 'color: #112233;' > end > > > Le Tuesday 13 June 2023 à 05:19:14PM, H a écrit : > > On June 13, 2023 5:16:32 PM EDT, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > > > > On June 13, 2023 5:00:19 PM EDT, 'William Lupton' via pandoc-discuss > > <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: > > > > As far as I know, you can't add 'style' attributes. But you can > embed > > CSS via header-includes. You'll find an example of this if you > search > > the manual for 'header-includes' (and you can use a filter to > set the > > variable; I think Albert gave an example of how to do this a few > weeks > > ago). > > > > On Tue, 13 Jun 2023, 21:37 H, <[1]agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > > > > Continuing my quest to write a custom filter, I now ran into > a need > > to add attributes to different types of tags as exemplified > below: > > > > - In header tags such as <h2>, I need to add "style=color: > #112233; > > " so it becomes <h2 style="color: #112233;">. > > > > - I analogously also need to add style information to > <image> tags. > > > > In my filter I tried: > > > > style_h2 = > > > > if (el.level == 2) then > > local attr = el.attributes > > attr.insert = style_h2 > > end > > > > but ended up with the below in my html output: > > > > <h2 > > data-insert=" style="text-transform: uppercase; color: # > > cc002b;""> > > > > Clearly not the correct way. Can I add the style information > as > > above in a filter, in the pandoc function as I am going > through my > > document block-by-block and modifying the document structure > as > > needed? I already adding <div> with various style > information as I > > iterate over the blocks and that works fine but now I need to > > modify existing tags. > > > > I guess I could do it similarly to below but then it applies > to all > > eg H2: > > > > function Header(el) > > -- remove header identifier for all levels > > el.identifier = '' > > > > -- convert level 1 and 2 to upper case > > if (el.level == 1) or (el.level == 2) then > > return el:walk { > > Str = function(el) > > return pandoc.Str(text.upper(el.text)) > > end > > } > > else > > return el > > end > > end > > > > How to do it on individual H2 in a filter? > > > > Thanks. > > > > -- > > 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 [2] > pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [3]https:// > > groups.google.com/d/msgid/pandoc-discuss/ > > 76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com. > > > > > > I need to stay away from css since the software the output is used > in does > > not allow css info to be added. > > > > > > Can I "rewrite" a tag in the filter? > > > > -- > > 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 [4]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [5] > https://groups.google.com/d/msgid/ > > pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.com. > > > > References: > > > > [1] mailto:agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org > > [2] mailto:pandoc-discuss%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [3] > https://groups.google.com/d/msgid/pandoc-discuss/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com > > [4] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [5] > https://groups.google.com/d/msgid/pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.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/ZIjfUqabWGUWcZz2%40localhost > . > -- 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_xxj%3DP-e03Z6A4BbbqyCAdiCgpxs3cGR8WH_P590Q%2BbQkWg%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 9353 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <CAEe_xxj=P-e03Z6A4BbbqyCAdiCgpxs3cGR8WH_P590Q+bQkWg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <CAEe_xxj=P-e03Z6A4BbbqyCAdiCgpxs3cGR8WH_P590Q+bQkWg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2023-06-13 21:58 ` H [not found] ` <CA9D2999-4E90-450E-A709-0ECCA45E3494-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-13 21:58 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw On June 13, 2023 5:38:18 PM EDT, 'William Lupton' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: >sorry; i was wrong when i said that i thought that you can't add style >attributes (i should have checked) > >of course the style attributes _are_ CSS, but i guess that this is ok >for >you > >what do you mean by 'rewriting' a tag? > >On Tue, 13 Jun 2023 at 22:27, Bastien DUMONT ><bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> >wrote: > >> You call “insert” as if it were a method of “attr”, but attr is a >> key-value table. The correct way to add an attribute is: >> >> if (el.level == 2) then >> local attr = el.attributes >> attr.style = 'color: #112233;' >> end >> >> >> Le Tuesday 13 June 2023 à 05:19:14PM, H a écrit : >> > On June 13, 2023 5:16:32 PM EDT, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: >> > >> > On June 13, 2023 5:00:19 PM EDT, 'William Lupton' via >pandoc-discuss >> > <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: >> > >> > As far as I know, you can't add 'style' attributes. But you >can >> embed >> > CSS via header-includes. You'll find an example of this if >you >> search >> > the manual for 'header-includes' (and you can use a filter >to >> set the >> > variable; I think Albert gave an example of how to do this >a few >> weeks >> > ago). >> > >> > On Tue, 13 Jun 2023, 21:37 H, <[1]agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> >wrote: >> > >> > Continuing my quest to write a custom filter, I now ran >into >> a need >> > to add attributes to different types of tags as >exemplified >> below: >> > >> > - In header tags such as <h2>, I need to add >"style=color: >> #112233; >> > " so it becomes <h2 style="color: #112233;">. >> > >> > - I analogously also need to add style information to >> <image> tags. >> > >> > In my filter I tried: >> > >> > style_h2 = >> > >> > if (el.level == 2) then >> > local attr = el.attributes >> > attr.insert = style_h2 >> > end >> > >> > but ended up with the below in my html output: >> > >> > <h2 >> > data-insert=" style="text-transform: uppercase; >color: # >> > cc002b;""> >> > >> > Clearly not the correct way. Can I add the style >information >> as >> > above in a filter, in the pandoc function as I am going >> through my >> > document block-by-block and modifying the document >structure >> as >> > needed? I already adding <div> with various style >> information as I >> > iterate over the blocks and that works fine but now I >need to >> > modify existing tags. >> > >> > I guess I could do it similarly to below but then it >applies >> to all >> > eg H2: >> > >> > function Header(el) >> > -- remove header identifier for all levels >> > el.identifier = '' >> > >> > -- convert level 1 and 2 to upper case >> > if (el.level == 1) or (el.level == 2) then >> > return el:walk { >> > Str = function(el) >> > return pandoc.Str(text.upper(el.text)) >> > end >> > } >> > else >> > return el >> > end >> > end >> > >> > How to do it on individual H2 in a filter? >> > >> > Thanks. >> > >> > -- >> > 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 [2] >> pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > To view this discussion on the web visit [3]https:// >> > groups.google.com/d/msgid/pandoc-discuss/ >> > 76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com. >> > >> > >> > I need to stay away from css since the software the output is >used >> in does >> > not allow css info to be added. >> > >> > >> > Can I "rewrite" a tag in the filter? >> > >> > -- >> > 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 [4]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > To view this discussion on the web visit [5] >> https://groups.google.com/d/msgid/ >> > >pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.com. >> > >> > References: >> > >> > [1] mailto:agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org >> > [2] mailto:pandoc-discuss%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> > [3] >> >https://groups.google.com/d/msgid/pandoc-discuss/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com >> > [4] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> > [5] >> >https://groups.google.com/d/msgid/pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.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/ZIjfUqabWGUWcZz2%40localhost >> . >> I used the phrase ”rewriting a tag” to mean creating a new tag from scratch. I then tried pandoc.Header() which does take up to three arguments but I could not create something similar to <H2 style=”blablabla”;>. How do I add style attributes as above? -- 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/CA9D2999-4E90-450E-A709-0ECCA45E3494%40meddatainc.com. ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <CA9D2999-4E90-450E-A709-0ECCA45E3494-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <CA9D2999-4E90-450E-A709-0ECCA45E3494-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-14 6:38 ` 'William Lupton' via pandoc-discuss 0 siblings, 0 replies; 18+ messages in thread From: 'William Lupton' via pandoc-discuss @ 2023-06-14 6:38 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 7997 bytes --] This filter inserts a header before each paragraph. -- https://pandoc.org/lua-filters.html#lua-filter-structure function Para(para) return { -- https://pandoc.org/lua-filters.html#pandoc.header -- https://pandoc.org/lua-filters.html#type-attr pandoc.Header(2, 'Inserted header', {style='blablabla'}), para } end On Tue, 13 Jun 2023 at 23:00, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > On June 13, 2023 5:38:18 PM EDT, 'William Lupton' via pandoc-discuss < > pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: > >sorry; i was wrong when i said that i thought that you can't add style > >attributes (i should have checked) > > > >of course the style attributes _are_ CSS, but i guess that this is ok > >for > >you > > > >what do you mean by 'rewriting' a tag? > > > >On Tue, 13 Jun 2023 at 22:27, Bastien DUMONT > ><bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> > >wrote: > > > >> You call “insert” as if it were a method of “attr”, but attr is a > >> key-value table. The correct way to add an attribute is: > >> > >> if (el.level == 2) then > >> local attr = el.attributes > >> attr.style = 'color: #112233;' > >> end > >> > >> > >> Le Tuesday 13 June 2023 à 05:19:14PM, H a écrit : > >> > On June 13, 2023 5:16:32 PM EDT, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > >> > > >> > On June 13, 2023 5:00:19 PM EDT, 'William Lupton' via > >pandoc-discuss > >> > <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote: > >> > > >> > As far as I know, you can't add 'style' attributes. But you > >can > >> embed > >> > CSS via header-includes. You'll find an example of this if > >you > >> search > >> > the manual for 'header-includes' (and you can use a filter > >to > >> set the > >> > variable; I think Albert gave an example of how to do this > >a few > >> weeks > >> > ago). > >> > > >> > On Tue, 13 Jun 2023, 21:37 H, <[1]agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> > >wrote: > >> > > >> > Continuing my quest to write a custom filter, I now ran > >into > >> a need > >> > to add attributes to different types of tags as > >exemplified > >> below: > >> > > >> > - In header tags such as <h2>, I need to add > >"style=color: > >> #112233; > >> > " so it becomes <h2 style="color: #112233;">. > >> > > >> > - I analogously also need to add style information to > >> <image> tags. > >> > > >> > In my filter I tried: > >> > > >> > style_h2 = > >> > > >> > if (el.level == 2) then > >> > local attr = el.attributes > >> > attr.insert = style_h2 > >> > end > >> > > >> > but ended up with the below in my html output: > >> > > >> > <h2 > >> > data-insert=" style="text-transform: uppercase; > >color: # > >> > cc002b;""> > >> > > >> > Clearly not the correct way. Can I add the style > >information > >> as > >> > above in a filter, in the pandoc function as I am going > >> through my > >> > document block-by-block and modifying the document > >structure > >> as > >> > needed? I already adding <div> with various style > >> information as I > >> > iterate over the blocks and that works fine but now I > >need to > >> > modify existing tags. > >> > > >> > I guess I could do it similarly to below but then it > >applies > >> to all > >> > eg H2: > >> > > >> > function Header(el) > >> > -- remove header identifier for all levels > >> > el.identifier = '' > >> > > >> > -- convert level 1 and 2 to upper case > >> > if (el.level == 1) or (el.level == 2) then > >> > return el:walk { > >> > Str = function(el) > >> > return pandoc.Str(text.upper(el.text)) > >> > end > >> > } > >> > else > >> > return el > >> > end > >> > end > >> > > >> > How to do it on individual H2 in a filter? > >> > > >> > Thanks. > >> > > >> > -- > >> > 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 [2] > >> pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > To view this discussion on the web visit [3]https:// > >> > groups.google.com/d/msgid/pandoc-discuss/ > >> > 76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com. > >> > > >> > > >> > I need to stay away from css since the software the output is > >used > >> in does > >> > not allow css info to be added. > >> > > >> > > >> > Can I "rewrite" a tag in the filter? > >> > > >> > -- > >> > 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 [4]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > To view this discussion on the web visit [5] > >> https://groups.google.com/d/msgid/ > >> > > >pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.com. > >> > > >> > References: > >> > > >> > [1] mailto:agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org > >> > [2] mailto:pandoc-discuss%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > >> > [3] > >> > > > https://groups.google.com/d/msgid/pandoc-discuss/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com > >> > [4] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > >> > [5] > >> > > > https://groups.google.com/d/msgid/pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.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/ZIjfUqabWGUWcZz2%40localhost > >> . > >> > > I used the phrase ”rewriting a tag” to mean creating a new tag from > scratch. I then tried pandoc.Header() which does take up to three arguments > but I could not create something similar to <H2 style=”blablabla”;>. > > How do I add style attributes as above? > > -- > 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/CA9D2999-4E90-450E-A709-0ECCA45E3494%40meddatainc.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxg8edH5Jqj6CHUseoj2R1nE_W63DDtoF_m%2B8WfBcJomww%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 13053 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Inserting attributes into elements 2023-06-13 21:27 ` Bastien DUMONT 2023-06-13 21:38 ` 'William Lupton' via pandoc-discuss @ 2023-06-13 22:05 ` H [not found] ` <0a6aa41a-fe72-a1e8-2630-ec6070c0bbb3-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 1 sibling, 1 reply; 18+ messages in thread From: H @ 2023-06-13 22:05 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw On 06/13/2023 05:27 PM, Bastien DUMONT wrote: > attr.style = 'color: #112233;' Wonderful, many thanks! Btw, I was reading my email in the reverse order or I would have found this before my other post... ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <0a6aa41a-fe72-a1e8-2630-ec6070c0bbb3-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <0a6aa41a-fe72-a1e8-2630-ec6070c0bbb3-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-13 22:53 ` H [not found] ` <74253f39-02db-dc2e-2ae1-9d27aaab82ea-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-13 22:53 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw On 06/13/2023 06:05 PM, H wrote: > On 06/13/2023 05:27 PM, Bastien DUMONT wrote: >> attr.style = 'color: #112233;' > Wonderful, many thanks! Btw, I was reading my email in the reverse order or I would have found this before my other post... > How can I similarly add a style to an <image ...> tag? This <image ...> tag is wrapped inside a <figure> tag. ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <74253f39-02db-dc2e-2ae1-9d27aaab82ea-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <74253f39-02db-dc2e-2ae1-9d27aaab82ea-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-14 0:34 ` H [not found] ` <61724767-ada0-133f-6751-5884c7460a25-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-14 0:34 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw On 06/13/2023 06:53 PM, H wrote: > On 06/13/2023 06:05 PM, H wrote: >> On 06/13/2023 05:27 PM, Bastien DUMONT wrote: >>> attr.style = 'color: #112233;' >> Wonderful, many thanks! Btw, I was reading my email in the reverse order or I would have found this before my other post... >> > How can I similarly add a style to an <image ...> tag? This <image ...> tag is wrapped inside a <figure> tag. > Besides adding a style to <img ...> (Image) elements, I also want to add a style to <hr /> (HorizontalRule). It seems that the following does not work: local style_hr = 'border-top-style: solid; border-top-width: thin; border-color: #cc002b;' if (el.type == 'HorizontalRule') then local attr = el.attributes attr.style = style_hr end The desired output is: <hr style="border-top-style: solid; border-top-width: thin; border-color: #cc002b;" /> Pandoc fails assigning the style, however, adding the code to the html file shows it is valid html code. Have I missed something or might this be a bug? -- 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/61724767-ada0-133f-6751-5884c7460a25%40meddatainc.com. ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <61724767-ada0-133f-6751-5884c7460a25-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <61724767-ada0-133f-6751-5884c7460a25-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-14 6:49 ` Bastien DUMONT 2023-06-14 16:23 ` H 0 siblings, 1 reply; 18+ messages in thread From: Bastien DUMONT @ 2023-06-14 6:49 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw You can learn which elements have an “attributes” field from the doc: https://pandoc.org/lua-filters.html Le Tuesday 13 June 2023 à 08:34:05PM, H a écrit : > On 06/13/2023 06:53 PM, H wrote: > > On 06/13/2023 06:05 PM, H wrote: > >> On 06/13/2023 05:27 PM, Bastien DUMONT wrote: > >>> attr.style = 'color: #112233;' > >> Wonderful, many thanks! Btw, I was reading my email in the reverse order or I would have found this before my other post... > >> > > How can I similarly add a style to an <image ...> tag? This <image ...> tag is wrapped inside a <figure> tag. > > > Besides adding a style to <img ...> (Image) elements, I also want to add a style to <hr /> (HorizontalRule). It seems that the following does not work: > > local style_hr = 'border-top-style: solid; border-top-width: thin; border-color: #cc002b;' > > if (el.type == 'HorizontalRule') then > local attr = el.attributes > attr.style = style_hr > end > > The desired output is: > > <hr style="border-top-style: solid; border-top-width: thin; border-color: #cc002b;" /> > > Pandoc fails assigning the style, however, adding the code to the html file shows it is valid html code. > > Have I missed something or might this be a bug? > > -- > 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/61724767-ada0-133f-6751-5884c7460a25%40meddatainc.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/ZIljDhAA-th045Jn%40localhost. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Inserting attributes into elements 2023-06-14 6:49 ` Bastien DUMONT @ 2023-06-14 16:23 ` H [not found] ` <b696e1f5-0648-c8f0-4117-257896e40f8b-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-14 16:23 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 2477 bytes --] On 06/14/2023 02:49 AM, Bastien DUMONT wrote: > You can learn which elements have an “attributes” field from the doc: https://pandoc.org/lua-filters.html > > Le Tuesday 13 June 2023 à 08:34:05PM, H a écrit : >> On 06/13/2023 06:53 PM, H wrote: >>> On 06/13/2023 06:05 PM, H wrote: >>>> On 06/13/2023 05:27 PM, Bastien DUMONT wrote: >>>>> attr.style = 'color: #112233;' >>>> Wonderful, many thanks! Btw, I was reading my email in the reverse order or I would have found this before my other post... >>>> >>> How can I similarly add a style to an <image ...> tag? This <image ...> tag is wrapped inside a <figure> tag. >>> >> Besides adding a style to <img ...> (Image) elements, I also want to add a style to <hr /> (HorizontalRule). It seems that the following does not work: >> >> local style_hr = 'border-top-style: solid; border-top-width: thin; border-color: #cc002b;' >> >> if (el.type == 'HorizontalRule') then >> local attr = el.attributes >> attr.style = style_hr >> end >> >> The desired output is: >> >> <hr style="border-top-style: solid; border-top-width: thin; border-color: #cc002b;" /> >> >> Pandoc fails assigning the style, however, adding the code to the html file shows it is valid html code. >> >> Have I missed something or might this be a bug? >> >> -- >> 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/61724767-ada0-133f-6751-5884c7460a25%40meddatainc.com. Corre,t in that list HorizontalRule does not have an attributes field but ought it not to have one? My example above is, after all, valid HTML code. I have for now worked around it by creating the desired <hr ... /> tag in my code but it would be much more elegant to to be able to add style information to HorizontalRule. -- 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/b696e1f5-0648-c8f0-4117-257896e40f8b%40meddatainc.com. [-- Attachment #2: Type: text/html, Size: 3898 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <b696e1f5-0648-c8f0-4117-257896e40f8b-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <b696e1f5-0648-c8f0-4117-257896e40f8b-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-14 17:30 ` BPJ [not found] ` <CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT=vfJcUuiRM-dHempA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: BPJ @ 2023-06-14 17:30 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 5652 bytes --] Den ons 14 juni 2023 18:24H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> skrev: > On 06/14/2023 02:49 AM, Bastien DUMONT wrote: > > You can learn which elements have an “attributes” field from the doc: https://pandoc.org/lua-filters.html > > Le Tuesday 13 June 2023 à 08:34:05PM, H a écrit : > > On 06/13/2023 06:53 PM, H wrote: > > On 06/13/2023 06:05 PM, H wrote: > > On 06/13/2023 05:27 PM, Bastien DUMONT wrote: > > attr.style = 'color: #112233;' > > Wonderful, many thanks! Btw, I was reading my email in the reverse order or I would have found this before my other post... > > > How can I similarly add a style to an <image ...> tag? This <image ...> tag is wrapped inside a <figure> tag. > > > Besides adding a style to <img ...> (Image) elements, I also want to add a style to <hr /> (HorizontalRule). It seems that the following does not work: > > local style_hr = 'border-top-style: solid; border-top-width: thin; border-color: #cc002b;' > > if (el.type == 'HorizontalRule') then > local attr = el.attributes > attr.style = style_hr > end > > The desired output is: > > <hr style="border-top-style: solid; border-top-width: thin; border-color: #cc002b;" /> > > Pandoc fails assigning the style, however, adding the code to the html file shows it is valid html code. > > Have I missed something or might this be a bug? > > -- > 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/61724767-ada0-133f-6751-5884c7460a25%40meddatainc.com. > > Corre,t in that list HorizontalRule does not have an attributes field but > ought it not to have one? > Pandoc's document module used to not support attributes at all. IIRC attributes were first introduced for fenced code blocks, then extended to inline code. Spans and divs (in the Pandoc sense) were introduced specifically to provide containers for arbitrary content to which attributes can be attached. At the same time (IIRC) attributes were extended to headings ("Header"), links and images. It was decided not to extend attributes to other elements as that would entail huge changes to the code base. Later when Pandoc's table model was changed the new table model included attributes. Code needs attributes to allow to attach highlighting information to it, and headings and images need them too for various reasons, and links probably came along for the ride together with images. Normally divs and spans are enough for all other cases, because in regular CSS in an external file or embedded in the `<head>` of an HTML document you can use a child selector, e.g. in Markdown you type ``````markdown :::class **** ::: `````` and then you style the rule with ``````css div.class hr { ... } `````` Your imposed limitation of not being able to use external CSS creates problems which most users simply don't have. For the horizontal rule case you can use a raw block to insert the HTML directly, if you are not going to generate other formats from the source: ``````markdown Para before. ```{=html} <hr style="..."> ``` Para after `````` You can also use a filter to do things like this: ``````lua local hr_filter = { HorizontalRule = function() return pandoc.RawBlock('html', '<hr style="...">') end } function Div(div) if div.classes:includes('class') then return div:walk(hr_filter).content end end `````` I sometimes post-process HTML generated by pandoc with with Mojo::Dom < https://metacpan.org/pod/Mojo::DOM> to transfer attributes from wrapping divs/spans to contained elements and remove the wrapper, or just to set attributes to elements contained in wrappers. The API makes such changes very easy. You basically find elements in an HTML document with CSS selectors, then loop through the found elements and change them in-place with Perl code. Adding/removing/changing attributes is very easy: you just treat the element object as if it is a hash (associative array) reference containing the attributes! Then when you are done you print the document object to a file or stdout. My example above is, after all, valid HTML code. I have for now worked > around it by creating the desired <hr ... /> tag in my code but it would be > much more elegant to to be able to add style information to HorizontalRule. > > > -- > 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/b696e1f5-0648-c8f0-4117-257896e40f8b%40meddatainc.com > <https://groups.google.com/d/msgid/pandoc-discuss/b696e1f5-0648-c8f0-4117-257896e40f8b%40meddatainc.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/CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT%3DvfJcUuiRM-dHempA%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 8774 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT=vfJcUuiRM-dHempA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT=vfJcUuiRM-dHempA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2023-06-15 1:19 ` H [not found] ` <37d8c191-388e-164e-6955-9014b4f0a4a0-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 0 siblings, 1 reply; 18+ messages in thread From: H @ 2023-06-15 1:19 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw On 06/14/2023 01:30 PM, BPJ wrote: > > Pandoc's document module used to not support attributes at all. IIRC attributes were first introduced for fenced code blocks, then extended to inline code. Spans and divs (in the Pandoc sense) were introduced specifically to provide containers for arbitrary content to which attributes can be attached. At the same time (IIRC) attributes were extended to headings ("Header"), links and images. It was decided not to extend attributes to other elements as that would entail huge changes to the code base. Later when Pandoc's table model was changed the new table model included attributes. > > Code needs attributes to allow to attach highlighting information to it, and headings and images need them too for various reasons, and links probably came along for the ride together with images. Normally divs and spans are enough for all other cases, because in regular CSS in an external file or embedded in the `<head>` of an HTML document you can use a child selector, e.g. in Markdown you type > > ``````markdown > :::class > **** > ::: > `````` > > and then you style the rule with > > ``````css > div.class hr { ... } > `````` > > Your imposed limitation of not being able to use external CSS creates problems which most users simply don't have. For the horizontal rule case you can use a raw block to insert the HTML directly, if you are not going to generate other formats from the source: > > ``````markdown > Para before. > > ```{=html} > <hr style="..."> > ``` > > Para after > `````` > > You can also use a filter to do things like this: > > ``````lua > local hr_filter = { > HorizontalRule = function() > return pandoc.RawBlock('html', '<hr style="...">') > end > } > function Div(div) > if div.classes:includes('class') then > return div:walk(hr_filter).content > end > end > `````` > > > I sometimes post-process HTML generated by pandoc with with Mojo::Dom <https://metacpan.org/pod/Mojo::DOM> to transfer attributes from wrapping divs/spans to contained elements and remove the wrapper, or just to set attributes to elements contained in wrappers. The API makes such changes very easy. You basically find elements in an HTML document with CSS selectors, then loop through the found elements and change them in-place with Perl code. Adding/removing/changing attributes is very easy: you just treat the element object as if it is a hash (associative array) reference containing the attributes! Then when you are done you print the document object to a file or stdout. > Thank you for the explanation. I did resort to creating the <hr ... /> in the filter. Now another problem - I have multiple images in my markdown document and a <figure></figure> tag pair gets added around the <image> which is fine. However, while processing the <figure> block I want to make changes to the default style attribute <image> for some of the images. Using the logging module I find e.g.: (#) figure Figure { attr: Attr { attributes: AttributeList { style: "margin: 0px;" } classes: List {} identifier: "" } caption: { long: Blocks {} } content: Blocks[1] { [1] Plain { content: Inlines[1] { [1] Image { attr: Attr { attributes: AttributeList {} classes: List {} identifier: "" } caption: Inlines[1] { [1] Str "whatever" } src: "https://www.somedomain.tld/images/someimage.jpg" title: "" } } } } } and if look at the logging output for the Image I find: #) image Image { attr: Attr { attributes: AttributeList { style: "height: auto; width: 100%; object-fit: contain;" } classes: List {} identifier: "" } caption: Inlines[1] { [1] Str "whatever" } src: "https://www.somedomain.tld/images/someimage.jpg" title: "" } While processing the Figure element in the filter, I want to change the style attributes for the Image listed above. They show up correctly in the logging module output for Image above but the logging output for Figure shows an empty list. I thought print(pandoc.utils.stringify(el.content[1].content[1].attr.attributes)) would give me the attributes but it does not. Could this be a bug? -- 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/37d8c191-388e-164e-6955-9014b4f0a4a0%40meddatainc.com. ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <37d8c191-388e-164e-6955-9014b4f0a4a0-FcZObrvlYduBUy7/sJONFg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <37d8c191-388e-164e-6955-9014b4f0a4a0-FcZObrvlYduBUy7/sJONFg@public.gmane.org> @ 2023-06-15 10:13 ` 'William Lupton' via pandoc-discuss 2023-06-15 13:00 ` BPJ 1 sibling, 0 replies; 18+ messages in thread From: 'William Lupton' via pandoc-discuss @ 2023-06-15 10:13 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 6229 bytes --] Can you give an outline of how you're processing Image and Figure elements? If you're changing the image style in Image() and then return the modified image then I would indeed expect this modified image to show up in Figure() (which, with the default traversal order, will be called later). I tried a simple example and it seemed to work as expected. Also note that https://pandoc.org/lua-filters.html#pandoc.utils.stringify expects an element (Pandoc, Meta, Block, or Inline). I guess you can't pass it an https://pandoc.org/lua-filters.html#type-attributes object; when I tried your code I got this error: Error running filter figure.lua: table expected, got AttributeList stack traceback: figure.lua:5: in function 'Figure' On Thu, 15 Jun 2023 at 02:19, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote: > On 06/14/2023 01:30 PM, BPJ wrote: > > > > Pandoc's document module used to not support attributes at all. IIRC > attributes were first introduced for fenced code blocks, then extended to > inline code. Spans and divs (in the Pandoc sense) were introduced > specifically to provide containers for arbitrary content to which > attributes can be attached. At the same time (IIRC) attributes were > extended to headings ("Header"), links and images. It was decided not to > extend attributes to other elements as that would entail huge changes to > the code base. Later when Pandoc's table model was changed the new table > model included attributes. > > > > Code needs attributes to allow to attach highlighting information to it, > and headings and images need them too for various reasons, and links > probably came along for the ride together with images. Normally divs and > spans are enough for all other cases, because in regular CSS in an external > file or embedded in the `<head>` of an HTML document you can use a child > selector, e.g. in Markdown you type > > > > ``````markdown > > :::class > > **** > > ::: > > `````` > > > > and then you style the rule with > > > > ``````css > > div.class hr { ... } > > `````` > > > > Your imposed limitation of not being able to use external CSS creates > problems which most users simply don't have. For the horizontal rule case > you can use a raw block to insert the HTML directly, if you are not going > to generate other formats from the source: > > > > ``````markdown > > Para before. > > > > ```{=html} > > <hr style="..."> > > ``` > > > > Para after > > `````` > > > > You can also use a filter to do things like this: > > > > ``````lua > > local hr_filter = { > > HorizontalRule = function() > > return pandoc.RawBlock('html', '<hr style="...">') > > end > > } > > function Div(div) > > if div.classes:includes('class') then > > return div:walk(hr_filter).content > > end > > end > > `````` > > > > > > I sometimes post-process HTML generated by pandoc with with Mojo::Dom < > https://metacpan.org/pod/Mojo::DOM> to transfer attributes from wrapping > divs/spans to contained elements and remove the wrapper, or just to set > attributes to elements contained in wrappers. The API makes such changes > very easy. You basically find elements in an HTML document with CSS > selectors, then loop through the found elements and change them in-place > with Perl code. Adding/removing/changing attributes is very easy: you just > treat the element object as if it is a hash (associative array) reference > containing the attributes! Then when you are done you print the document > object to a file or stdout. > > > Thank you for the explanation. I did resort to creating the <hr ... /> in > the filter. > > Now another problem - I have multiple images in my markdown document and a > <figure></figure> tag pair gets added around the <image> which is fine. > > However, while processing the <figure> block I want to make changes to the > default style attribute <image> for some of the images. Using the logging > module I find e.g.: > > (#) figure Figure { > attr: Attr { > attributes: AttributeList { > style: "margin: 0px;" > } > classes: List {} > identifier: "" > } > caption: { > long: Blocks {} > } > content: Blocks[1] { > [1] Plain { > content: Inlines[1] { > [1] Image { > attr: Attr { > attributes: AttributeList {} > classes: List {} > identifier: "" > } > caption: Inlines[1] { > [1] Str "whatever" > } > src: "https://www.somedomain.tld/images/someimage.jpg" > title: "" > } > } > } > } > } > > > and if look at the logging output for the Image I find: > > #) image Image { > attr: Attr { > attributes: AttributeList { > style: "height: auto; width: 100%; object-fit: contain;" > } > classes: List {} > identifier: "" > } > caption: Inlines[1] { > [1] Str "whatever" > } > src: "https://www.somedomain.tld/images/someimage.jpg" > title: "" > } > > While processing the Figure element in the filter, I want to change the > style attributes for the Image listed above. They show up correctly in the > logging module output for Image above but the logging output for Figure > shows an empty list. > > I thought > print(pandoc.utils.stringify(el.content[1].content[1].attr.attributes)) > would give me the attributes but it does not. > > Could this be a bug? > > -- > 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/37d8c191-388e-164e-6955-9014b4f0a4a0%40meddatainc.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxiL-3qDCB8EpKca2YpAaAtamAYdX%3DantnbJRHJpzUkWow%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 8465 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Inserting attributes into elements [not found] ` <37d8c191-388e-164e-6955-9014b4f0a4a0-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-15 10:13 ` 'William Lupton' via pandoc-discuss @ 2023-06-15 13:00 ` BPJ [not found] ` <CADAJKhBjJTZki4np=oSfbbcmtBjEahCU4440tRfOh_6TMzSAYw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 1 sibling, 1 reply; 18+ messages in thread From: BPJ @ 2023-06-15 13:00 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 11161 bytes --] Den tors 15 juni 2023 03:20H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> skrev: > On 06/14/2023 01:30 PM, BPJ wrote: > > > > Pandoc's document module used to not support attributes at all. IIRC > attributes were first introduced for fenced code blocks, then extended to > inline code. Spans and divs (in the Pandoc sense) were introduced > specifically to provide containers for arbitrary content to which > attributes can be attached. At the same time (IIRC) attributes were > extended to headings ("Header"), links and images. It was decided not to > extend attributes to other elements as that would entail huge changes to > the code base. Later when Pandoc's table model was changed the new table > model included attributes. > > > > Code needs attributes to allow to attach highlighting information to it, > and headings and images need them too for various reasons, and links > probably came along for the ride together with images. Normally divs and > spans are enough for all other cases, because in regular CSS in an external > file or embedded in the `<head>` of an HTML document you can use a child > selector, e.g. in Markdown you type > > > > ``````markdown > > :::class > > **** > > ::: > > `````` > > > > and then you style the rule with > > > > ``````css > > div.class hr { ... } > > `````` > > > > Your imposed limitation of not being able to use external CSS creates > problems which most users simply don't have. For the horizontal rule case > you can use a raw block to insert the HTML directly, if you are not going > to generate other formats from the source: > > > > ``````markdown > > Para before. > > > > ```{=html} > > <hr style="..."> > > ``` > > > > Para after > > `````` > > > > You can also use a filter to do things like this: > > > > ``````lua > > local hr_filter = { > > HorizontalRule = function() > > return pandoc.RawBlock('html', '<hr style="...">') > > end > > } > > function Div(div) > > if div.classes:includes('class') then > > return div:walk(hr_filter).content > > end > > end > > `````` > > > > > > I sometimes post-process HTML generated by pandoc with with Mojo::Dom < > https://metacpan.org/pod/Mojo::DOM> to transfer attributes from wrapping > divs/spans to contained elements and remove the wrapper, or just to set > attributes to elements contained in wrappers. The API makes such changes > very easy. You basically find elements in an HTML document with CSS > selectors, then loop through the found elements and change them in-place > with Perl code. Adding/removing/changing attributes is very easy: you just > treat the element object as if it is a hash (associative array) reference > containing the attributes! Then when you are done you print the document > object to a file or stdout. > > > Thank you for the explanation. I did resort to creating the <hr ... /> in > the filter. > > Now another problem - I have multiple images in my markdown document and a > <figure></figure> tag pair gets added around the <image> which is fine. > > However, while processing the <figure> block I want to make changes to the > default style attribute <image> for some of the images. Using the logging > module I find e.g.: > > (#) figure Figure { > attr: Attr { > attributes: AttributeList { > style: "margin: 0px;" > } > classes: List {} > identifier: "" > } > caption: { > long: Blocks {} > } > content: Blocks[1] { > [1] Plain { > content: Inlines[1] { > [1] Image { > attr: Attr { > attributes: AttributeList {} > classes: List {} > identifier: "" > } > caption: Inlines[1] { > [1] Str "whatever" > } > src: "https://www.somedomain.tld/images/someimage.jpg" > title: "" > } > } > } > } > } > > > and if look at the logging output for the Image I find: > > #) image Image { > attr: Attr { > attributes: AttributeList { > style: "height: auto; width: 100%; object-fit: contain;" > } > classes: List {} > identifier: "" > } > caption: Inlines[1] { > [1] Str "whatever" > } > src: "https://www.somedomain.tld/images/someimage.jpg" > title: "" > } > > While processing the Figure element in the filter, I want to change the > style attributes for the Image listed above. They show up correctly in the > logging module output for Image above but the logging output for Figure > shows an empty list. > I’m not quite sure what you mean but here are basically two ways to affect only elements inside another element of a certain kind (with a certain tag): A. If you want to do something with all Image elements inside any Figure element you can use a local filter which you apply only to the Figure element. This is done by calling the `:walk(inner_filter)` method on the parent/ancestor element. Some things to keep in mind: a) The `inner_filter` is a table where the keys are element tag names and each value are filter functions to apply to descendants with that tag. b) The `:walk` method does _not_ change the element it is called on. Rather it returns a “copy” with any modifications applied. Thus you have to assign the return value of `?walk` to a variable, or return the return value of `:walk` from the outer filter function in turn. This again can take two forms: 1. If the action of the inner filter function does not access the parent/ancestor element in any way it is probably more efficient (and less cluttered) to define the inner filter only once outside the outer filter function: ```lua -- Define static "inner" filter once local fig_img_filter = { Image = function(img) -- Do something with Image img.attributes.style = 'border: 0.2rem solid black' return img end } -- Main filter function function Figure(fig) -- Apply "inner" filter to images inside the Figure return fig:walk(fig_img_filter) end ``` 2. If on the other hand the inner filter function needs to access the parent/ancestor element you need to define the inner filter inside the outer filter function where the parent is in scope: ```lua function Div(div) -- Test condition on div if div.classes:includes('foo') then -- Apply dynamic filter to nested links return div:walk({ Link = function(lnk) -- Test condition on link if lnk.classes:includes('bar') then -- Copy something from div lnk.attributes.baz = div.attributes.zip else -- Copy something else from div lnk.attributes.baz = div.attributes.zap end return lnk end }).content -- Div is not needed anymore so replace it with its content end end ``` This also illustrates the common situation where a Div or Span is only used to tell the filter what to do to elements inside it. In this case the Div is no longer needed when you have applied the changes to the elements inside it, so rather than returning the Div you return only what is inside it. B. In case you want to do something only with specific descendants of an element you have to walk/check the children at each level manually. Some things to remember: a) You need to check that any child exist separately before accessing its properties, because trying to access properties on a non-existing value is a fatal error. b) Don’t forget to reassign any elements which you have changed to the right place in the structure or the change may not take effect. It’s not all that clear when it is needed so it’s safer to do it always. Here is a more explicit version (with more comments and some extras :-) of my filter for conditionally stripping the Figure around an Image: ```lua function Figure(fig) -- First check that we have exactly one child... if 1 == #fig.content then local child = fig.content[1] -- ...then check that the child is a Plain... if 'Plain' == child.tag then -- ...then check that there is exactly one grandchild... if 1 == #child.content then local grandchild = child.content[1] -- ...and that the grandchild is an Image. if 'Image' == grandchild.tag then -- Bingo! -- Now do we want it to be a figure? if grandchild.classes:includes('fig') then grandchild.attributes.style = style_for_img_in_fig -- Put grandchild back child.content[1] = grandchild -- Put child back fig.content[1] = child fig.attributes.style = style_for_figs -- Done with figure return fig end -- else if a standalone image grandchild.attributes.style = style_for_img -- Don't want the fig so return the image! return granchild end end end end -- If not all the conditions hold return nil end ``` (Note: the `style_for_*` variables aren’t actually defined in this code; they are just placeholders for some strings!) > I thought > print(pandoc.utils.stringify(el.content[1].content[1].attr.attributes)) > would give me the attributes but it does not. > `pandoc.utils.stringify` concatenates and returns the Str element values in its argument, which must be an element object. The attributes of an element don't meet any of those two descriptions, but they are an object with custom stringification (in the Lua sense) so you can just say `print(element.attributes)` to inspect them. > Could this be a bug? > No. > -- > 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/37d8c191-388e-164e-6955-9014b4f0a4a0%40meddatainc.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhBjJTZki4np%3DoSfbbcmtBjEahCU4440tRfOh_6TMzSAYw%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 16463 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <CADAJKhBjJTZki4np=oSfbbcmtBjEahCU4440tRfOh_6TMzSAYw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Inserting attributes into elements [not found] ` <CADAJKhBjJTZki4np=oSfbbcmtBjEahCU4440tRfOh_6TMzSAYw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2023-06-16 1:12 ` H 0 siblings, 0 replies; 18+ messages in thread From: H @ 2023-06-16 1:12 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 11966 bytes --] On 06/15/2023 09:00 AM, BPJ wrote: > > > Den tors 15 juni 2023 03:20H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org <mailto:agents@meddatainc.com>> skrev: > > On 06/14/2023 01:30 PM, BPJ wrote: > > > > Pandoc's document module used to not support attributes at all. IIRC attributes were first introduced for fenced code blocks, then extended to inline code. Spans and divs (in the Pandoc sense) were introduced specifically to provide containers for arbitrary content to which attributes can be attached. At the same time (IIRC) attributes were extended to headings ("Header"), links and images. It was decided not to extend attributes to other elements as that would entail huge changes to the code base. Later when Pandoc's table model was changed the new table model included attributes. > > > > Code needs attributes to allow to attach highlighting information to it, and headings and images need them too for various reasons, and links probably came along for the ride together with images. Normally divs and spans are enough for all other cases, because in regular CSS in an external file or embedded in the `<head>` of an HTML document you can use a child selector, e.g. in Markdown you type > > > > ``````markdown > > :::class > > **** > > ::: > > `````` > > > > and then you style the rule with > > > > ``````css > > div.class hr { ... } > > `````` > > > > Your imposed limitation of not being able to use external CSS creates problems which most users simply don't have. For the horizontal rule case you can use a raw block to insert the HTML directly, if you are not going to generate other formats from the source: > > > > ``````markdown > > Para before. > > > > ```{=html} > > <hr style="..."> > > ``` > > > > Para after > > `````` > > > > You can also use a filter to do things like this: > > > > ``````lua > > local hr_filter = { > > HorizontalRule = function() > > return pandoc.RawBlock('html', '<hr style="...">') > > end > > } > > function Div(div) > > if div.classes:includes('class') then > > return div:walk(hr_filter).content > > end > > end > > `````` > > > > > > I sometimes post-process HTML generated by pandoc with with Mojo::Dom <https://metacpan.org/pod/Mojo::DOM> to transfer attributes from wrapping divs/spans to contained elements and remove the wrapper, or just to set attributes to elements contained in wrappers. The API makes such changes very easy. You basically find elements in an HTML document with CSS selectors, then loop through the found elements and change them in-place with Perl code. Adding/removing/changing attributes is very easy: you just treat the element object as if it is a hash (associative array) reference containing the attributes! Then when you are done you print the document object to a file or stdout. > > > Thank you for the explanation. I did resort to creating the <hr ... /> in the filter. > > Now another problem - I have multiple images in my markdown document and a <figure></figure> tag pair gets added around the <image> which is fine. > > However, while processing the <figure> block I want to make changes to the default style attribute <image> for some of the images. Using the logging module I find e.g.: > > (#) figure Figure { > attr: Attr { > attributes: AttributeList { > style: "margin: 0px;" > } > classes: List {} > identifier: "" > } > caption: { > long: Blocks {} > } > content: Blocks[1] { > [1] Plain { > content: Inlines[1] { > [1] Image { > attr: Attr { > attributes: AttributeList {} > classes: List {} > identifier: "" > } > caption: Inlines[1] { > [1] Str "whatever" > } > src: "https://www.somedomain.tld/images/someimage.jpg" > title: "" > } > } > } > } > } > > > and if look at the logging output for the Image I find: > > #) image Image { > attr: Attr { > attributes: AttributeList { > style: "height: auto; width: 100%; object-fit: contain;" > } > classes: List {} > identifier: "" > } > caption: Inlines[1] { > [1] Str "whatever" > } > src: "https://www.somedomain.tld/images/someimage.jpg" > title: "" > } > > While processing the Figure element in the filter, I want to change the style attributes for the Image listed above. They show up correctly in the logging module output for Image above but the logging output for Figure shows an empty list. > > > > > I’m not quite sure what you mean but here are basically two ways to affect only elements inside another element of a certain kind (with a certain tag): > > A. If you want to do something with all Image elements inside any Figure element you can use a local filter which you apply only to the Figure element. This is done by calling the `:walk(inner_filter)` method on the parent/ancestor element. > > Some things to keep in mind: > > a) The `inner_filter` is a table where the keys are element tag names and each value are filter functions to apply to descendants with that tag. > b) The `:walk` method does _not_ change the element it is called on. Rather it returns a “copy” with any modifications applied. Thus you have to assign the return value of `?walk` to a variable, or return the return value of `:walk` from the outer filter function in turn. > > This again can take two forms: > > 1. If the action of the inner filter function does not access the parent/ancestor element in any way it is probably more efficient (and less cluttered) to define the inner filter only once outside the outer filter function: > > ```lua > -- Define static "inner" filter once > local fig_img_filter = { > Image = function(img) > -- Do something with Image > img.attributes.style = 'border: 0.2rem solid black' > return img > end > } > > -- Main filter function > function Figure(fig) > -- Apply "inner" filter to images inside the Figure > return fig:walk(fig_img_filter) > end > ``` > > 2. If on the other hand the inner filter function needs to access the parent/ancestor element you need to define the inner filter inside the outer filter function where the parent is in scope: > > ```lua > function Div(div) > -- Test condition on div > if div.classes:includes('foo') then > -- Apply dynamic filter to nested links > return div:walk({ > Link = function(lnk) > -- Test condition on link > if lnk.classes:includes('bar') then > -- Copy something from div > lnk.attributes.baz = div.attributes.zip > else > -- Copy something else from div > lnk.attributes.baz = div.attributes.zap > end > return lnk > end > }).content > -- Div is not needed anymore so replace it with its content > end > end > ``` > > This also illustrates the common situation where a Div or Span is only used to tell the filter what to do to elements inside it. In this case the Div is no longer needed when you have applied the changes to the elements inside it, so rather than returning the Div you return only what is inside it. > > B. In case you want to do something only with specific descendants of an element you have to walk/check the children at each level manually. > > Some things to remember: > > a) You need to check that any child exist separately before accessing its properties, because trying to access properties on a non-existing value is a fatal error. > b) Don’t forget to reassign any elements which you have changed to the right place in the structure or the change may not take effect. It’s not all that clear when it is needed so it’s safer to do it always. > > Here is a more explicit version (with more comments and some extras :-) of my filter for conditionally stripping the Figure around an Image: > > ```lua > function Figure(fig) > -- First check that we have exactly one child... > if 1 == #fig.content then > local child = fig.content[1] > -- ...then check that the child is a Plain... > if 'Plain' == child.tag then > -- ...then check that there is exactly one grandchild... > if 1 == #child.content then > local grandchild = child.content[1] > -- ...and that the grandchild is an Image. > if 'Image' == grandchild.tag then > -- Bingo! > -- Now do we want it to be a figure? > if grandchild.classes:includes('fig') then > grandchild.attributes.style = style_for_img_in_fig > -- Put grandchild back > child.content[1] = grandchild > -- Put child back > fig.content[1] = child > fig.attributes.style = style_for_figs > -- Done with figure > return fig > end > -- else if a standalone image > grandchild.attributes.style = style_for_img > -- Don't want the fig so return the image! > return granchild > end > end > end > end > -- If not all the conditions hold > return nil > end > ``` > > (Note: the `style_for_*` variables aren’t actually defined in this code; they are just placeholders for some strings!) > > > > I thought > print(pandoc.utils.stringify(el.content[1].content[1].attr.attributes)) > would give me the attributes but it does not. > > > `pandoc.utils.stringify` concatenates and returns the Str element values in its argument, which must be an element object. The attributes of an element don't meet any of those two descriptions, but they are an object with custom stringification (in the Lua sense) so you can just say `print(element.attributes)` to inspect them. > > > > Could this be a bug? > > > No. Thank you for your thorough and excellent explanation! -- 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/0104c4b7-c583-c8d4-75ab-87eea44c07d5%40meddatainc.com. [-- Attachment #2: Type: text/html, Size: 21084 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2023-06-16 1:12 UTC | newest] Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-06-13 20:37 Inserting attributes into elements H [not found] ` <76a72c07-6699-d243-ae20-64808682ec9e-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-13 21:00 ` 'William Lupton' via pandoc-discuss [not found] ` <CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6+4SztxQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2023-06-13 21:16 ` H [not found] ` <F6DC033A-83F1-48E8-9947-A372BB0366E7-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-13 21:19 ` H [not found] ` <90C7A30F-C0FA-49D8-B0CD-6521B58113F1-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-13 21:27 ` Bastien DUMONT 2023-06-13 21:38 ` 'William Lupton' via pandoc-discuss [not found] ` <CAEe_xxj=P-e03Z6A4BbbqyCAdiCgpxs3cGR8WH_P590Q+bQkWg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2023-06-13 21:58 ` H [not found] ` <CA9D2999-4E90-450E-A709-0ECCA45E3494-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-14 6:38 ` 'William Lupton' via pandoc-discuss 2023-06-13 22:05 ` H [not found] ` <0a6aa41a-fe72-a1e8-2630-ec6070c0bbb3-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-13 22:53 ` H [not found] ` <74253f39-02db-dc2e-2ae1-9d27aaab82ea-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-14 0:34 ` H [not found] ` <61724767-ada0-133f-6751-5884c7460a25-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-14 6:49 ` Bastien DUMONT 2023-06-14 16:23 ` H [not found] ` <b696e1f5-0648-c8f0-4117-257896e40f8b-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-14 17:30 ` BPJ [not found] ` <CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT=vfJcUuiRM-dHempA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2023-06-15 1:19 ` H [not found] ` <37d8c191-388e-164e-6955-9014b4f0a4a0-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 2023-06-15 10:13 ` 'William Lupton' via pandoc-discuss 2023-06-15 13:00 ` BPJ [not found] ` <CADAJKhBjJTZki4np=oSfbbcmtBjEahCU4440tRfOh_6TMzSAYw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2023-06-16 1:12 ` H
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).