From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32855 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: Wrapping sections of existing document in
Date: Wed, 21 Jun 2023 17:36:48 +0200 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000dd710b05fea58940" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29890"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBHFSZSSAMGQE6SAT5AA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jun 21 17:37:04 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-qv1-f56.google.com ([209.85.219.56]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qBztI-0007Zj-49 for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 21 Jun 2023 17:37:04 +0200 Original-Received: by mail-qv1-f56.google.com with SMTP id 6a1803df08f44-62de65b3a5bsf82443616d6.2 for ; Wed, 21 Jun 2023 08:37:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687361823; cv=pass; d=google.com; s=arc-20160816; b=CsbkwnXeuMz7aKiMXOTbP/fs6zu//eTjWAex2+FjWLXcH1TKSZ3s43RoVtDkoWQuok oDHzleWT+aPbi3oqpo++kIGje9h/lr/71I+Eicjihd3HvLT9WLqgZisweRnPTNM7ujtq 3IyWxSyQcK4wSQL8d1Q9OUPzwGtY/vTICtdA/DXbUb2PHLV/c/OQvMah6xxqYgVA0YQ4 F9r7N1l0xINdSyPctEbfzuTsGJ/tUIWfPfhuhIRe9rk7vkEwlJsDcMuBeGcDCZYbppCR nfzJcvjdu0JEbJngSj0L0NOQgRfBpZTXfCXm/vIfEIqDFxkwgdXs5hN7A1HqMpdr6xGv ywPg== 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:to:subject:message-id:date :from:in-reply-to:references:mime-version:sender:dkim-signature :dkim-signature; bh=VS6cg9qPimYgCAH+m55L982dFEE3U7yAEGvgXhb7Wxg=; b=kdeB0/8BDxYAWhIUfM3hB9K9Jh8vSf8tSzuW0LrNWuTpDu+QhG+zqDd3A2wSTRdoyN a+u05xdGTPHo+iPz4m6bx+PdBwzPS8p+20ONsBNO17ys59eI2cysn0o3rFE7RdyttVzk aWURdksyMnnWiOFoZIjmjh7KJNt7zdG7QSn77WCoCYWjSCk4jUkIc/Meo2dk1Id1PJTl KuNZCWW9uoErtfKNLbnefjRvX8YWE5RLYtOfLJHL1ezoEx+X1eo/DKR0pvb6avp1yuEF 6itGXQ/dBRLGbbQyZw79Hs+4NwxcpkedRok2qxdkzrgnzKCIWgc3YnqygYmzXo2y2TSh zGvA== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fhqIX1o5; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::b34 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1687361823; x=1689953823; 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:to:subject :message-id:date:from:in-reply-to:references:mime-version:sender :from:to:cc:subject:date:message-id:reply-to; bh=VS6cg9qPimYgCAH+m55L982dFEE3U7yAEGvgXhb7Wxg=; b=FyprAyavp9w+YyYWbHAFz4Rpltx9FNJmCaQtfAFwT13hw+t4Usw1QktNkvg4XgKvkj GqTFsxqj3AkHfThmMzFsq9BjvENAZM5SvLH35pyC+GpjCElRTrc8dyTL5rEF21LGcGNk k+3/h8wlkbITfghPesu+mAglwjmF3HqcpNm2D0qpvT7XUhkqlFJGYVYP+0xcv/tePfmN CH/rFYkJigFPnocjFoi6+VTqX3YAg/G3sSbYz+K+PEXFY+JYs11iybGuzCVgV55pJ0yN kZ4ibKMsyO/zkFj6kvSPNDYNwKC3amplKJapzL+rKxl5L64YNGQ5i91X/283loOPoO9f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687361823; x=1689953823; 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:to:subject :message-id:date:from:in-reply-to:references:mime-version:from:to:cc :subject:date:message-id:reply-to; bh=VS6cg9qPimYgCAH+m55L982dFEE3U7yAEGvgXhb7Wxg=; b=qDniuhgNnhY8xrAM9A8fpz72BW8lhHrfTAXGGW/8QQEbgw1t3DbSZPtsN5e9GvqdNt XB3gYRWUBs0kt9k9uj1GldV+DHmUQ8FZPryskzxHr/23Dca+VjgDwbA8+03NtwOYN6RH Dg4UMbIKs8W7FDz5geLSYPCuaVkI8u1blscG10jI4UdpNwrkI4hxFjAD1dyniRmHnhZj 5CdhHzjqlttOrGpzM+sv1r7tcPkoaU81ylWtCNk2bHhyXBWYwjGKj9D1wT7Djs27iQXZ haEFUsrVEJgSKw66hdm8qIAeD2cZ9bgAZM92vyQ/EwmnFdtJ2YvaqfXB6LnRFRlqo20f F5aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687361823; x=1689953823; 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:to:subject :message-id:date:from:in-reply-to:references:mime-version :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=VS6cg9qPimYgCAH+m55L982dFEE3U7yAEGvgXhb7Wxg=; b=SNdW4n+pA7cmbnHKdInxmoYX2Gn3WjjKW58EOqznfU8Q8wKj8qTKny/WCyAX+Er7mG ts0TMbWVn5Z8tFsNlreDcL20+alo4xmdAMk1nh2qz2TQnuhOAyElxDWQXIjF/iTgN8cZ N57VgUQtvYC5vrlsHcZyjmxmtC9ax5wwdDyHI5UPDiikiE+UKw5UnzsMrDOL1x7kb92G M94ZC6bbk4dUGpiW2MkV3CYkN04OtuVv4jkse9DjLmMEApn+pYAvXZOIsrIfkALh95fI Ks2nR2 Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDwMtAFR0GvZK3e9CfcGLz0LBs+xjr4gjizbpf0NPjDpHJeQs/aF MhzWwQIHPjOowxuBuqkkXBc= X-Google-Smtp-Source: ACHHUZ4uzxWYh+izjDbZJZawbXui7aX0SZzcFqW9haA2P0losY69308mH6Gh9bN/W39mWV1jzsYqFw== X-Received: by 2002:ad4:5d6e:0:b0:62e:ba9:e962 with SMTP id fn14-20020ad45d6e000000b0062e0ba9e962mr10019991qvb.56.1687361823152; Wed, 21 Jun 2023 08:37:03 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:ad4:59c7:0:b0:62f:eef5:d9c3 with SMTP id el7-20020ad459c7000000b0062feef5d9c3ls4258435qvb.0.-pod-prod-09-us; Wed, 21 Jun 2023 08:37:00 -0700 (PDT) X-Received: by 2002:a67:f408:0:b0:440:a867:add9 with SMTP id p8-20020a67f408000000b00440a867add9mr5454453vsn.3.1687361820130; Wed, 21 Jun 2023 08:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687361820; cv=none; d=google.com; s=arc-20160816; b=zXRiS1xmw7XI5zoZ54KXOo+6F6qVhtwCVK/JR7SxWZUrnyLsRktYpAahZwqOXpjnyo bwIzNRXkJn508fUwpydVCR0upWMQA6lhEfFXeZmfs2qmrB2T8QOKum1sd7LX/wqyigKo nI1dZ7+1S1Ai1JoXFttrMqo429iaH5HookzgBDgUXocWDNl4pwSvbZ3I/qk+eRJ2O0f5 uXqD1o4ew6eSvRekRyOKzJioqcMSghnwPe+6wjXXl7FLd4nY9Fvtksnc3hjScDF//0SM ZeSUm3ISNoljtijDMDBGjslnhiT334fcwom/8silOKgYAqSNt4cx/kdkZ/8bUBewKxO8 Z9qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GhiGTYb9hWK0fAqSRXdrBB3vHBLZvdffw8PS6dMhzHs=; b=Pz6P+iGTpd5bM9pyv+Wcw9rT1sZFCSvLMPaNs+b4+J2ii4k1a57ZTXHuPlUGwXKCwr GJIld1mqlg7+kE89CR24VPOrLfPgd2dAFNamx5rAhK0vjfnK0mfNEJVU5i5RI4EPGRF/ YtcOW7TCsQmwx0C625UNmGGMc5/TCVRnLmDhRXCQ79SV4FnGNosojos/qoOlbvIfBzdE BgGY1kvdjL/pSHpCHG/e00+nLrkpGcGa61Gk+DD4gDgfPRT6LTBOrfGXTtoqiMD3Rdl6 7VfVfxoGn+LUhNPI3qa3pOsa+Nq+l4bMNdF49TMIDRRFyaJfHfZi/q40nLF5feETCj/y T7/A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fhqIX1o5; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::b34 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com. [2607:f8b0:4864:20::b34]) by gmr-mx.google.com with ESMTPS id h35-20020a0561023da300b0043f8d83fd30si423448vsv.2.2023.06.21.08.37.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Jun 2023 08:37:00 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::b34 as permitted sender) client-ip=2607:f8b0:4864:20::b34; Original-Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-bfee66a5db6so819244276.0 for ; Wed, 21 Jun 2023 08:37:00 -0700 (PDT) X-Received: by 2002:a25:2e0c:0:b0:bc3:843a:953a with SMTP id u12-20020a252e0c000000b00bc3843a953amr11376196ybu.18.1687361819601; Wed, 21 Jun 2023 08:36:59 -0700 (PDT) In-Reply-To: X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fhqIX1o5; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::b34 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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:32855 Archived-At: --000000000000dd710b05fea58940 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 1. You have two lists, the original/old one and the new one. 2. Push elements from the old list onto the new list until you get to the first element which should go into the new nested div. 3. Create a third list and push elements from the old list onto that list until you get to the last element which should go into the div. 4. Create a div from the third list. 5. Push the div onto the new list. 6. Either repeat steps 2=E2=80=935 or resume pushing elements from the old list onto the new list until you get to the last element. ``````lua function Pandoc(doc) local old =3D doc.blocks local new =3D pandoc.Blocks({ }) local div =3D false local i =3D 0 local elem =3D nil while i < #old do i =3D i + 1 elem =3D old[i] if test_div_start_condition(elem) then div =3D pandoc.Blocks({ elem }) elseif test_div_end_condition(elem) then if div then div[#div + 1] =3D elem new[#new + 1] =3D pandoc.Div(div, { class =3D 'foo', bar =3D 'baz' = }) div =3D nil -- -- If this is the only div -- while i < #old do -- i =3D i + 1 -- new[#new + 1] =3D =3D old[i] -- end else new[#new + 1] =3D elem end elseif div then div[#div + 1] =3D elem else new[#new + 1] =3D elem end end doc.blocks =3D new return doc end `````` Den tis 20 juni 2023 02:16H skrev: > On June 19, 2023 6:11:35 PM EDT, H wrote: > >What is the "best" way of wrapping parts of an existing document in > >
in a filter? > > > >Using insert.table(existingtable, pandoc.Div(existingtextblocks)) does > >not work since the existing text blocks get duplicated in the output. > > > >I see two options but there might be others: > > > >- Surround existing text blocks with pandoc.RawInline(1, 'html, > >'
') and pandoc.RawInLine('html', '
'). > > > >- Create a new table and use insert.table(newtable, > >pandoc.Div(existingtextblock)) and also insert the rest of the > >document. > > > >Are there other options? > > Replying to my own question, it seems the most "elegant" way of > accomplishing this requires this to be done be in two stages: > > - First, delete the blocks in question from the block list table, eg > doc.blocks. > - Second, insert them into the same table using pandoc.Div(). > > Unfortunately it seems table.delete() does not accept a list of blocks, > only one block at a time, pandoc.Div, on the other hand, accepts a table. > Here is a code example when I was trying it out: > > local temp =3D {} > for i =3D 3, 1, -1 do > table.insert(temp, table.remove(doc.blocks, 5)) > end > > table.insert(doc.blocks, 2, pandoc.Div(temp)) > > The above code removes blocks 5 through 7 from doc.blocks, then inserts > them, in the same order but surrounded by
, in position 2. > > If there is a better way of accomplishing this, I would appreciate hearin= g > it. > > -- > 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/AC708553-331A-45D3-A618-= EAA8BB7784A5%40meddatainc.com > . > --=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/CADAJKhBZGdihMMgb%3D2_9rT04RsobJyu%2B48HxtO5755ADPcnZBQ%40ma= il.gmail.com. --000000000000dd710b05fea58940 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
1.=C2=A0 You have two lists, the origin= al/old one and the new one.
2.=C2=A0 Push elements f= rom the old list onto the new list until you get to the first element which= should go into the new nested div.
3.=C2=A0 Create = a third list and
push elements from the old list ont= o that list until you get to the last
element which = should go into the div.
4.=C2=A0 Create a div from t= he third
list.
5.=C2=A0 Push = the div onto the new list.
6.=C2=A0 Either repeat st= eps 2=E2=80=935 or resume pushing elements from the old
list onto the new list until you get to the last element.

``````lua
func= tion Pandoc(doc)
=C2=A0 local old =3D doc.blocks
=C2=A0 local new =3D pandoc.Blocks({ })
=C2=A0 local div =3D false
=C2=A0 local i = =3D 0
=C2=A0 local elem =3D nil
=C2=A0 while i < #old do
=C2=A0 =C2=A0 i =3D i= + 1
=C2=A0 =C2=A0 elem =3D old[i]
=C2=A0 =C2=A0 if test_div_start_condition(elem) then
=C2=A0 =C2=A0 =C2=A0 div =3D pandoc.Blocks({ elem })
=C2=A0 =C2=A0 elseif test_div_end_condition(elem) then
=C2=A0 =C2=A0 =C2=A0 if div then
=C2=A0= =C2=A0 =C2=A0 =C2=A0 div[#div + 1] =3D elem
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 new[#new + 1] =3D pandoc.Div(div, { class =3D 'foo= ', bar =3D 'baz' })
=C2=A0 =C2=A0 =C2=A0= =C2=A0 div =3D nil
=C2=A0 =C2=A0 =C2=A0 =C2=A0 -- -= - If this is the only div
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 -- while i < #old do
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 --=C2=A0 =C2=A0i =3D i + 1
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 --=C2=A0 =C2=A0new[#new + 1] =3D =3D old[i]
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 -- end
=C2=A0 =C2=A0 =C2= =A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 new[#new + 1] = =3D elem
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 elseif div then
=C2=A0 =C2=A0 =C2= =A0 div[#div + 1] =3D elem
=C2=A0 =C2=A0 else
<= div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 new[#new + 1] =3D elem
=C2=A0 =C2=A0 end
=C2=A0 end
=C2=A0 doc.blocks =3D new
=C2=A0 return do= c
end
``````


Den tis 20 juni 2023 02:16H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> skrev:
On June 19, 2023 6:11:35 PM EDT, H <agents@meddatain= c.com> wrote:
>What is the "best" way of wrapping parts of an existing docum= ent in
><div></div> in a filter?
>
>Using insert.table(existingtable, pandoc.Div(existingtextblocks)) does<= br> >not work since the existing text blocks get duplicated in the output. >
>I see two options but there might be others:
>
>- Surround existing text blocks with pandoc.RawInline(1, 'html,
>'<div>') and pandoc.RawInLine('html', '</d= iv>').
>
>- Create a new table and use insert.table(newtable,
>pandoc.Div(existingtextblock)) and also insert the rest of the
>document.
>
>Are there other options?

Replying to my own question, it seems the most "elegant" way of a= ccomplishing this requires this to be done be in two stages:

- First, delete the blocks in question from the block list table, eg doc.bl= ocks.
- Second, insert them into the same table using pandoc.Div().

Unfortunately it seems table.delete() does not accept a list of blocks, onl= y one block at a time, pandoc.Div, on the other hand, accepts a table. Here= is a code example when I was trying it out:

local temp =3D {}
for i =3D 3, 1, -1 do
=C2=A0 table.insert(temp, table.remove(doc.blocks, 5))
end

table.insert(doc.blocks, 2, pandoc.Div(temp))

The above code removes blocks 5 through 7 from doc.blocks, then inserts the= m, in the same order but surrounded by <div></div>, in position= 2.

If there is a better way of accomplishing this, I would appreciate hearing = it.

--
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 pandoc-discuss+unsubscribe@googlegroups.= com.
To view this discussion on the web visit https://groups.google= .com/d/msgid/pandoc-discuss/AC708553-331A-45D3-A618-EAA8BB7784A5%40meddatai= nc.com.

--
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://gro= ups.google.com/d/msgid/pandoc-discuss/CADAJKhBZGdihMMgb%3D2_9rT04RsobJyu%2B= 48HxtO5755ADPcnZBQ%40mail.gmail.com.
--000000000000dd710b05fea58940--