public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Manipulate Image in DOCX -> HTML using Lua Filter
@ 2019-08-09 19:53 Ken Dow
       [not found] ` <2ad2cd23-4cc0-4e2a-bf07-bd2f09e2ae03-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Ken Dow @ 2019-08-09 19:53 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 754 bytes --]

I'd like to modify the attributes of all images from a DOCX conversion to 
HTML in a Lua filter. So far:

function Image(el)
   el.classes = {"image"}
--   el.attributes = {"style", "mu"}
   return el
end


This el.classes line sets  the `img` class = "image". The el.attributes 
line removes the `img` tag from the output. What am I missing? 

-- 
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/2ad2cd23-4cc0-4e2a-bf07-bd2f09e2ae03%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 2421 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Manipulate Image in DOCX -> HTML using Lua Filter
       [not found] ` <2ad2cd23-4cc0-4e2a-bf07-bd2f09e2ae03-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-08-10 12:41   ` Ken Dow
       [not found]     ` <9c5993b8-c9ec-4b14-9702-f0279ace3e6f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Ken Dow @ 2019-08-10 12:41 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1245 bytes --]

The following removes the `style="width100;height:100"` altogether, which 
is what I wanted:

function Image(el)
  el.attributes = {}
  return el
end


But this doesn't set anything - it also completely removes the style 
attribute. So I still don't understand see how `el.attributes` is supposed 
to work for images:

function Image(el)
  el.attributes = {["width"] = 101, ["height"] = 102}
  return el
end


On Friday, 9 August 2019 15:53:07 UTC-4, Ken Dow wrote:
>
> I'd like to modify the attributes of all images from a DOCX conversion to 
> HTML in a Lua filter. So far:
>
> function Image(el)
>    el.classes = {"image"}
> --   el.attributes = {"style", "mu"}
>    return el
> end
>
>
> This el.classes line sets  the `img` class = "image". The el.attributes 
> line removes the `img` tag from the output. What am I missing? 
>

-- 
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/9c5993b8-c9ec-4b14-9702-f0279ace3e6f%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 6891 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Manipulate Image in DOCX -> HTML using Lua Filter
       [not found]     ` <9c5993b8-c9ec-4b14-9702-f0279ace3e6f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-08-10 17:07       ` Albert Krewinkel
  0 siblings, 0 replies; 3+ messages in thread
From: Albert Krewinkel @ 2019-08-10 17:07 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Ken Dow writes:

> The following removes the `style="width100;height:100"` altogether, which is what I wanted:
>
> function Image(el)
>   el.attributes = {}
>   return el
> end
>
> But this doesn't set anything - it also completely removes the style
> attribute. So I still don't understand see how `el.attributes` is
> supposed to work for images:
>
> function Image(el)
>   el.attributes = {["width"] = 101, ["height"] = 102}
>   return el
> end

Those are reasonable assumptions to make. The problems stems from the
fact that `el.attributes` isn't actually a key-value table, but a list
of tuples in disguise. Try this:

    el.attributes = {{"width", 101}, {"height", 102}}

We do this to preserve attribute order, which is not possible with a
plain key-value table.  There is some Lua-magic in place which makes the
attributes behave *as if* it was a key-value table, but it isn't. That
is why pandoc gets confused here.

Could you raise an issue over at https://github.com/jgm/pandoc/issues?
Your code is absolutely reasonable and we should make it work in the way
one would expect.


PS: Alternative solution: go via the `Attr` function, which deals with
    these tables in the way you expected.

        function Image (img)
          img.attr = pandoc.Attr(img.id, img.classes, {width=100, height=100})
          return img
        end


--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-10 17:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-09 19:53 Manipulate Image in DOCX -> HTML using Lua Filter Ken Dow
     [not found] ` <2ad2cd23-4cc0-4e2a-bf07-bd2f09e2ae03-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-08-10 12:41   ` Ken Dow
     [not found]     ` <9c5993b8-c9ec-4b14-9702-f0279ace3e6f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-08-10 17:07       ` Albert Krewinkel

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).