From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32847 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: mf Newsgroups: gmane.text.pandoc Subject: Re: Wrapping sections of existing document in
Date: Tue, 20 Jun 2023 12:37:04 +0200 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8"; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8881"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDZYJ4HW2QPBBU4CY2SAMGQE6KWV5GY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Jun 20 12:37:13 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lj1-f191.google.com ([209.85.208.191]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qBYjZ-00028U-0U for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 20 Jun 2023 12:37:13 +0200 Original-Received: by mail-lj1-f191.google.com with SMTP id 38308e7fff4ca-2b337a245b7sf34087001fa.3 for ; Tue, 20 Jun 2023 03:37:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687257432; cv=pass; d=google.com; s=arc-20160816; b=TE69bOYQt73upVlKV4q4c/tCz2KrkNHAUNNKvPuQIRqm5k1RMVvComQsvCzBZH1Sdj MiLjWhR/g6aEK8NFf0LPMR6le0DM3XqsQ6G+fTs1fgptykUUGKySZYT7MClM6GspdbJr Yc/oAJaB/Sa4cNc9MZ7zi0CBYwJognEkZZypkRFWh6cLcQYkhq3nSY90EXXPexCf/8Fg dDyd+rfbueSFo31LVQLto8qJmaKjfu6LyADxdeLBbbXAmECm18LvIj4Juma9WCYjWSR3 ZvKxC53kq7f8Som5StVIXpJkaHYtawdNRpF8jLie7ZNwGCyzaI5GOK8H8g8jwEWEW0Oe hI1w== 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:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:sender:dkim-signature:dkim-signature; bh=Oa8jwl+IGkX6HiWk2QHZBjOndpdiEZHRQNKKWc6EIng=; b=gH8Q87w1R3BMFmqvp/Qg6IzA+85RhxCqL1p4c34JI5Sx+jwQ7M//ye1zgfTh9SZ6ej 3RkYOWNqtC/R4hznSEN0Ekr+PP3tw/XUMGTC7OLhvSO/0FIsES6DcF49e9M396IKCmMZ 1gbBr5AZaveZRTEI3RKs2/cqZfzRZZqY8GuVZWuNRC1zIpJHHouHBFJdREr4gaXndACt q0iLZriueMR6vwAOVYLd6obly0rWlOVNkpyNyetBRIOtlMq8Zgz2JNACpUpfyyB11wZh lx3TsF1Fn4A6oGPOQ/cGM8XtdUFjde+TONsPdO5Kp7U5UYZV0VLtyNhNjrMmXsrmlbll wq7g== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Wh0y4M+X; spf=pass (google.com: domain of massifrg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::229 as permitted sender) smtp.mailfrom=massifrg-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=1687257432; x=1689849432; 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:in-reply-to :from:references:to:content-language:subject:user-agent:mime-version :date:message-id:sender:from:to:cc:subject:date:message-id:reply-to; bh=Oa8jwl+IGkX6HiWk2QHZBjOndpdiEZHRQNKKWc6EIng=; b=FBmx5aVvW8fW/RYvJq+Iedc6Tln2y0XryXSDPbzFUHKomdyf+vZHOuujrG6mTLOuUf 9zEB9Vd1f6D1IACfcmAwBcq3EmoW53nAR6FnFjW72NKJ+JU3a+P+q22pf7K/aPEiQaeX CzDyujRsyUFjDWEoNwrO+VNibjcNrTi3hpdoTFNSmXExnrFQ29u0aC+qnz9PfP6m5Zzx aFN4BCHAIKpb0o5/PYUp3Ojwka4i3t6zAwrHYnrSMFz48ecTtaw1gUchZhghgGlKszx2 uZ/VMwYuMwu4eYO09fOqZB5H78fnLInZztPBxF0aUL/y/ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687257432; x=1689849432; 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:in-reply-to :from:references:to:content-language:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=Oa8jwl+IGkX6HiWk2QHZBjOndpdiEZHRQNKKWc6EIng=; b=s2+3DjLzda3v1Mdya8YcCsB7YNTZOj6nky4kB37zJrIR3GPsnVn6mrkelFuqZDHHyS EqPyXqTfiPphkzKJ1bSPmTSYaBkgGURa1yy9+A1ONnR2JU5Jf2i0dsbVwq1cPrKSilHw iAYu5IT16dwctW2rkoeNRl2R8Wg34afrb8AvqMJL4867hzQMjWBG5DVXMjDQqYq3+uT2 YYWkSfBII+tbY9fs4yxBNz1792b+Xy2nxrcIUJZ6twqvWKi2GB3ixTKXAkhgkcmmD9Np 0j/fjytxISkU5p1x8vmxCttXpNW8FKt1OkWD12E8LfNLp3ktYQ24pqFDCnY X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687257432; x=1689849432; 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:in-reply-to :from:references:to:content-language:subject:user-agent:mime-version :date:message-id:x-beenthere:x-gm-message-state:sender:from:to:cc :subject:date:message-id:reply-to; bh=Oa8jwl+IGkX6HiWk2QHZBjOndpdiEZHRQNKKWc6EIng=; b=gbDOMSsh0fNA24eUZZtuu0Vmua1x0EqR3AQO8TtoNyUUjprP9qu7M/mtsQbaxKy7Ng zAoVeBg8HeNTlU1J8t90XFKs3xB7rkDfRRNN4fzbVef9cDRSFrVgGXkBDVbPQEyB3+jq aZ+5IQqlZDv9F9vClXg0w+dYbjRlx617XG94kLmKccftoP/t1MGkx6lv2d+ndBpd3bq8 UbOb+Xtfdw0R9jiNXBG31dfZFTsP2TLvxntNNijoitnscgVYVMUfijwp Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AC+VfDwIK79DCHxGJmh00wZujuwTiIh6XQT2ogQ3Y5vRpVGiCKhn8G+c ANuycCze6v8KAZRQOWbuvaQ= X-Google-Smtp-Source: ACHHUZ6ifQjO6M14y7nyFroivQD+gdtDis/09IoRO5zxphtJA/bRZDKqcp3/gXYykf8KWJaRB32HDQ== X-Received: by 2002:a2e:a401:0:b0:2b4:809a:1c7c with SMTP id p1-20020a2ea401000000b002b4809a1c7cmr2749694ljn.19.1687257431987; Tue, 20 Jun 2023 03:37:11 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a2e:bc28:0:b0:2af:7062:5772 with SMTP id b40-20020a2ebc28000000b002af70625772ls230852ljf.1.-pod-prod-05-eu; Tue, 20 Jun 2023 03:37:06 -0700 (PDT) X-Received: by 2002:a2e:9c19:0:b0:2b4:6f0c:4765 with SMTP id s25-20020a2e9c19000000b002b46f0c4765mr3693380lji.16.1687257426441; Tue, 20 Jun 2023 03:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687257426; cv=none; d=google.com; s=arc-20160816; b=e+Q5HWSwOXrt7YXywSz29xG+c0R8BCysQHpRfMwvz64+qeFyzRyhkYmG8kEUEN9py4 ADVNFKOj5cTIBdTz7BbcDVT3/Y5Xn1tAdypr9X9cCqM/fjm5svJVSl1pqwECA4vOO2EN /R5DQmfou0wkJp8dosCTTHsdc97q3gNhs1lcGFR+KmlGf8I4HZsnuhm6H0Ya4s9wpROg bCKSWXi6bd7IDFLcZOsZmtNHVMZIhbboTGLFq42nXx1DeWbZb57KKGeKKBc1Ny0qUaSA PEcloJng5oIb8tyI+3uipw3SpcxpjLSBg8nPg8GPWTlJkYOvgPvTW/+NvO0bb9Cuzynl eIKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=mpPj3TWXlp53n46V2URnAvA9BR9OXAwXzEpbdINKJI4=; b=p2wRFQGofnzGA63jvzg09qsB6ToyqquO53Lw1MJ7mohKOOS9eJ7PCgHP9orV+zFYjV sBhwcNqVy/jq1ZuCVuYSPVyQ8obiJ2q6Vho3Gbem6Vg/aq3EyJt0RX4XNIfBOKfGJl5v SW1nVFKuWwcpOCQVKRBLRvUeF9lt+SYRl3dA20PJ8Gj41hEIUzMPqnfrIQrHasn6jTMR kocN3kb4HA4FuuPkj4GvyZeANnpQ5OxJQWNoS/CFFxztDAhA76bATMhvcOGpEDT+pSf4 gvhxF4smu60wn7bZ1MsIA0OSen+/zu7lsuKaBZyTZOz5oAuXjyFJXaCcDbYw3YFaGvdX FgeA== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Wh0y4M+X; spf=pass (google.com: domain of massifrg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::229 as permitted sender) smtp.mailfrom=massifrg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com. [2a00:1450:4864:20::229]) by gmr-mx.google.com with ESMTPS id y17-20020a05651c155100b002b476a83875si86299ljp.3.2023.06.20.03.37.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Jun 2023 03:37:06 -0700 (PDT) Received-SPF: pass (google.com: domain of massifrg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::229 as permitted sender) client-ip=2a00:1450:4864:20::229; Original-Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b470330145so37039361fa.3 for ; Tue, 20 Jun 2023 03:37:06 -0700 (PDT) X-Received: by 2002:a2e:7305:0:b0:2b4:6f70:c392 with SMTP id o5-20020a2e7305000000b002b46f70c392mr3995892ljc.36.1687257425866; Tue, 20 Jun 2023 03:37:05 -0700 (PDT) Original-Received: from [192.168.1.52] (host-95-229-108-50.business.telecomitalia.it. [95.229.108.50]) by smtp.gmail.com with ESMTPSA id v21-20020a2e9915000000b002adb0164258sm352918lji.112.2023.06.20.03.37.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Jun 2023 03:37:05 -0700 (PDT) Content-Language: it-IT, en-US In-Reply-To: X-Original-Sender: massifrg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Wh0y4M+X; spf=pass (google.com: domain of massifrg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::229 as permitted sender) smtp.mailfrom=massifrg-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:32847 Archived-At: Il 20/06/23 02:14, H ha scritto: > 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. >> This would apply only to HTML output. >> 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 = {} > for i = 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 hearing it. > Consider using the Blocks function in the filter (see https://pandoc.org/lua-filters.html#filters-on-element-sequences). The Blocks function is called on every sequence of blocks. Here's an example: local my_filter = { { Blocks = function(blocks) local first_in_div, last_in_div = detect_seq_for_div(blocks) -- check if last is after first and the Div will not be empty if first_in_div and last_in_div and last_in_div - first_in_div > 1 then local newblocks = pandoc.List() local divblocks = pandoc.List() for i = 1, #blocks do if i < first_in_div or i > last_in_div then newblocks:insert(blocks[i]) else divblocks:insert(blocks[i]) if i == last_in_div then local div = pandoc.Div(divblocks) newblocks:insert(div) end end end return newblocks end -- if no meaningful sequence is detected, -- no return statement to keep the current blocks end, } } You should write the detect_seq_for_div function that scans a list of blocks and returns two positive integers only if it contains a meaningful sequence of blocks that you want to wrap in a Div. Otherwise it should return nil. Those two integers are the indexes of the first and the last block you want to put in the Div.