Hi,

This would indeed be significantly harder than conversion the other way around.

Your approach using RawInline is probably the best one.

GPT4 tells me it is possible in Docx this way (xml):

<w:pict> <v:shape id="_x0000_i1025" type="#_x0000_t75" style="width:300pt;height:200pt"> <v:imagedata r:id="rId5" o:title="Image Description"/> <w10:wrap type="square" anchorx="column" anchory="line"/> <v:stroke color="black" weight="1pt"/> <!-- Specify the border color and weight here --> </v:shape> </w:pict>
.
Then possibly you could try a filter like this?

  1. function Image (img)
  2.  
  3. align = 'left'
  4. for k, v in pairs(img.classes) do
  5. if v == 'center' then
  6. align = 'center'
  7. elseif v == 'right' then
  8. align = 'right'
  9. end
  10. end
  11.  
  12. border_code = '<v:stroke color="black" weight="1pt"/>'
  13.  
  14. ret_img = {
  15. pandoc.RawInline('openxml', string.format('<w:pPr><w:jc w:val="%s"/></w:pPr>', align)),
  16. pandoc.RawInline('openxml', '<w:pict><v:shape type="#_x0000_t75">'),
  17. pandoc.RawInline('openxml', border_code),
  18. img,
  19. pandoc.RawInline('openxml', '</v:shape></w:pict>'),
  20. }
  21.  
  22. return ret_img
  23. end

Hope I was of any help

Stephan.


On Thursday, 27 April 2023 at 15:29:12 UTC+2 Oskar Wood Hansen wrote:
When i convert from markdown to docx I would like to use a luafilter to add styling to my images. I have a css snippet that does the styling I want within obsidian, but this doesnt affect pandoc conversion to docx. I also have another luafiler that emables to center-align the images i want (I haven't written it my self). Ideally I'd like to have another luafilter, that enables me to toggle the custom styling (add borders) to my images.

The working luafilter to align:

function Image (img)

  align = 'left'
  for k, v in pairs(img.classes) do
    if v == 'center' then
      align = 'center'
    elseif v == 'right' then
      align = 'right'
    end
  end
 
  ret_img = {
     pandoc.RawInline('openxml', string.format('<w:pPr><w:jc w:val="%s"/></w:pPr>', align)),
     img
  }

  return ret_img
end


which allows me to add ![text that isnt transferred to docx anyway](imgpath.png){.center}.

The CCS to add border styling is simple:
img {
  border: 1px solid #d8d5d4;
  padding: 5px;
  border-radius: 5px;
}

I would also like to be able to invoke that with for instance .border.

I've been searching for a full day, trying different things out - so I hope my possible rookie question is acceptable.

also once again praise to talber and jgm and co!

--
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/cbcc1adb-41bd-449a-9fc3-f3410f1e6e5bn%40googlegroups.com.