* Transform a fenced div to mkdocs markdown admonition format
@ 2022-11-03 16:14 Aidan Reilly
[not found] ` <ddc82450-b82b-4b8f-9d5f-30c6a28c206fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Aidan Reilly @ 2022-11-03 16:14 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 932 bytes --]
Hello!
Trying to figure out how to use pandoc +fenced_div with a filter to
transform this:
::: note
Here is the first line of this note.
And the second,
And the third!
:::
into this:
!!! note
Here is the first line of this note.
And the second,
And the third!
Struggling to understand if it is possible to "indent" elements using
pandoc. The mkdocs markdown spec requires the body of notes to be indented
by 4 spaces. Is there a way to apply indents without stringifying the
content?
Thanks!
--
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/ddc82450-b82b-4b8f-9d5f-30c6a28c206fn%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 1571 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <ddc82450-b82b-4b8f-9d5f-30c6a28c206fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-11-03 20:09 ` John MacFarlane
[not found] ` <7AF275BD-12EB-4424-84E5-1A45FF675520-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: John MacFarlane @ 2022-11-03 20:09 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
I assume you’re targeting markdown?
You could then just create a RawBlock with format “markdown”, and put this content in it with whatever indentation you like.
> On Nov 3, 2022, at 9:14 AM, Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
>
> Hello!
>
> Trying to figure out how to use pandoc +fenced_div with a filter to transform this:
>
> ::: note
> Here is the first line of this note.
>
> And the second,
>
> And the third!
> :::
>
> into this:
>
> !!! note
> Here is the first line of this note.
>
> And the second,
>
> And the third!
>
> Struggling to understand if it is possible to "indent" elements using pandoc. The mkdocs markdown spec requires the body of notes to be indented by 4 spaces. Is there a way to apply indents without stringifying the content?
>
> Thanks!
>
>
> --
> 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/ddc82450-b82b-4b8f-9d5f-30c6a28c206fn%40googlegroups.com.
--
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/7AF275BD-12EB-4424-84E5-1A45FF675520%40gmail.com.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <7AF275BD-12EB-4424-84E5-1A45FF675520-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2022-11-03 20:40 ` Aidan Reilly
[not found] ` <CAM4RMsh1iqDjA7WqfCuWJV4NCD_ELXfFL0iV+pGUWASvgAzq5g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Aidan Reilly @ 2022-11-03 20:40 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 2765 bytes --]
Hi John, sorry - yes I am targeting markdown. Ok I’ll try that thanks.
Aidan
On Thu 3 Nov 2022 at 20:09, John MacFarlane <fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> I assume you’re targeting markdown?
>
> You could then just create a RawBlock with format “markdown”, and put this
> content in it with whatever indentation you like.
>
>
> > On Nov 3, 2022, at 9:14 AM, Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> >
> > Hello!
> >
> > Trying to figure out how to use pandoc +fenced_div with a filter to
> transform this:
> >
> > ::: note
> > Here is the first line of this note.
> >
> > And the second,
> >
> > And the third!
> > :::
> >
> > into this:
> >
> > !!! note
> > Here is the first line of this note.
> >
> > And the second,
> >
> > And the third!
> >
> > Struggling to understand if it is possible to "indent" elements using
> pandoc. The mkdocs markdown spec requires the body of notes to be indented
> by 4 spaces. Is there a way to apply indents without stringifying the
> content?
> >
> > Thanks!
> >
> >
> > --
> > 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/ddc82450-b82b-4b8f-9d5f-30c6a28c206fn%40googlegroups.com
> .
>
> --
> 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/7AF275BD-12EB-4424-84E5-1A45FF675520%40gmail.com
> .
>
> --
*Aidan Reilly*
He/Him/His
Senior Technical Writer, Telco (Cork, Ireland)
aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
IM/GitHub: aireilly
TEL: +353851261126
<https://www.redhat.com/>
--
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/CAM4RMsh1iqDjA7WqfCuWJV4NCD_ELXfFL0iV%2BpGUWASvgAzq5g%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 5612 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <CAM4RMsh1iqDjA7WqfCuWJV4NCD_ELXfFL0iV+pGUWASvgAzq5g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-11-03 20:55 ` Aidan Reilly
[not found] ` <CAM4RMsj6rwDLDmNxNzvUDODw0qa5NZgZtbAS_ozf+XJ3ZE+jHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Aidan Reilly @ 2022-11-03 20:55 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 3570 bytes --]
Something like this copied from https://jmablog.com/post/pandoc-filters/?
My problem is understanding how to add the required indent to every line in
the `elem` - If I stringify, I lose the markup (backticks, etc) in the
content.
function Div (elem)
if FORMAT:match 'latex' then
if elem.classes[1] == "notes" then
return {
pandoc.RawBlock('latex',
'\\begin{tcolorbox}[colframe=Apricot!20!white,
colback=Apricot!8!white]'),
elem,
pandoc.RawBlock('latex', '\\end{tcolorbox}')
}
else
return elem
end
end
end
On Thu, Nov 3, 2022 at 8:40 PM Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> Hi John, sorry - yes I am targeting markdown. Ok I’ll try that thanks.
>
> Aidan
>
> On Thu 3 Nov 2022 at 20:09, John MacFarlane <fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>
>> I assume you’re targeting markdown?
>>
>> You could then just create a RawBlock with format “markdown”, and put
>> this content in it with whatever indentation you like.
>>
>>
>> > On Nov 3, 2022, at 9:14 AM, Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
>> >
>> > Hello!
>> >
>> > Trying to figure out how to use pandoc +fenced_div with a filter to
>> transform this:
>> >
>> > ::: note
>> > Here is the first line of this note.
>> >
>> > And the second,
>> >
>> > And the third!
>> > :::
>> >
>> > into this:
>> >
>> > !!! note
>> > Here is the first line of this note.
>> >
>> > And the second,
>> >
>> > And the third!
>> >
>> > Struggling to understand if it is possible to "indent" elements using
>> pandoc. The mkdocs markdown spec requires the body of notes to be indented
>> by 4 spaces. Is there a way to apply indents without stringifying the
>> content?
>> >
>> > Thanks!
>> >
>> >
>> > --
>> > 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/ddc82450-b82b-4b8f-9d5f-30c6a28c206fn%40googlegroups.com
>> .
>>
>> --
>> 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/7AF275BD-12EB-4424-84E5-1A45FF675520%40gmail.com
>> .
>>
>> --
>
> *Aidan Reilly*
>
> He/Him/His
>
> Senior Technical Writer, Telco (Cork, Ireland)
>
> aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
>
> IM/GitHub: aireilly
>
> TEL: +353851261126
> <https://www.redhat.com/>
>
--
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/CAM4RMsj6rwDLDmNxNzvUDODw0qa5NZgZtbAS_ozf%2BXJ3ZE%2BjHw%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 7404 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <CAM4RMsj6rwDLDmNxNzvUDODw0qa5NZgZtbAS_ozf+XJ3ZE+jHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-11-03 21:00 ` Albert Krewinkel
[not found] ` <87h6zf698z.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Albert Krewinkel @ 2022-11-03 21:00 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
You could try with `pandoc.write`. Probably something along the lines of
``` lua
local md = pandoc.write(pandoc.Pandoc(div.contents), 'markdown')
return md:gsub('\n', ' \n')
```
(untested)
Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:
> Something like this copied from https://jmablog.com/post/
> pandoc-filters/? My problem is understanding how to add the required
> indent to every line in the `elem` - If I stringify, I lose the
> markup (backticks, etc) in the content.
>
> function Div (elem)
> if FORMAT:match 'latex' then
> if elem.classes[1] == "notes" then
> return {
> pandoc.RawBlock('latex', '\\begin{tcolorbox}[colframe=Apricot!20!white, colback=Apricot!8!white]'),
> elem,
> pandoc.RawBlock('latex', '\\end{tcolorbox}')
> }
> else
> return elem
> end
> end
> end
>
>
> On Thu, Nov 3, 2022 at 8:40 PM Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> wrote:
>
> Hi John, sorry - yes I am targeting markdown. Ok I’ll try that
> thanks.
>
> Aidan
>
> On Thu 3 Nov 2022 at 20:09, John MacFarlane <
> fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> I assume you’re targeting markdown?
>
> You could then just create a RawBlock with format “markdown”,
> and put this content in it with whatever indentation you
> like.
>
>
> > On Nov 3, 2022, at 9:14 AM, Aidan Reilly <
> aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> >
> > Hello!
> >
> > Trying to figure out how to use pandoc +fenced_div with a
> filter to transform this:
> >
> > ::: note
> > Here is the first line of this note.
> >
> > And the second,
> >
> > And the third!
> > :::
> >
> > into this:
> >
> > !!! note
> > Here is the first line of this note.
> >
> > And the second,
> >
> > And the third!
> >
> > Struggling to understand if it is possible to "indent"
> elements using pandoc. The mkdocs markdown spec requires the
> body of notes to be indented by 4 spaces. Is there a way to
> apply indents without stringifying the content?
> >
> > Thanks!
> >
> >
> > --
> > 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/
> ddc82450-b82b-4b8f-9d5f-30c6a28c206fn%40googlegroups.com.
>
> --
> 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/
> 7AF275BD-12EB-4424-84E5-1A45FF675520%40gmail.com.
>
>
> --
>
> Aidan Reilly
>
> He/Him/His
>
> Senior Technical Writer, Telco (Cork, Ireland)
>
> aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
>
> IM/GitHub: aireilly
>
> TEL: +353851261126
>
> [logo]
>
>
>
> --
> Aidan
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
--
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/87h6zf698z.fsf%40zeitkraut.de.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <87h6zf698z.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-11-04 0:25 ` Aidan Reilly
[not found] ` <CAM4RMshtHUuFSHryQqAgquMduCd5xSM7c2CKnvR0H1=zsg2xQQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Aidan Reilly @ 2022-11-04 0:25 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 6228 bytes --]
Trying this, but it's just passing the text of the admonition block through:
local stringify = (require 'pandoc.utils').stringify
local admonitions = {
warning = {pandoc.Str("!!! warning")},
note = {pandoc.Str("!!! note")},
tip = {pandoc.Str("!!! tip")},
important = {pandoc.Str("!!! important")},
caution = {pandoc.Str("!!! caution")}
}
function Writer (doc, opts)
local filter = {
Div = function (el)
local admonition_text = admonitions[el.classes[1]]
if admonition_text then
table.insert(el.content, 1,
pandoc.Para{ pandoc.Str(stringify(admonition_text)) })
local md = pandoc.write(pandoc.Pandoc(el.content), 'markdown')
return pandoc.RawBlock('markdown', md):gsub('\n', ' \n')
end
end
}
return pandoc.write(doc:walk(filter), 'markdown', opts)
end
On Thu, Nov 3, 2022 at 9:03 PM Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
wrote:
> You could try with `pandoc.write`. Probably something along the lines of
>
> ``` lua
> local md = pandoc.write(pandoc.Pandoc(div.contents), 'markdown')
> return md:gsub('\n', ' \n')
> ```
>
> (untested)
>
> Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:
>
> > Something like this copied from https://jmablog.com/post/
> > pandoc-filters/? My problem is understanding how to add the required
> > indent to every line in the `elem` - If I stringify, I lose the
> > markup (backticks, etc) in the content.
> >
> > function Div (elem)
> > if FORMAT:match 'latex' then
> > if elem.classes[1] == "notes" then
> > return {
> > pandoc.RawBlock('latex',
> '\\begin{tcolorbox}[colframe=Apricot!20!white, colback=Apricot!8!white]'),
> > elem,
> > pandoc.RawBlock('latex', '\\end{tcolorbox}')
> > }
> > else
> > return elem
> > end
> > end
> > end
> >
> >
> > On Thu, Nov 3, 2022 at 8:40 PM Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> > wrote:
> >
> > Hi John, sorry - yes I am targeting markdown. Ok I’ll try that
> > thanks.
> >
> > Aidan
> >
> > On Thu 3 Nov 2022 at 20:09, John MacFarlane <
> > fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > I assume you’re targeting markdown?
> >
> > You could then just create a RawBlock with format “markdown”,
> > and put this content in it with whatever indentation you
> > like.
> >
> >
> > > On Nov 3, 2022, at 9:14 AM, Aidan Reilly <
> > aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> > >
> > > Hello!
> > >
> > > Trying to figure out how to use pandoc +fenced_div with a
> > filter to transform this:
> > >
> > > ::: note
> > > Here is the first line of this note.
> > >
> > > And the second,
> > >
> > > And the third!
> > > :::
> > >
> > > into this:
> > >
> > > !!! note
> > > Here is the first line of this note.
> > >
> > > And the second,
> > >
> > > And the third!
> > >
> > > Struggling to understand if it is possible to "indent"
> > elements using pandoc. The mkdocs markdown spec requires the
> > body of notes to be indented by 4 spaces. Is there a way to
> > apply indents without stringifying the content?
> > >
> > > Thanks!
> > >
> > >
> > > --
> > > 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/
> > ddc82450-b82b-4b8f-9d5f-30c6a28c206fn%40googlegroups.com.
> >
> > --
> > 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/
> > 7AF275BD-12EB-4424-84E5-1A45FF675520%40gmail.com.
> >
> >
> > --
> >
> > Aidan Reilly
> >
> > He/Him/His
> >
> > Senior Technical Writer, Telco (Cork, Ireland)
> >
> > aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
> >
> > IM/GitHub: aireilly
> >
> > TEL: +353851261126
> >
> > [logo]
> >
> >
> >
> > --
> > Aidan
>
>
> --
> 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/87h6zf698z.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/CAM4RMshtHUuFSHryQqAgquMduCd5xSM7c2CKnvR0H1%3Dzsg2xQQ%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 9983 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <CAM4RMshtHUuFSHryQqAgquMduCd5xSM7c2CKnvR0H1=zsg2xQQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-11-05 8:03 ` Albert Krewinkel
[not found] ` <87a6556cg2.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Albert Krewinkel @ 2022-11-05 8:03 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <87a6556cg2.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-11-05 13:09 ` Aidan Reilly
[not found] ` <CAM4RMsiRRywBgcHHQgfUxV5BZQfQw5sgqy44za4VC9=_TmqYPA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Aidan Reilly @ 2022-11-05 13:09 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 2808 bytes --]
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 <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> 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.
[-- Attachment #2: Type: text/html, Size: 4373 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <CAM4RMsiRRywBgcHHQgfUxV5BZQfQw5sgqy44za4VC9=_TmqYPA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-11-05 13:10 ` Aidan Reilly
2022-11-05 13:53 ` Albert Krewinkel
1 sibling, 0 replies; 11+ messages in thread
From: Aidan Reilly @ 2022-11-05 13:10 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 3090 bytes --]
Oh I guess I need to configure https://github.com/pandoc/lua-filters ?
On Sat, 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:
>
> 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 <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> 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.
[-- Attachment #2: Type: text/html, Size: 4985 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <CAM4RMsiRRywBgcHHQgfUxV5BZQfQw5sgqy44za4VC9=_TmqYPA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-11-05 13:10 ` Aidan Reilly
@ 2022-11-05 13:53 ` Albert Krewinkel
[not found] ` <875yft5wqc.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
1 sibling, 1 reply; 11+ messages in thread
From: Albert Krewinkel @ 2022-11-05 13:53 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:
> 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
The most likely cause for this is an older pandoc version. The
`PANDOC_WRITER_OPTIONS` global was introduced in pandoc 2.17.
The filter can be made more robust by replacing line 9 with
```lua
local opts = PANDOC_WRITER_OPTIONS or {columns = 72}
```
That will ensure that the filter works even with older pandoc versions
(but with reduced functionality in that case).
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
--
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/875yft5wqc.fsf%40zeitkraut.de.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Transform a fenced div to mkdocs markdown admonition format
[not found] ` <875yft5wqc.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-11-05 16:26 ` Aidan Reilly
0 siblings, 0 replies; 11+ messages in thread
From: Aidan Reilly @ 2022-11-05 16:26 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 2009 bytes --]
That did it Albert - thank you! I need to spend a bit more time brushing up
on Lua I think.
Aidan
On Sat, Nov 5, 2022 at 1:58 PM Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
wrote:
>
> Aidan Reilly <aireilly-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:
>
> > 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
>
> The most likely cause for this is an older pandoc version. The
> `PANDOC_WRITER_OPTIONS` global was introduced in pandoc 2.17.
>
> The filter can be made more robust by replacing line 9 with
>
> ```lua
> local opts = PANDOC_WRITER_OPTIONS or {columns = 72}
> ```
>
> That will ensure that the filter works even with older pandoc versions
> (but with reduced functionality in that case).
>
>
>
> --
> 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/875yft5wqc.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/CAM4RMshpnCHthCjffGJMiXuxbRKwWR%2B%2BzxpqW62TUWN64395bQ%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 3342 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-11-05 16:26 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 16:14 Transform a fenced div to mkdocs markdown admonition format Aidan Reilly
[not found] ` <ddc82450-b82b-4b8f-9d5f-30c6a28c206fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-11-03 20:09 ` John MacFarlane
[not found] ` <7AF275BD-12EB-4424-84E5-1A45FF675520-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-11-03 20:40 ` Aidan Reilly
[not found] ` <CAM4RMsh1iqDjA7WqfCuWJV4NCD_ELXfFL0iV+pGUWASvgAzq5g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-11-03 20:55 ` Aidan Reilly
[not found] ` <CAM4RMsj6rwDLDmNxNzvUDODw0qa5NZgZtbAS_ozf+XJ3ZE+jHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-11-03 21:00 ` Albert Krewinkel
[not found] ` <87h6zf698z.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-11-04 0:25 ` Aidan Reilly
[not found] ` <CAM4RMshtHUuFSHryQqAgquMduCd5xSM7c2CKnvR0H1=zsg2xQQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-11-05 8:03 ` Albert Krewinkel
[not found] ` <87a6556cg2.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-11-05 13:09 ` Aidan Reilly
[not found] ` <CAM4RMsiRRywBgcHHQgfUxV5BZQfQw5sgqy44za4VC9=_TmqYPA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-11-05 13:10 ` Aidan Reilly
2022-11-05 13:53 ` Albert Krewinkel
[not found] ` <875yft5wqc.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-11-05 16:26 ` Aidan Reilly
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).