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-/JYPxA39Uh5TLH3MbocFFw@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-/JYPxA39Uh5TLH3MbocFFw@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.