From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31691 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Aidan Reilly Newsgroups: gmane.text.pandoc Subject: Re: Transform a fenced div to mkdocs markdown admonition format Date: Sat, 5 Nov 2022 13:09:31 +0000 Message-ID: References: <7AF275BD-12EB-4424-84E5-1A45FF675520@gmail.com> <87h6zf698z.fsf@zeitkraut.de> <87a6556cg2.fsf@zeitkraut.de> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000051f07505ecb8e742" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12882"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDO2LZEJ4EIRBGWBTGNQMGQEM2E3OXI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Nov 05 14:09:50 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-il1-f183.google.com ([209.85.166.183]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1orIvm-0003AQ-2t for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 05 Nov 2022 14:09:50 +0100 Original-Received: by mail-il1-f183.google.com with SMTP id k3-20020a92c243000000b0030201475a6bsf1156227ilo.9 for ; Sat, 05 Nov 2022 06:09:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667653789; cv=pass; d=google.com; s=arc-20160816; b=MXDup2ErS478m1rq1W/2y7LqDKsjsFcmfB4A81487ig3xBnZMgqWmh+yl8zWY2uNwf I0qobn5JmZM0JQpmUqE7lc3okgzE1o11TWjKW1fM783RM0Y515NGOjTjToi8lRq5X37E V8A5AUgWCIefP6V2ZZdKNwLnWbWefBf13OUo4yFFtHD3839gcRSRdL8ilzUAPnyAi5sq Md0lctWzCHGvr0/6Bn+xG3B97hCV4Mb9i8H6U0yFFSaljLDELfZXr/tXtcRu0yjCBhrV Ofoj0g4yH9TRnAPUUi+wSbZQb36NzMY7HjxhB/E5OoRT6SfSdQzdz+v1zeQFlj3Zdin7 pDeQ== 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; bh=dBMaH0IYyQW7kfwcjuc5NdmdEanuyCnFTQFZ86XgwOs=; b=Tmf+278+rED6qqJyYjetrgK6KW/sxe2HZ1pVXtIEKpkksEJQHL8XItVvWk8VdDMYIV y9JT0Hkb01IMwjnmfodLm5nCmkQ7KdpKwTq2T52iA/Po3Jy8nxnxa7Ridsvpqm2p47tJ QhfgffF4E+q5cKSKrf3Zp348Cc7LZ9mY5+KwF+CQ3EJ83+rtIj2+8dyd9ADvzfaIVvbh btGIUSOyptfZyekUPV21pbwUOXkmJoLIrpNbX9XUscSPlNwiIwIHCsVQH2VhkrJtJk6C Sdi85szSPkccm20xa8lH7mNcc0+iu57OzmvgHs9H+3/RfYmd5Q/yUiMjODHPL+BtWoEI WAUQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G73OB8G1; spf=pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.133.124 as permitted sender) smtp.mailfrom=aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; 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=dBMaH0IYyQW7kfwcjuc5NdmdEanuyCnFTQFZ86XgwOs=; b=noFZnHuqTprhlzWEpCLcTAD+ih+Bhm36aZud5Sxudx7JsqhfqYBnX/pRXrifOLgB// Qd8iqOuYcaij5ye6fiC9pLVG6EVg0Rt0Dz094j3hq/PVDwynHDjhqYXvX8tKHvD/3MPy cLd30IzB4yhulPVzRmgtZfS62Co5+00aoF+c/Fqm7RxCBGtX6vs4GSgfeTwDLD6II9v4 8O24xy9TSHjG9DMZG7VUIKis+uEUWyaTYdz7/WbbyCuVHugyiPHLs4qsHhiHh+Q4QxX/ YDvhcj0lTPnHN1mlgfsQIZ/wYJQW3+fh4w745mIManh77obPuWIIhY2qWOFKpO/gCHh0 LVAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=dBMaH0IYyQW7kfwcjuc5NdmdEanuyCnFTQFZ86XgwOs=; b=jMqFMGdys8JacElC361aOQR5VHQuh/y4kiMEGO/RwjcST4fDseBSbpy4w14k1J61TD lKqo+x4Jq2ZAi6XH7nO//4QWq78/QMxO8lM0MxYoz+NKhri2ckplICbs6//Z4PVVgygy 9zOyWlYL5f0/+AUZYcTvY7YazC7myYQEvjnj+2U8IhfK1yS+jzCG7QagP/Q7QD7F3cmv XfL5mxE1jmSFBdJhsF+LJMv/ptBzVo6i7qaMUUii0v5H8G28n3NJlqnWpiffSPKrD4Y3 oKoU2gRH114fRJ6aDAUNgUo9ZPCJcplFTGde5rQqZ2hbqc Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACrzQf1XLGTMHY6pDQvBOVfLcK6plQ8IPNmw3BO5r9OMzqDNjaOWJGA+ Tl+GD5Kw6lUtzkU9sa5zyo8= X-Google-Smtp-Source: AMsMyM4Sv+piz9K92+OFrmJfWh/EArGeTFv2mi36Tmqmj1QS8DRcmUGXv7sXX6TYUThYzktp0N5xbQ== X-Received: by 2002:a02:94cf:0:b0:363:4a26:8cff with SMTP id x73-20020a0294cf000000b003634a268cffmr24503377jah.286.1667653788880; Sat, 05 Nov 2022 06:09:48 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a02:b0d8:0:b0:369:7404:3a4c with SMTP id w24-20020a02b0d8000000b0036974043a4cls1604962jah.10.-pod-prod-gmail; Sat, 05 Nov 2022 06:09:46 -0700 (PDT) X-Received: by 2002:a02:95ce:0:b0:375:7eda:8c58 with SMTP id b72-20020a0295ce000000b003757eda8c58mr11005880jai.292.1667653785894; Sat, 05 Nov 2022 06:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667653785; cv=none; d=google.com; s=arc-20160816; b=Oj0ZblqYIx0hbHXL60AB+wvgufBUfXeux6hNG9/nmSb1bHQNoVrhF63yXwRi3F4o9a Jfatj4jnpOPm+XsoAseWczgKNPtWRTr5sdVxt9AO9p/ffIPo8A5PU30TydiZT8KRfAno 4dU5gupaumGqgOgWyDdJ0Zax3ucpQz6jMbfJVrE8/HmwJ1uwf1WFcGdTiLSYyGtRmWmA OmsuQAtLVddn7P8B6t5Ot5ZWJ4pJESJv/+Ho7x3347QxwTUQMhexilJib9lifx2+9tAL U/Dcwo+sodqcKJVJ5iym7mhpVcxEFnd7fxXI6+cZuHx8wSgI0f+I6PjOCRBH33jQAXCd 3ODg== 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=wSIOaJggpHAp2DCYB8ooUihOHh4RbfZ7be+y/INup6c=; b=vRCZpUYOZrK3Zt8MlHpnUBV6iYaCLNZfnuV+VWNLfxlDlpJCjcRSl9VRwOvxSYsxGx z+AATfbhlXMjzJq1ch8d4yVoDWPZgiZ2zjO/PlBZkpG3E2H1qvThIxvplF4AU13Oi/R1 ssSdUwud9P7FNIS3BJMlD9P8bezvRzFffkU9TSQicoxAatF3dHL7NIH2RtZNn7TI5H6i 0+hSQNnfJI1OQT4/AWKf5WMIhJtZZbcB8OKUVVAv+2L0DyQ7m1iB2hotWy3ybNoqzE5n l4ROth9d0HogDpFnRxo2xhI7YVUcS1OghyR0gSvHnIJ8LBSCTPsRR5fVcmetCixpmAh6 dwdA== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G73OB8G1; spf=pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.133.124 as permitted sender) smtp.mailfrom=aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Original-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com. [170.10.133.124]) by gmr-mx.google.com with ESMTPS id y20-20020a6bc414000000b00688fefa6d1dsi75787ioa.2.2022.11.05.06.09.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Nov 2022 06:09:45 -0700 (PDT) Received-SPF: pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; Original-Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-496-RkHyulArNdanTlND-jX4BA-1; Sat, 05 Nov 2022 09:09:43 -0400 X-MC-Unique: RkHyulArNdanTlND-jX4BA-1 Original-Received: by mail-ua1-f72.google.com with SMTP id z44-20020a9f372f000000b00390af225beaso3321558uad.12 for ; Sat, 05 Nov 2022 06:09:43 -0700 (PDT) X-Received: by 2002:a05:6102:356f:b0:3aa:52b2:d90a with SMTP id bh15-20020a056102356f00b003aa52b2d90amr23217372vsb.20.1667653782917; Sat, 05 Nov 2022 06:09:42 -0700 (PDT) X-Received: by 2002:a05:6102:356f:b0:3aa:52b2:d90a with SMTP id bh15-20020a056102356f00b003aa52b2d90amr23217326vsb.20.1667653782592; Sat, 05 Nov 2022 06:09:42 -0700 (PDT) In-Reply-To: <87a6556cg2.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Original-Sender: aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G73OB8G1; spf=pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.133.124 as permitted sender) smtp.mailfrom=aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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:31691 Archived-At: --00000000000051f07505ecb8e742 Content-Type: text/plain; charset="UTF-8" Thanks Albert! I really appreciate you looking at this. When I run the above, I get this error: Error running filter admonitions.lua: admonitions.lua:10: attempt to index a nil value (local 'opts') stack traceback: admonitions.lua:10: in main chunk Do I need to specify something in the command line? I'm running the build like so: asciidoctor -b docbook -o - $PAGE | pandoc --markdown-headings=atx --shift-heading-level-by=1 --wrap=none -t markdown+backtick_code_blocks --lua-filter=admonitions.lua -f docbook - > ./docs/$PAGE.md On Sat, Nov 5, 2022 at 8:19 AM Albert Krewinkel wrote: > Aidan Reilly writes: > > > Trying this, but it's just passing the text of the admonition block > > through > > The order of spaces and newline in the replacement was switched. After > some playing around, this is the filter I came up with: > > ``` lua > local admonitions = { > warning = '!!! warning', > note = '!!! note', > tip = '!!! tip', > important = '!!! important', > caution = '!!! caution' > } > > local opts = PANDOC_WRITER_OPTIONS -- reuse options to render snippets > opts.columns = opts.columns - 4 -- admons are indented by four spaces > opts.template = nil -- render a snippet > > function Div (div) > local admonition_text = admonitions[div.classes[1]] > if not admonition_text then return nil end -- not an admonition: bail > > local md = admonition_text .. '\n' .. > pandoc.write(pandoc.Pandoc(div.content), 'markdown', opts) > return pandoc.RawBlock( > 'markdown', > md:gsub('\n*$', '') -- remove trailing newlines > :gsub('\n', '\n ') -- indent block > ) > end > ``` > > > -- > Albert Krewinkel > GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 > > -- > You received this message because you are subscribed to a topic in the > Google Groups "pandoc-discuss" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/pandoc-discuss/65G0Kuih1wA/unsubscribe. > To unsubscribe from this group and all its topics, 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/87a6556cg2.fsf%40zeitkraut.de > . > > -- Aidan -- 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/CAM4RMsiRRywBgcHHQgfUxV5BZQfQw5sgqy44za4VC9%3D_TmqYPA%40mail.gmail.com. --00000000000051f07505ecb8e742 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Albert!

I really appreciate you looking at = this. When I run the above, I get this error:=C2=A0

Error running filter admonitions.lua:
admonitions.lua:10: attem= pt to index a nil value (local 'opts')
stack traceback:
admo= nitions.lua:10: in main chunk


Do I need to specify something = in the command line? I'm running the build like so:=C2=A0

asciidoctor -b docbook -o - $PAGE | pandoc =C2=A0--markd= own-headings=3Datx --shift-heading-level-by=3D1 --wrap=3Dnone -t markdown+b= acktick_code_blocks --lua-filter=3Dadmonitions.lua -f docbook - > ./docs= /$PAGE.md

On Sat, Nov 5, 2022 at 8:19 AM Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org= > wrote:
Aida= n Reilly <airei= lly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:

> Trying this, but it's just passing the text of the admonition bloc= k
> through

The order of spaces and newline in the replacement was switched. After
some playing around, this is the filter I came up with:

``` lua
local admonitions =3D {
=C2=A0 warning=C2=A0 =C2=A0=3D '!!! warning',
=C2=A0 note=C2=A0 =C2=A0 =C2=A0 =3D '!!! note',
=C2=A0 tip=C2=A0 =C2=A0 =C2=A0 =C2=A0=3D '!!! tip',
=C2=A0 important =3D '!!! important',
=C2=A0 caution=C2=A0 =C2=A0=3D '!!! caution'
}

local opts =3D PANDOC_WRITER_OPTIONS -- reuse options to render snippets opts.columns =3D opts.columns - 4=C2=A0 =C2=A0 -- admons are indented by fo= ur spaces
opts.template =3D nil=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 -- render a snippet

function Div (div)
=C2=A0 local admonition_text =3D admonitions[div.classes[1]]
=C2=A0 if not admonition_text then return nil end=C2=A0 -- not an admonitio= n: bail

=C2=A0 local md =3D admonition_text .. '\n' ..
=C2=A0 =C2=A0 pandoc.write(pandoc.Pandoc(div.content), 'markdown', = opts)
=C2=A0 return pandoc.RawBlock(
=C2=A0 =C2=A0 'markdown',
=C2=A0 =C2=A0 md:gsub('\n*$', '')=C2=A0 =C2=A0 =C2=A0-- rem= ove trailing newlines
=C2=A0 =C2=A0 =C2=A0 :gsub('\n', '\n=C2=A0 =C2=A0 ') -- ind= ent block
=C2=A0 )
end
```


--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe=C2=A0 e836 388d c0b2 1f63 1124

--
You received this message because you are subscribed to a topic in the Goog= le Groups "pandoc-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pandoc-discuss/65G0Kuih1wA/un= subscribe.
To unsubscribe from this group and all its topics, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87a6556= cg2.fsf%40zeitkraut.de.



--
Aidan

--
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://group= s.google.com/d/msgid/pandoc-discuss/CAM4RMsiRRywBgcHHQgfUxV5BZQfQw5sgqy44za= 4VC9%3D_TmqYPA%40mail.gmail.com.
--00000000000051f07505ecb8e742--