From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31692 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:10:58 +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="00000000000080562e05ecb8ec83" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19045"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDO2LZEJ4EIRB4GBTGNQMGQEDCDK4MY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Nov 05 14:11:16 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-qv1-f60.google.com ([209.85.219.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1orIx9-0004lk-H8 for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 05 Nov 2022 14:11:15 +0100 Original-Received: by mail-qv1-f60.google.com with SMTP id e9-20020ad45369000000b004bbb737fcf9sf4963163qvv.6 for ; Sat, 05 Nov 2022 06:11:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667653874; cv=pass; d=google.com; s=arc-20160816; b=E204FgYRQhqvTFMRgwyooECEyyfp5g0Q2s7cPSR9v6zIhEtps+CMzm6b2mL0ANl6Tu ZvKl959u052Y5mcO6ajkGX8nRvEPm2WQgpwgzZZupgZ/o2pbvHNDEYFtLoBUmoG2dYE+ S6Wlk8kxzVh22y7Y7oGAkQmTdgnXq3TpA45etrjvU6rXiAOhSR+dbHeuNAe6HjmIXene D6IM0EkFw/3ubwv1R4I7XkbLl9RW8c0VwkWek/VfXzNbLmbdLduGwvIDv2tOlS6Ra9zn j50ivd10iApBvmyMLy2C+Dd3TSIkA4/DSjLwKQ/OfI0EN/jkxVj3otShCTxI6RwEGSw+ dTEQ== 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=Xpdmvxc1bCWeLjtqEx4KJZLfQWeNooaDD5shx9Vag6o=; b=Yl92Zgv1LkyqgBsCafGm2cl16RK+zSTMs/b1JTT+jhkiqp+h0iPp0HgrwsaQNK72Xz nwjgm1h6LWIMq8STMV2ws28pUSKQoPYaupHU4viNIcDTSs7FkJHhYeBMGLHwBonWjMao lYwMEKtwYxOPAeISDw1rFhVLHyrxSJdvOxaPN2cs39C9HcCjayR1wxB74wpmvRHMjmXf Cjc16neOI4fLN6AyajAtb2vCPLQrAiPUshB4Mvgm3TejMGiYlYg+qZs6eTTucu5eildi vsrIsLUJQXrQq/2aHtoL5jRQgdUGFp2DzOX6rP0518umD2JcKLssugZGwCELfURu3r1C 5xSQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UJSVKytg; spf=pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.129.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=Xpdmvxc1bCWeLjtqEx4KJZLfQWeNooaDD5shx9Vag6o=; b=TNsl81z42BeaKEhyVolX2Indm+f+iY5Tsb7sqmjDMhJkl+E9II9cYREo3Ur1oYvC6O erZPoBu5ycHOeLD5XgsPAUf68VWynmFTHMzhGujGLQGqhg6dLYT2nxU+X5X4z46XwiQT Y2Rci4ndhA0LIwuXg9ormfn7PdxgdSM2mFGP+V0ZxdGMc+ihjkTFoXSKS9GcgfpGuwpF a6Z0zoqo6Dz2t2gzGHIlrjIQSpDGe1cd/GxpDUGBqRr9EAWSsgm6eMGIoe15nl+IQXtW vesxe8CLaGX4CKZP/sXHnjIUyRQ93NBcbF37+ns3W3d8PEVIZ4TpEehK97M14LKTYsXt Lcig== 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=Xpdmvxc1bCWeLjtqEx4KJZLfQWeNooaDD5shx9Vag6o=; b=qUAyNqOQ0+b4GNkSMb9iKJeh0kAREh+fXEHA5T+jF7k8fSauYuDRk2ol4QF7CNI9XT Lh1P7YGLAw52YyvGR55idlLKU3AoEDtjaz6/iBv62elIv37B2WejtF23nI2qBV+CdE9x 3LZ9AYk9dd7CpHMweR7H/8A9o+wP+aad2LcZo+AtCjdROGjVvdP6v/kTS8J5oTiRHCBu xAceCDseV7WEaSogoNiC9w8/FDoFokPYeuI/neDjBCW34bezW8zydFKv4pcegrraYyzw cOjadwWF83WIAdzgO7lD39QMw9SeCwnFhG1ngKKLG3XFvm Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACrzQf1b4keVCShsMsSwSUS17lgxM7efiEEDtmnde/n6JHi/kuBt0tM/ yPjWpLM7Gic3iydJGpFoSmk= X-Google-Smtp-Source: AMsMyM7BlGXkg/IVvx40mFlDYFU9K40mAvDeR8GwhLn6VOS+jIqDeTJq/pkgjU0UMg7rTM+/hRGAFQ== X-Received: by 2002:a05:620a:178a:b0:6fa:94ff:1b1f with SMTP id ay10-20020a05620a178a00b006fa94ff1b1fmr4911586qkb.337.1667653874601; Sat, 05 Nov 2022 06:11:14 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:ae9:ee17:0:b0:6cd:ef1b:e92a with SMTP id i23-20020ae9ee17000000b006cdef1be92als4579002qkg.9.-pod-prod-gmail; Sat, 05 Nov 2022 06:11:12 -0700 (PDT) X-Received: by 2002:a05:620a:1263:b0:6fa:15e:26a4 with SMTP id b3-20020a05620a126300b006fa015e26a4mr28775629qkl.596.1667653872025; Sat, 05 Nov 2022 06:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667653872; cv=none; d=google.com; s=arc-20160816; b=IBl9TgonaMgvRd5HrGZqhDiCsUgIx/iZED/OKXP9Zr/tCVdVs7GH+3sUl4FcEBornL HWoB9dSl/ZU8st6qSrpDRQk8JVjx76ipJH7k6CuiU1teMvaE0h3D8YBsxt6BL9b5ubV1 sWyavQmFNPM/B/nhYet4QZd0IROZ3Oguu255gQl1AlGuI5cy3uGmkisQSE5Wmxuc2KqW 40ojVx0x4ZCrwSqysaeU/0rHDCO2cNUuwghuReOmD4uXh8wbumo4D6Un87/wLVT9Gnq1 s8IgNUI166yoJnC5wInetBYTd2Qyfp+0wO1xPpwzcFi0JkZyDNVxHdQh4zMZCnWrgGaB jaVg== 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=D/VmxF1eERCQ6k2Eg9hQscERYtY69BGLcY+4vl7NQAo=; b=WNGr0lyMlunJdBF1B+lCuPdMxQ+FxtMe3qRDTmJCBpfbT3jx05MBZAQ/UHqs3Bjeyw xWEcNZUuFd4QOk/+B3fIlxpCNZAch8J83x7gV4W216ATYpyCAAKljmhOLEW5gzJfI1wh ++QgxEf4+L0CrkWVzlDTOJAwkdAyFFYhc3+LDUkSZUFTYmGk7yY2x7DdUnVrKR0d8kTO pniSPYejIY8qjelXcH+MGfmIT1k+D7MhDgUjlK87eR54aLJ/5qZomXV65RSInKdeEROB FIM/IjmO3ciXY6dF3a4jmvMqI4veOItascec/crUnh4GMJHGYu12swoJ+bcyeh3q+kv8 Ljyw== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UJSVKytg; spf=pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.129.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.129.124]) by gmr-mx.google.com with ESMTPS id t12-20020a05620a0b0c00b006eea4b5abb0si85479qkg.0.2022.11.05.06.11.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Nov 2022 06:11:12 -0700 (PDT) Received-SPF: pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; Original-Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-63-bI9iGUxbNjundcexbSILtA-1; Sat, 05 Nov 2022 09:11:10 -0400 X-MC-Unique: bI9iGUxbNjundcexbSILtA-1 Original-Received: by mail-vk1-f198.google.com with SMTP id r23-20020a1f2b17000000b003b89463c349so1756381vkr.0 for ; Sat, 05 Nov 2022 06:11:10 -0700 (PDT) X-Received: by 2002:a1f:c7c3:0:b0:3b4:318d:42d3 with SMTP id x186-20020a1fc7c3000000b003b4318d42d3mr22337587vkf.7.1667653869795; Sat, 05 Nov 2022 06:11:09 -0700 (PDT) X-Received: by 2002:a1f:c7c3:0:b0:3b4:318d:42d3 with SMTP id x186-20020a1fc7c3000000b003b4318d42d3mr22337543vkf.7.1667653869517; Sat, 05 Nov 2022 06:11:09 -0700 (PDT) In-Reply-To: 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=UJSVKytg; spf=pass (google.com: domain of aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org designates 170.10.129.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:31692 Archived-At: --00000000000080562e05ecb8ec83 Content-Type: text/plain; charset="UTF-8" Oh I guess I need to configure https://github.com/pandoc/lua-filters ? On Sat, Nov 5, 2022 at 1:09 PM Aidan Reilly wrote: > 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 < > albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 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 > -- 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/CAM4RMsiuGY-%2BxiH8RgUqTbSjjGd0bUoGWvU9%2BL0JmUiMOPix7g%40mail.gmail.com. --00000000000080562e05ecb8ec83 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Oh I guess I need to configure=C2=A0https://github.com/pandoc/lua-filters ?
On S= at, Nov 5, 2022 at 1:09 PM Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
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: 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 l= ike so:=C2=A0

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

On Sat, Nov 5, 2022 at 8:19 = AM Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> wrote:
Aidan Reilly <aireilly-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


--
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://gro= ups.google.com/d/msgid/pandoc-discuss/CAM4RMsiuGY-%2BxiH8RgUqTbSjjGd0bUoGWv= U9%2BL0JmUiMOPix7g%40mail.gmail.com.
--00000000000080562e05ecb8ec83--