From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32822 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: H Newsgroups: gmane.text.pandoc Subject: Re: Inserting attributes into elements Date: Wed, 14 Jun 2023 21:19:50 -0400 Message-ID: <37d8c191-388e-164e-6955-9014b4f0a4a0@meddatainc.com> References: <76a72c07-6699-d243-ae20-64808682ec9e@meddatainc.com> <90C7A30F-C0FA-49D8-B0CD-6521B58113F1@meddatainc.com> <0a6aa41a-fe72-a1e8-2630-ec6070c0bbb3@meddatainc.com> <74253f39-02db-dc2e-2ae1-9d27aaab82ea@meddatainc.com> <61724767-ada0-133f-6751-5884c7460a25@meddatainc.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13251"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCEIZSNSZ4IRBOGOVGSAMGQEB265BSA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Jun 15 03:19:58 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-qt1-f191.google.com ([209.85.160.191]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1q9beW-0003FP-ST for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 15 Jun 2023 03:19:56 +0200 Original-Received: by mail-qt1-f191.google.com with SMTP id d75a77b69052e-3fb2e6ca6eesf5032841cf.1 for ; Wed, 14 Jun 2023 18:19:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686791996; cv=pass; d=google.com; s=arc-20160816; b=Uv0WH0W1Jgbr6ICPQbksqHt2H90lH+KQfVHNIlczoOtDVsgk/UxuE/LqypXIm1doe6 X8S16cJFI6z6B9ZtxWi/Tnm7DmP+BT5r3wiQa5XF+oDcg2tKWr2cCpfqLWRcoqvsW4AJ YN4ldutP1o9vvaHRRFTssqZbfPabdWYKlq8roAYVbNdwSBXhoIVZve5DUmO92OtNGLGc +xSAgGqzthS6PviOeCmZiq0mhoe6YatOHWxXltQreluYZT8V1mezTpLQ060lQ9xEvD2E pDVws45huFt5jAZuWOtQ9dNeV5LglBa9Rz3/QFhmxYzDWs5yRFgm6uzMDtgpE3zZcZ9N tBUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:ui-outboundreport :content-language:content-transfer-encoding:in-reply-to:mime-version :user-agent:date:message-id:from:references:to:subject:sender :dkim-signature; bh=UNlNjiEBk7JoU1dpX/+JmlmdKs/MFa9pxDe1gWrIU7M=; b=QUDPuhoBzRgPkd9G3h7pNn+QQHUiySAwhUDbl2LALXH9/QXyVN6T5JxBzc4ejVC2wY IOolh7ZI/LFkmxFn2dNzzVZrMgX4J+Qg+oq9nyD+7IQf2386m/gl1efL5jpEKNgokgvT cbx9iRNxWadI2M+W+ei3ThfKqYB86F+beL33omfcoXNyIlLasDRAAYWHzh+9Yb4E5ygG AQlimRiwlCdBX0YGTIPrAgaqX8R4PM1yKiJeG+jO5Qm2+p7V2q/dPFowF63AD90bEpIq zcYmbdygGFRbidfLNiOf0+qXZlqV8Li5yL1fJHfhy3EJC180CwTwfTuQJy4js96i+zgI xkKg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org designates 74.208.4.194 as permitted sender) smtp.mailfrom=agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=meddatainc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1686791996; x=1689383996; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :ui-outboundreport:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:sender:from:to:cc:subject:date:message-id:reply-to; bh=UNlNjiEBk7JoU1dpX/+JmlmdKs/MFa9pxDe1gWrIU7M=; b=RoKXeM9uEw/vBDfgwYHQAnqcPWGGODISrANGOxbCe/RYEk6a+HcaQO1NFZo/VFRaQx kyQ2h4nkwDtQ/Ejp3oIx3usihqAo8WqZJwXtJ37maJqeHvEPZrIlEmrzlYNS3NDwsodE 23odeRqFnBhmLauLHm4nYKvexIU0l6gznyGMkLb7brFJCE/GkCf0AVkbf6OyUA/H1Ju9 ykcGESZJkepfK816Dlwk6uIgrWD5uiFUOVT8DBCp7NXwiHQvNgpXEZFY/GBe110JL0Zq X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686791996; x=1689383996; 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-authentication-results:x-original-sender :ui-outboundreport:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:x-beenthere:x-gm-message-state:sender:from:to:cc:subject :date:message-id:reply-to; bh=UNlNjiEBk7JoU1dpX/+JmlmdKs/MFa9pxDe1gWrIU7M=; b=HH+I3sT1CWm3SAAR71wjhTfk9lRvYNnvF+U3YtJFVYvyT/p6J7bQJOGRuRtDShlTGZ ZS+ERhxQqgAQYt6xGGcoiiPjENzmo6zKsGV7PlFAAFgSv5QD+in2o1vlj/z2xyqFDC6E l9E+AQsGT1hm1CjFHx1IkVd275J/X8qnFs7HK/ePbUy8DywU/ornTSo+vvf61HMmwlYC 7Q Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDzyK3r2+sjZ7VnguVBH8+eNQsWTgCvTws8DaiR4aAWaGK3qVtm4 5yXyRv6ayasreSvnCKtrxag= X-Google-Smtp-Source: ACHHUZ5VArZ3zsJU/+8ymCn7KrE/1xrXiA7Ah3TyLfV47T85SQSg8lz4LPJ5srvr8d3eeWxXotSqZg== X-Received: by 2002:a05:622a:1813:b0:3f9:b358:f6f1 with SMTP id t19-20020a05622a181300b003f9b358f6f1mr23307168qtc.1.1686791995943; Wed, 14 Jun 2023 18:19:55 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a25:cbd1:0:b0:b9d:9c6a:32fd with SMTP id b200-20020a25cbd1000000b00b9d9c6a32fdls1720321ybg.0.-pod-prod-05-us; Wed, 14 Jun 2023 18:19:52 -0700 (PDT) X-Received: by 2002:a25:cbd6:0:b0:bca:f2b2:cbf5 with SMTP id b205-20020a25cbd6000000b00bcaf2b2cbf5mr3826682ybg.38.1686791992201; Wed, 14 Jun 2023 18:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686791992; cv=none; d=google.com; s=arc-20160816; b=xHOnHA4mywC26yw2i4g9XCn7W35mKWzG2p3jqa3oLoXuc8CipzxRSNfbc1ZbUd0tG7 Gckj6qvUEktIO0/wHA3X6uBGWDKXCSUGaS4A3zEjnuVEs6e5BqPzu59v7jFsiWtZ5GXg 3DOyS24R1s2FaqePJrSppft0Od1y0xPbhiyvWTQuct+KFB+repmPpBRxAeeK9NO8t94K Q92SMUib78ng7YAa9+WU633ayF6aoBcsMy85Q5tDdjpNOBIzXjokhGzeDVgLgvuUqXNh 0+JP/uJyU8EbpAbvKQj2ZRtIZr7LsJP71Es1EeIE+x425kTXz5jJMfnN64aPdkd2AGCQ +soA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=L4JlKAHWgtc5MUNMjTfAJ+AK2dMaL5khKVBvVbGsJEI=; b=Si6TNrtTbxSRVrzRGJpzXtt+FCDFU2Pqb8dSgU/8L3GosZFFYsrifLwn8hC30ICRar Gstnp4Oy/PLiVFegHHDuhuHRAEgTdmKlG2+lkbciov7IMv3nU17JtetA2lhHdNIb/1lu KUy3F6a+J2yv/xxV/VGcPpWCpg4qpDoQTXCKwVN8Sgzyq0RF5kRII3iFLBZYAftavzi2 i1Y9hfTIo0vPBswFcsLflp06odIewA1Wq8aVKuydRxn6fdUw4iiU1eZcxFjednKmNMIi EetfePxraVarAtjLnomv8YZkjIPdVVYdMpa4knThxa1oaDFIj4xhe82Mky+iiFi2dAq5 7v9Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org designates 74.208.4.194 as permitted sender) smtp.mailfrom=agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=meddatainc.com Original-Received: from mout.perfora.net (mout.perfora.net. [74.208.4.194]) by gmr-mx.google.com with ESMTPS id b62-20020a25cb41000000b00bd612fdd729si326965ybg.4.2023.06.14.18.19.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 18:19:52 -0700 (PDT) Received-SPF: pass (google.com: domain of agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org designates 74.208.4.194 as permitted sender) client-ip=74.208.4.194; Original-Received: from [192.168.1.17] ([72.94.51.172]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0MhSU8-1qV09F19gA-00McjV for ; Thu, 15 Jun 2023 03:19:51 +0200 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:0rTrD+fwxdRlp7HQu/mH34VGSfpqdx90NtHpZZwjF6oJXkiwd6q UnO3CVscGp841wczVntssocb6xTZPW5m0Ot2mcStyk/fEn5bIBAEnWvnl1IYkBoRK1T5TaO 9oHK/4ymS0hk46NNKQentBqqOPYtXea+grnZ72gxSz1HPLkGPJkxLQjhFJfV8HbcrVYm/Ac 2T/UwAuuazJiE02OM7mpw== UI-OutboundReport: notjunk:1;M01:P0:7yVmALWtmAI=;F+l1BUkRdMgMQ1gfr8fR8Bvfcbm BxyFjq5hugAdpRSvz2SUxGx1s0m3U4qRjK+XG3aIislJHQbgg0DtpDCFCKDJFshPRMd6hB9OB qaO4+V3Qz9fqOMWaMtxMfHT0yc+1eZH5i7TCgAgAvaiGPqn9S1/sqWPZdP9IakadCckJoTIYw RRuUHcmxiBaa7Z8xAbce3mry2iaRhEVb9OJkuoOwxXJDJAcsmyqYAF6LDmhN+uIiAK/Rdw2Rw SfHTlAw+lzSYRhICSK0mtHzkE/7ga3dvu8vxws4S5ZvnxHG4HOkNz/MJ9QRJ/kDvBqbny/ooW D7gJC4FKUy5JXP160O0LEb+oZrMxSNVc8Cc5/fjloeZ4Pd6MnJbDnkb9hoUWd5JcHAZ3TVfN7 oICWSLv9D1aVQ7b9VP5CzCjuEoKy1wE8KAJ414lT2wKKTEe4M5hnmqHH4JMNRv7CJOFStKAr4 FIqH3Z+6g1CjHFX7J+UTnqQul7emJNtMhKlvftmcJUB2J4Sul1SW0vYewxfSLSRF45tVhlhq+ CAx8wOvM+FcT9fCSLZ2gP8ZRkZxNcK6xkHi/P37gOLxB+Po2hkaJaPVpD7QtVnV2YMZx9fC0V jKmR6JfY/pa09d/fDRppsFGpM3NfzuEpJ2U5EIgHZjcN3yBEuU/PBefvyxyR137kzlgoD0J6q 76xHUn5seqre6GbS2LV/Ntkty8v+yjfAQ/D6rykBQA== X-Original-Sender: agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org designates 74.208.4.194 as permitted sender) smtp.mailfrom=agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=meddatainc.com 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:32822 Archived-At: On 06/14/2023 01:30 PM, BPJ wrote: > > Pandoc's document module used to not support attributes at all. IIRC attr= ibutes were first introduced for fenced code blocks, then extended to inlin= e code. Spans and divs (in the Pandoc sense) were introduced specifically t= o provide containers for arbitrary content to which attributes can be attac= hed. At the same time (IIRC) attributes were extended to headings ("Header"= ), links and images. It was decided not to extend attributes to other eleme= nts 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 probab= ly came along for the ride together with images. Normally divs and spans ar= e enough for all other cases, because in regular CSS in an external file or= embedded in the `` 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 pro= blems 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 ge= nerate other formats from the source: > > ``````markdown > Para before. > > ```{=3Dhtml} >
> ``` > > Para after > `````` > > You can also use a filter to do things like this: > > ``````lua > local hr_filter =3D { > =C2=A0 HorizontalRule =3D function() > =C2=A0 =C2=A0 return pandoc.RawBlock('html', '
') > =C2=A0 end > } > function Div(div) > =C2=A0 if div.classes:includes('class') then > =C2=A0 =C2=A0 return div:walk(hr_filter).content > =C2=A0 end > end > `````` > =C2=A0=C2=A0 > > I sometimes post-process HTML generated by pandoc with with Mojo::Dom to transfer attributes from wrapping divs= /spans to contained elements and remove the wrapper, or just to set attribu= tes 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. Ad= ding/removing/changing attributes is very easy: you just treat the element = object as if it is a hash (associative array) reference containing the attr= ibutes! Then when you are done you print the document object to a file or s= tdout. > Thank you for the explanation. I did resort to creating the
in t= he filter. Now another problem - I have multiple images in my markdown document and a =
tag pair gets added around the which is fine. However, while processing the
block I want to make changes to the = default style attribute for some of the images. Using the logging m= odule I find e.g.: (#) figure Figure { =C2=A0 attr: Attr { =C2=A0=C2=A0=C2=A0 attributes: AttributeList { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 style: "margin: 0px;" =C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0 classes: List {} =C2=A0=C2=A0=C2=A0 identifier: "" =C2=A0 } =C2=A0 caption: { =C2=A0=C2=A0=C2=A0 long: Blocks {} =C2=A0 } =C2=A0 content: Blocks[1] { =C2=A0=C2=A0=C2=A0 [1] Plain { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 content: Inlines[1] { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [1] Image { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 attr: Attr { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 attribut= es: AttributeList {} =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 classes:= List {} =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 identifi= er: "" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 caption: Inlines[1] = { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [1] Str = "whatever" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 src: "https://www.so= medomain.tld/images/someimage.jpg" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 title: "" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0 } =C2=A0 } } and if look at the logging output for the Image I find: #) image Image { =C2=A0 attr: Attr { =C2=A0=C2=A0=C2=A0 attributes: AttributeList { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 style: "height: auto; width: 100%; object-fi= t: contain;" =C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0 classes: List {} =C2=A0=C2=A0=C2=A0 identifier: "" =C2=A0 } =C2=A0 caption: Inlines[1] { =C2=A0=C2=A0=C2=A0 [1] Str "whatever" =C2=A0 } =C2=A0 src: "https://www.somedomain.tld/images/someimage.jpg" =C2=A0 title: "" } While processing the Figure element in the filter, I want to change the sty= le attributes for the Image listed above. They show up correctly in the log= ging 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? --=20 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 e= mail 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/37d8c191-388e-164e-6955-9014b4f0a4a0%40meddatainc.com.