* Lua filter to convert Markdown comment
@ 2021-01-14 18:08 Peter Matulis
[not found] ` <CAMxYqzEvRHcFQ1BYsFODC-Bd36=LfO-UKcVYPNzR8i8rDZorXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Peter Matulis @ 2021-01-14 18:08 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 1801 bytes --]
Hi. I'm new to Pandoc & Lua but my present issue is straightforward. I am
converting a Markdown file to HTML with pandoc like this:
pandoc -L filter.lua -f gfm -t html -o file.html file.md
Where file.md contains a line with this MD comment (the MD file was
obtained by converting from RST where I had to seed that file with an RST
comment to use as a placeholder for what I'm doing here):
<!-- blah -->
I simply want to convert this into an actual (second-level) MD header:
## blah
From what I've read, I would ideally specify an "element" that will be
acted upon, but what is a comment considered? Anyway, I think I can specify
`Pandoc` to mean "check the entire document", and that's what I've done
here (I will eventually be iterating through multiple MD files so I should
really not be doing it like this; please advise!):
function Pandoc (value)
comment = "<!-- blah -->"
comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah")
return value
end
I've run the main logic through Lua on the terminal and it works:
$ lua
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> comment = "<!-- blah -->"
> comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah")
> print (comment)
## blah
But I'm failing to integrate it with Pandoc (no change is registered in
file.html). It's probably due to my misunderstanding of functions (not a
programmer!).
TIA.
/pm
--
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/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UKcVYPNzR8i8rDZorXw%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 3515 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CAMxYqzEvRHcFQ1BYsFODC-Bd36=LfO-UKcVYPNzR8i8rDZorXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Lua filter to convert Markdown comment [not found] ` <CAMxYqzEvRHcFQ1BYsFODC-Bd36=LfO-UKcVYPNzR8i8rDZorXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-01-14 18:51 ` John MacFarlane [not found] ` <m2h7njgxme.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: John MacFarlane @ 2021-01-14 18:51 UTC (permalink / raw) To: Peter Matulis, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw What you want to do is match on a RawBlock element. Something like function RawBlock(el) if el.text:match("<!--") then content = -- fill this in based on el.text return pandoc.Header(2, content) end end Peter Matulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > Hi. I'm new to Pandoc & Lua but my present issue is straightforward. I am > converting a Markdown file to HTML with pandoc like this: > > pandoc -L filter.lua -f gfm -t html -o file.html file.md > > Where file.md contains a line with this MD comment (the MD file was > obtained by converting from RST where I had to seed that file with an RST > comment to use as a placeholder for what I'm doing here): > > <!-- blah --> > > I simply want to convert this into an actual (second-level) MD header: > > ## blah > > From what I've read, I would ideally specify an "element" that will be > acted upon, but what is a comment considered? Anyway, I think I can specify > `Pandoc` to mean "check the entire document", and that's what I've done > here (I will eventually be iterating through multiple MD files so I should > really not be doing it like this; please advise!): > > function Pandoc (value) > comment = "<!-- blah -->" > comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") > return value > end > > I've run the main logic through Lua on the terminal and it works: > > $ lua > Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio >> comment = "<!-- blah -->" >> comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >> print (comment) > ## blah > > But I'm failing to integrate it with Pandoc (no change is registered in > file.html). It's probably due to my misunderstanding of functions (not a > programmer!). > > TIA. > > /pm > > -- > 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/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UKcVYPNzR8i8rDZorXw%40mail.gmail.com. ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <m2h7njgxme.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>]
* Re: Lua filter to convert Markdown comment [not found] ` <m2h7njgxme.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> @ 2021-01-14 20:57 ` Peter Matulis [not found] ` <CAMxYqzEn22Y4goKKW-D3Coqi5UTNR+6AgfcJAkJZPy8qtXjvjQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Peter Matulis @ 2021-01-14 20:57 UTC (permalink / raw) To: John MacFarlane; +Cc: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 2863 bytes --] Gratitude. This got me going. On Thu, 14 Jan 2021 at 13:52, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote: > > What you want to do is match on a RawBlock element. > Something like > > function RawBlock(el) > if el.text:match("<!--") then > content = -- fill this in based on el.text > return pandoc.Header(2, content) > end > end > > > Peter Matulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > Hi. I'm new to Pandoc & Lua but my present issue is straightforward. I am > > converting a Markdown file to HTML with pandoc like this: > > > > pandoc -L filter.lua -f gfm -t html -o file.html file.md > > > > Where file.md contains a line with this MD comment (the MD file was > > obtained by converting from RST where I had to seed that file with an RST > > comment to use as a placeholder for what I'm doing here): > > > > <!-- blah --> > > > > I simply want to convert this into an actual (second-level) MD header: > > > > ## blah > > > > From what I've read, I would ideally specify an "element" that will be > > acted upon, but what is a comment considered? Anyway, I think I can > specify > > `Pandoc` to mean "check the entire document", and that's what I've done > > here (I will eventually be iterating through multiple MD files so I > should > > really not be doing it like this; please advise!): > > > > function Pandoc (value) > > comment = "<!-- blah -->" > > comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") > > return value > > end > > > > I've run the main logic through Lua on the terminal and it works: > > > > $ lua > > Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio > >> comment = "<!-- blah -->" > >> comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") > >> print (comment) > > ## blah > > > > But I'm failing to integrate it with Pandoc (no change is registered in > > file.html). It's probably due to my misunderstanding of functions (not a > > programmer!). > > > > TIA. > > > > /pm > > > > -- > > 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/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UKcVYPNzR8i8rDZorXw%40mail.gmail.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/CAMxYqzEn22Y4goKKW-D3Coqi5UTNR%2B6AgfcJAkJZPy8qtXjvjQ%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 4405 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CAMxYqzEn22Y4goKKW-D3Coqi5UTNR+6AgfcJAkJZPy8qtXjvjQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Lua filter to convert Markdown comment [not found] ` <CAMxYqzEn22Y4goKKW-D3Coqi5UTNR+6AgfcJAkJZPy8qtXjvjQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-01-15 3:38 ` Peter Matulis [not found] ` <CAMxYqzHK6BvhbzE__4__Po+wizq_4b3CZT9q=9ZQ1iF9JR-VSg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Peter Matulis @ 2021-01-15 3:38 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 3615 bytes --] So I now have this: function RawBlock(el) if el.text:match("%<%!%-%- foo %-%-%>") then content = "foo" return pandoc.Header(2, content) end end There are actually about a dozen such known Markdown comments (e.g. 'foo', 'bar'). Instead of creating multiple files I'd like to have just one that uses a regex and capture group: if el.text:match("%<%!%-%- (%a+) %-%-%>") then I'm just unsure how to refer to the capture in a conditional statement (i.e. "if 'foo' is captured then 'content' = "foo", elsif 'bar' is captured then 'content' = "bar"). On Thu, 14 Jan 2021 at 15:57, Peter Matulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > Gratitude. This got me going. > > On Thu, 14 Jan 2021 at 13:52, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote: > >> >> What you want to do is match on a RawBlock element. >> Something like >> >> function RawBlock(el) >> if el.text:match("<!--") then >> content = -- fill this in based on el.text >> return pandoc.Header(2, content) >> end >> end >> >> >> Peter Matulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: >> >> > Hi. I'm new to Pandoc & Lua but my present issue is straightforward. I >> am >> > converting a Markdown file to HTML with pandoc like this: >> > >> > pandoc -L filter.lua -f gfm -t html -o file.html file.md >> > >> > Where file.md contains a line with this MD comment (the MD file was >> > obtained by converting from RST where I had to seed that file with an >> RST >> > comment to use as a placeholder for what I'm doing here): >> > >> > <!-- blah --> >> > >> > I simply want to convert this into an actual (second-level) MD header: >> > >> > ## blah >> > >> > From what I've read, I would ideally specify an "element" that will be >> > acted upon, but what is a comment considered? Anyway, I think I can >> specify >> > `Pandoc` to mean "check the entire document", and that's what I've done >> > here (I will eventually be iterating through multiple MD files so I >> should >> > really not be doing it like this; please advise!): >> > >> > function Pandoc (value) >> > comment = "<!-- blah -->" >> > comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >> > return value >> > end >> > >> > I've run the main logic through Lua on the terminal and it works: >> > >> > $ lua >> > Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio >> >> comment = "<!-- blah -->" >> >> comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >> >> print (comment) >> > ## blah >> > >> > But I'm failing to integrate it with Pandoc (no change is registered in >> > file.html). It's probably due to my misunderstanding of functions (not a >> > programmer!). >> > >> > TIA. >> > >> > /pm >> > >> > -- >> > 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/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UKcVYPNzR8i8rDZorXw%40mail.gmail.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/CAMxYqzHK6BvhbzE__4__Po%2Bwizq_4b3CZT9q%3D9ZQ1iF9JR-VSg%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 6590 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CAMxYqzHK6BvhbzE__4__Po+wizq_4b3CZT9q=9ZQ1iF9JR-VSg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Lua filter to convert Markdown comment [not found] ` <CAMxYqzHK6BvhbzE__4__Po+wizq_4b3CZT9q=9ZQ1iF9JR-VSg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-01-15 9:19 ` BPJ [not found] ` <CADAJKhDDZXjEBCWKRBnJChN1F-i_2BctoD1WHauPLXJHTKbGKA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: BPJ @ 2021-01-15 9:19 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 5388 bytes --] Almost there. You need `content = {pandoc.Str"Foo"}` since the content of a Header is a list of inline elements. As for multiple possible values Lua patterns are, as you seem to have discovered, a bit challenged in that they don't support alternations. The best solution is to use a table: ``````lua -- Localize `pandoc` to a shorter name to save space & type less! local p = pandoc -- This is your "substitution" table. local text4match = { -- If you need styling do this: foo = { p.Str"Foo", p.Space(), p.Str"and", p.Space(), p.Emph(p.Str"more.") }, -- If you do not need styling you can do this: bar = { p.Str"Bar and less." }, } function RawBlock (elem) local key = elem.text:match"%<%!%-%-%s*(%a+)%s*%-%-%>" if key then local text = text4match[key] if text then return p.Header(2, text) end end -- No match, no text, ignore this elem return nil end `````` HTH, /bpj -- Better --help|less than helpless Den fre 15 jan. 2021 04:39Peter Matulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev: > So I now have this: > > function RawBlock(el) > if el.text:match("%<%!%-%- foo %-%-%>") then > content = "foo" > return pandoc.Header(2, content) > end > end > > There are actually about a dozen such known Markdown comments (e.g. 'foo', > 'bar'). > Instead of creating multiple files I'd like to have just one that uses a > regex and capture group: > > if el.text:match("%<%!%-%- (%a+) %-%-%>") then > > I'm just unsure how to refer to the capture in a conditional statement > (i.e. "if 'foo' is captured then 'content' = "foo", elsif 'bar' is > captured then 'content' = "bar"). > > > On Thu, 14 Jan 2021 at 15:57, Peter Matulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Gratitude. This got me going. >> >> On Thu, 14 Jan 2021 at 13:52, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote: >> >>> >>> What you want to do is match on a RawBlock element. >>> Something like >>> >>> function RawBlock(el) >>> if el.text:match("<!--") then >>> content = -- fill this in based on el.text >>> return pandoc.Header(2, content) >>> end >>> end >>> >>> >>> Peter Matulis <pmatulis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: >>> >>> > Hi. I'm new to Pandoc & Lua but my present issue is straightforward. I >>> am >>> > converting a Markdown file to HTML with pandoc like this: >>> > >>> > pandoc -L filter.lua -f gfm -t html -o file.html file.md >>> > >>> > Where file.md contains a line with this MD comment (the MD file was >>> > obtained by converting from RST where I had to seed that file with an >>> RST >>> > comment to use as a placeholder for what I'm doing here): >>> > >>> > <!-- blah --> >>> > >>> > I simply want to convert this into an actual (second-level) MD header: >>> > >>> > ## blah >>> > >>> > From what I've read, I would ideally specify an "element" that will be >>> > acted upon, but what is a comment considered? Anyway, I think I can >>> specify >>> > `Pandoc` to mean "check the entire document", and that's what I've done >>> > here (I will eventually be iterating through multiple MD files so I >>> should >>> > really not be doing it like this; please advise!): >>> > >>> > function Pandoc (value) >>> > comment = "<!-- blah -->" >>> > comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >>> > return value >>> > end >>> > >>> > I've run the main logic through Lua on the terminal and it works: >>> > >>> > $ lua >>> > Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio >>> >> comment = "<!-- blah -->" >>> >> comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >>> >> print (comment) >>> > ## blah >>> > >>> > But I'm failing to integrate it with Pandoc (no change is registered in >>> > file.html). It's probably due to my misunderstanding of functions (not >>> a >>> > programmer!). >>> > >>> > TIA. >>> > >>> > /pm >>> > >>> > -- >>> > 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/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UKcVYPNzR8i8rDZorXw%40mail.gmail.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/CAMxYqzHK6BvhbzE__4__Po%2Bwizq_4b3CZT9q%3D9ZQ1iF9JR-VSg%40mail.gmail.com > <https://groups.google.com/d/msgid/pandoc-discuss/CAMxYqzHK6BvhbzE__4__Po%2Bwizq_4b3CZT9q%3D9ZQ1iF9JR-VSg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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/CADAJKhDDZXjEBCWKRBnJChN1F-i_2BctoD1WHauPLXJHTKbGKA%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 9714 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CADAJKhDDZXjEBCWKRBnJChN1F-i_2BctoD1WHauPLXJHTKbGKA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Lua filter to convert Markdown comment [not found] ` <CADAJKhDDZXjEBCWKRBnJChN1F-i_2BctoD1WHauPLXJHTKbGKA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2021-01-15 19:14 ` Peter 0 siblings, 0 replies; 6+ messages in thread From: Peter @ 2021-01-15 19:14 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 5672 bytes --] This is really nice. Gratitude. On Friday, 15 January 2021 at 04:19:51 UTC-5 BP wrote: > > Almost there. You need > > > `content = {pandoc.Str"Foo"}` > > > since the content of a Header is a list of inline elements. > > As for multiple possible values Lua patterns are, as you seem to have > discovered, a bit challenged in that they don't support alternations. The > best solution is to use a table: > > ``````lua > -- Localize `pandoc` to a shorter name to save space & type less! > local p = pandoc > > -- This is your "substitution" table. > local text4match = { > -- If you need styling do this: > foo = { p.Str"Foo", p.Space(), p.Str"and", p.Space(), > p.Emph(p.Str"more.") }, > -- If you do not need styling you can do this: > bar = { p.Str"Bar and less." }, > } > > function RawBlock (elem) > local key = elem.text:match"%<%!%-%-%s*(%a+)%s*%-%-%>" > if key then > local text = text4match[key] > if text then > return p.Header(2, text) > end > end > -- No match, no text, ignore this elem > return nil > end > `````` > > HTH, > > /bpj > > -- > Better --help|less than helpless > > Den fre 15 jan. 2021 04:39Peter Matulis <pmat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev: > >> So I now have this: >> >> function RawBlock(el) >> if el.text:match("%<%!%-%- foo %-%-%>") then >> content = "foo" >> return pandoc.Header(2, content) >> end >> end >> >> There are actually about a dozen such known Markdown comments (e.g. >> 'foo', 'bar'). >> Instead of creating multiple files I'd like to have just one that uses a >> regex and capture group: >> >> if el.text:match("%<%!%-%- (%a+) %-%-%>") then >> >> I'm just unsure how to refer to the capture in a conditional statement >> (i.e. "if 'foo' is captured then 'content' = "foo", elsif 'bar' is >> captured then 'content' = "bar"). >> >> >> On Thu, 14 Jan 2021 at 15:57, Peter Matulis <pmat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Gratitude. This got me going. >>> >>> On Thu, 14 Jan 2021 at 13:52, John MacFarlane <j...-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote: >>> >>>> >>>> What you want to do is match on a RawBlock element. >>>> Something like >>>> >>>> function RawBlock(el) >>>> if el.text:match("<!--") then >>>> content = -- fill this in based on el.text >>>> return pandoc.Header(2, content) >>>> end >>>> end >>>> >>>> >>>> Peter Matulis <pmat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: >>>> >>>> > Hi. I'm new to Pandoc & Lua but my present issue is straightforward. >>>> I am >>>> > converting a Markdown file to HTML with pandoc like this: >>>> > >>>> > pandoc -L filter.lua -f gfm -t html -o file.html file.md >>>> > >>>> > Where file.md contains a line with this MD comment (the MD file was >>>> > obtained by converting from RST where I had to seed that file with an >>>> RST >>>> > comment to use as a placeholder for what I'm doing here): >>>> > >>>> > <!-- blah --> >>>> > >>>> > I simply want to convert this into an actual (second-level) MD header: >>>> > >>>> > ## blah >>>> > >>>> > From what I've read, I would ideally specify an "element" that will be >>>> > acted upon, but what is a comment considered? Anyway, I think I can >>>> specify >>>> > `Pandoc` to mean "check the entire document", and that's what I've >>>> done >>>> > here (I will eventually be iterating through multiple MD files so I >>>> should >>>> > really not be doing it like this; please advise!): >>>> > >>>> > function Pandoc (value) >>>> > comment = "<!-- blah -->" >>>> > comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >>>> > return value >>>> > end >>>> > >>>> > I've run the main logic through Lua on the terminal and it works: >>>> > >>>> > $ lua >>>> > Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio >>>> >> comment = "<!-- blah -->" >>>> >> comment = comment:gsub("%<%!%-%- blah %-%-%>", "## blah") >>>> >> print (comment) >>>> > ## blah >>>> > >>>> > But I'm failing to integrate it with Pandoc (no change is registered >>>> in >>>> > file.html). It's probably due to my misunderstanding of functions >>>> (not a >>>> > programmer!). >>>> > >>>> > TIA. >>>> > >>>> > /pm >>>> > >>>> > -- >>>> > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> > To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/pandoc-discuss/CAMxYqzEvRHcFQ1BYsFODC-Bd36%3DLfO-UKcVYPNzR8i8rDZorXw%40mail.gmail.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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/pandoc-discuss/CAMxYqzHK6BvhbzE__4__Po%2Bwizq_4b3CZT9q%3D9ZQ1iF9JR-VSg%40mail.gmail.com >> <https://groups.google.com/d/msgid/pandoc-discuss/CAMxYqzHK6BvhbzE__4__Po%2Bwizq_4b3CZT9q%3D9ZQ1iF9JR-VSg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/e17e3930-8788-437b-b874-9b9bd9b6d14bn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 10530 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-15 19:14 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-01-14 18:08 Lua filter to convert Markdown comment Peter Matulis [not found] ` <CAMxYqzEvRHcFQ1BYsFODC-Bd36=LfO-UKcVYPNzR8i8rDZorXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-01-14 18:51 ` John MacFarlane [not found] ` <m2h7njgxme.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2021-01-14 20:57 ` Peter Matulis [not found] ` <CAMxYqzEn22Y4goKKW-D3Coqi5UTNR+6AgfcJAkJZPy8qtXjvjQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-01-15 3:38 ` Peter Matulis [not found] ` <CAMxYqzHK6BvhbzE__4__Po+wizq_4b3CZT9q=9ZQ1iF9JR-VSg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-01-15 9:19 ` BPJ [not found] ` <CADAJKhDDZXjEBCWKRBnJChN1F-i_2BctoD1WHauPLXJHTKbGKA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2021-01-15 19:14 ` Peter
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).