public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Lua Filter: Change image alt= attribute
@ 2023-04-28 15:24 ThomasH
       [not found] ` <0c93ede7-c24c-4a7f-ab8f-1b6b0d6aa7c1n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: ThomasH @ 2023-04-28 15:24 UTC (permalink / raw)
  To: pandoc-discuss


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

I want to change the alt= attribute of an image during translation. This is 
my Lua filter:





*function Image(elem)    nelem = elem:clone()    nelem.attributes.alt = 
'image'    return nelemend*

It doesn't work, though. With HTML like

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
See image: <img src="foo.jpg" alt="foobar"/>
</body>
</html>

I get an AST like this

[ Plain
    [ Str "See"
    , Space
    , Str "image:"
    , Space
    , Image
        ( "" , [] , [ ( "alt" , "image" ) ] )
        [ Str "foobar" ]
        ( "foo.jpg" , "" )
    ]
]

I'm not sure how to interprete the Image part, though. The Markdown output 
is:

See image: ![foobar](foo.jpg){alt="image"}

which shows that the original alt text is retained, and the intended 
replacement text is just added as if an arbitrary attribute.

What is wrong with my filter?

Thanks, T.

-- 
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/0c93ede7-c24c-4a7f-ab8f-1b6b0d6aa7c1n%40googlegroups.com.

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

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

end of thread, other threads:[~2023-04-29 16:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 15:24 Lua Filter: Change image alt= attribute ThomasH
     [not found] ` <0c93ede7-c24c-4a7f-ab8f-1b6b0d6aa7c1n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-04-28 20:58   ` BPJ
     [not found]     ` <CADAJKhD1xpL-Re2M8tUQq8DiZNM=dXNw8tQ=iqWEqrm57g_nzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-04-29 16:32       ` ThomasH

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