From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32501 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: ThomasH Newsgroups: gmane.text.pandoc Subject: Lua Filter: Change image alt= attribute Date: Fri, 28 Apr 2023 08:24:38 -0700 (PDT) Message-ID: <0c93ede7-c24c-4a7f-ab8f-1b6b0d6aa7c1n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_4126_1282422821.1682695478992" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25542"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCOJJAXZ7EPBBN6KV6RAMGQER3N7B3A-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Apr 28 17:24:44 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oa1-f58.google.com ([209.85.160.58]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1psPxk-0006Pz-22 for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 28 Apr 2023 17:24:44 +0200 Original-Received: by mail-oa1-f58.google.com with SMTP id 586e51a60fabf-188055f1e9esf59974fac.2 for ; Fri, 28 Apr 2023 08:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1682695483; x=1685287483; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:message-id:to:from:date:sender:from:to:cc :subject:date:message-id:reply-to; bh=OfF4fWHM24pCu2iI5+7hEvQ+z9Ak76z5i7/LQBC8mwc=; b=ZWJw+MXaoj17yFvaEDA86n4Bbvb6M5jFlPWWWpzAhYfYN2JURzIPcnwqEeNCtLXGvU igyHggLxCUWYK374TIbZEc7p3mWeuKCLVsUDoGECvtm7GaWOVpjpDfI185Y/zHnWToWv 2XcejNqMSZG87OnmVhMYp8HVKujMrX/XvANi+Zlr/wArWeZ2ERkUDI+Y3qy3+LyiT2be 0kFd32DPZb63e3o/ZanvXYII2MB2Q8EAsLoOOGvehXGYYZ2yFw+77XvC0psRoAvauQ2v Yijsw9oFfGuJO3vnN488x2Jis9z4Td/+3Ono4L3s0jrAABp9kH3B7ejrei4rbUTtBAia HDrg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682695483; x=1685287483; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:message-id:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=OfF4fWHM24pCu2iI5+7hEvQ+z9Ak76z5i7/LQBC8mwc=; b=smFZeY6USuy3BXozZG0UgCTLn7sRSCexDkY22ZCksdZri8ULbe1kYi0VP2JGo4ZgM/ NBUcTtaXUH7L8+NVZGam0E2UhitegqNtA+0JuUIJ5GDKftWRD0TJcSbdk+xAbln/em19 Bz+VWjLgmnX9M1Poeo7aZb2kUoR72G5W/J21TDN8w/pP26F3ZfTkB/HxUnMls6cFfwr3 upAux328spCZj9TdoyxjcQ9Kx+gU8IK7er6MI7UKNc6sTMjAD16BLrMhitf+tS3WTMvS w31yipZHcUWrB5D+pyltqtPGeli6ss88mv2ADewSWdnI8dw2Ot71+czvUvz3jydHv7YH jE7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682695483; x=1685287483; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-sender:mime-version:subject:message-id:to:from:date :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=OfF4fWHM24pCu2iI5+7hEvQ+z9Ak76z5i7/LQBC8mwc=; b=iU8p+b9nRahibktwHWJr0R/ohQCGMOrwfEj3mF2FOdH8NijoefigiiYSsb33WGfrjl ykLKEZeelqw2H0lYQ7JQzfsQPqtJjuzzB7RwQtQ3ETLTdxBUiNO17BMnlkqGv3rx9JfS hJVxFadidlqpHhy5KjBtL79bBnJI16bok+ifQmPfv0E6+tcP6NURzes03vgco3BFw3Ss e5kVStn/RFsSu0Y+dOoUrQfQrHQk1u71dG6zE0yKb10LgiodoIsFkRuHkk2Z8VwaZ06x zpqEHSwp6EbM8wFR21vXHfJ4DxYXry69bhNuuPBzSE5aLodQ38nBDFiASiJ7fynxUhsc Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDwf9P04AfrPD8wrmjR8aEg6ZJVSp/vHOB0g4RxaJ37BQBdiDmX1 32407ZyGE1JJvdKzuIoUNIw= X-Google-Smtp-Source: ACHHUZ4dIafil541EM+NzB32Pc7mUSxI02i/KF03kr0C+li3GPFLV/34jqtrONRn/s1bkkic7MCOFQ== X-Received: by 2002:a05:6871:10b:b0:17e:71a3:e509 with SMTP id y11-20020a056871010b00b0017e71a3e509mr2313010oab.8.1682695482808; Fri, 28 Apr 2023 08:24:42 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6808:1206:b0:38e:2841:4685 with SMTP id a6-20020a056808120600b0038e28414685ls1251290oil.5.-pod-prod-gmail; Fri, 28 Apr 2023 08:24:39 -0700 (PDT) X-Received: by 2002:aca:a992:0:b0:38d:e097:ac98 with SMTP id s140-20020acaa992000000b0038de097ac98mr1421815oie.6.1682695479520; Fri, 28 Apr 2023 08:24:39 -0700 (PDT) X-Original-Sender: therch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:32501 Archived-At: ------=_Part_4126_1282422821.1682695478992 Content-Type: multipart/alternative; boundary="----=_Part_4127_377612241.1682695478992" ------=_Part_4127_377612241.1682695478992 Content-Type: text/plain; charset="UTF-8" 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 See image: foobar 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. ------=_Part_4127_377612241.1682695478992 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I want to change the alt=3D attribute of an image during translation. = This is my Lua filter:

function Image(elem)=C2=A0 =C2=A0 nelem =3D elem:clone()
=C2=A0 =C2=A0 nelem.attribute= s.alt =3D 'image'
=C2=A0 =C2=A0 return nelem
end
It doesn't work, though. With HTML like

<?xml version=3D"1.0" encoding=3D"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=3D"foo.jp= g" alt=3D"foobar"/>
</body>
</html>

I get an AST like this

[ Plain
=C2=A0 =C2=A0 [ Str "See"
=C2=A0 =C2=A0 , Space
=C2=A0 =C2=A0 , = Str "image:"
=C2=A0 =C2=A0 , Space
=C2=A0 =C2=A0 , Image
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 ( "" , [] , [ ( "alt" , "image" ) ] )
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 [ Str "foobar" ]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ( "f= oo.jpg" , "" )
=C2=A0 =C2=A0 ]
]

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

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

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

What is wrong with my filter?

Thanks, T.

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
------=_Part_4127_377612241.1682695478992-- ------=_Part_4126_1282422821.1682695478992--