* Making a Table in a python filter @ 2020-11-27 13:14 Thomas Hodgson [not found] ` <398d2024-9d0a-4921-a03c-d8ae60c161edn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Thomas Hodgson @ 2020-11-27 13:14 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1132 bytes --] I have been playing with a python filter which will take code blocks containing logical formulae, e.g., ('P and Q') and produce a truth table. I have done this for LaTeX output. I use the truth-table-generator python package to create the LaTeX table, and then the filter returns a RawBlock with that LaTeX code. The python package will also return tables in Markdown. Is there a simple way for the filter to turn that Markdown string into a Pandoc Table object? The filter could then return the Table, and it would then work for any output format. I see in principle how I could write a function that takes a string a returns a table. But it seems to me that it's likely that somebody has already done this. -- 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/398d2024-9d0a-4921-a03c-d8ae60c161edn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1475 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <398d2024-9d0a-4921-a03c-d8ae60c161edn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Making a Table in a python filter [not found] ` <398d2024-9d0a-4921-a03c-d8ae60c161edn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-11-27 17:55 ` John MacFarlane [not found] ` <m2mtz2r8f5.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2020-11-30 6:51 ` christi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 1 sibling, 1 reply; 6+ messages in thread From: John MacFarlane @ 2020-11-27 17:55 UTC (permalink / raw) To: Thomas Hodgson, pandoc-discuss In Lua filters you can use pandoc.read to parse the content. In Haskell you can just call pandoc's Markdown reader. In Python, I don't know -- I suppose you could start a process and call the pandoc executable? Thomas Hodgson <thomas.hodgson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > I have been playing with a python filter which will take code blocks > containing logical formulae, e.g., ('P and Q') and produce a truth table. I > have done this for LaTeX output. I use the truth-table-generator python > package to create the LaTeX table, and then the filter returns a RawBlock > with that LaTeX code. > > The python package will also return tables in Markdown. Is there a simple > way for the filter to turn that Markdown string into a Pandoc Table object? > The filter could then return the Table, and it would then work for any > output format. > > I see in principle how I could write a function that takes a string a > returns a table. But it seems to me that it's likely that somebody has > already done this. > > -- > 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/398d2024-9d0a-4921-a03c-d8ae60c161edn%40googlegroups.com. ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <m2mtz2r8f5.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>]
* Re: Making a Table in a python filter [not found] ` <m2mtz2r8f5.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> @ 2020-11-28 16:42 ` Thomas Hodgson [not found] ` <133a8de0-0976-4a95-b778-a5d4ce66fd4an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Thomas Hodgson @ 2020-11-28 16:42 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2757 bytes --] Thanks! I got the Python approach working, but I have the following, possibly, confused question. My code returns a string which represents a Pandoc table object, like this: ``` Table [] [AlignCenter,AlignCenter,AlignCenter] [0.0,0.0,0.0] [[Plain [Str "P"]] ,[Plain [Str "Q"]] ,[Plain [Str "P",Space,Str "and",Space,Str "Q"]]] [[[Plain [Str "1"]] ,[Plain [Str "1"]] ,[Plain [Str "1"]]] ,[[Plain [Str "1"]] ,[Plain [Str "0"]] ,[Plain [Str "0"]]] ,[[Plain [Str "0"]] ,[Plain [Str "1"]] ,[Plain [Str "0"]]] ,[[Plain [Str "0"]] ,[Plain [Str "0"]] ,[Plain [Str "0"]]]] ``` But, I can't just return that. So, I'm still looking for a simple way to turn that into a Table object that I can return. Or am I missing something? On Friday, 27 November 2020 at 18:56:00 UTC+1 John MacFarlane wrote: > > In Lua filters you can use pandoc.read to parse the content. > > In Haskell you can just call pandoc's Markdown reader. > > In Python, I don't know -- I suppose you could start a > process and call the pandoc executable? > > > Thomas Hodgson <thomas....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > I have been playing with a python filter which will take code blocks > > containing logical formulae, e.g., ('P and Q') and produce a truth > table. I > > have done this for LaTeX output. I use the truth-table-generator python > > package to create the LaTeX table, and then the filter returns a > RawBlock > > with that LaTeX code. > > > > The python package will also return tables in Markdown. Is there a > simple > > way for the filter to turn that Markdown string into a Pandoc Table > object? > > The filter could then return the Table, and it would then work for any > > output format. > > > > I see in principle how I could write a function that takes a string a > > returns a table. But it seems to me that it's likely that somebody has > > already done this. > > > > -- > > 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/398d2024-9d0a-4921-a03c-d8ae60c161edn%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/133a8de0-0976-4a95-b778-a5d4ce66fd4an%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 4080 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <133a8de0-0976-4a95-b778-a5d4ce66fd4an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Making a Table in a python filter [not found] ` <133a8de0-0976-4a95-b778-a5d4ce66fd4an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-11-28 17:39 ` Thomas Hodgson 0 siblings, 0 replies; 6+ messages in thread From: Thomas Hodgson @ 2020-11-28 17:39 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 3760 bytes --] I realised that the best option for me is probably Panflute, which has a function to convert text to a pandoc object. On Sat, 28 Nov 2020 at 17:42, Thomas Hodgson <thomas.hodgson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > Thanks! > > I got the Python approach working, but I have the following, possibly, > confused question. My code returns a string which represents a Pandoc table > object, like this: > > ``` > Table [] [AlignCenter,AlignCenter,AlignCenter] [0.0,0.0,0.0] > [[Plain [Str "P"]] > ,[Plain [Str "Q"]] > ,[Plain [Str "P",Space,Str "and",Space,Str "Q"]]] > [[[Plain [Str "1"]] > ,[Plain [Str "1"]] > ,[Plain [Str "1"]]] > ,[[Plain [Str "1"]] > ,[Plain [Str "0"]] > ,[Plain [Str "0"]]] > ,[[Plain [Str "0"]] > ,[Plain [Str "1"]] > ,[Plain [Str "0"]]] > ,[[Plain [Str "0"]] > ,[Plain [Str "0"]] > ,[Plain [Str "0"]]]] > ``` > > But, I can't just return that. So, I'm still looking for a simple way to > turn that into a Table object that I can return. Or am I missing something? > > On Friday, 27 November 2020 at 18:56:00 UTC+1 John MacFarlane wrote: > >> >> In Lua filters you can use pandoc.read to parse the content. >> >> In Haskell you can just call pandoc's Markdown reader. >> >> In Python, I don't know -- I suppose you could start a >> process and call the pandoc executable? >> >> >> Thomas Hodgson <thomas....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: >> >> > I have been playing with a python filter which will take code blocks >> > containing logical formulae, e.g., ('P and Q') and produce a truth >> table. I >> > have done this for LaTeX output. I use the truth-table-generator python >> > package to create the LaTeX table, and then the filter returns a >> RawBlock >> > with that LaTeX code. >> > >> > The python package will also return tables in Markdown. Is there a >> simple >> > way for the filter to turn that Markdown string into a Pandoc Table >> object? >> > The filter could then return the Table, and it would then work for any >> > output format. >> > >> > I see in principle how I could write a function that takes a string a >> > returns a table. But it seems to me that it's likely that somebody has >> > already done this. >> > >> > -- >> > 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/398d2024-9d0a-4921-a03c-d8ae60c161edn%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/yAgboqNanPA/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/133a8de0-0976-4a95-b778-a5d4ce66fd4an%40googlegroups.com > <https://groups.google.com/d/msgid/pandoc-discuss/133a8de0-0976-4a95-b778-a5d4ce66fd4an%40googlegroups.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/CAFtWZz%3D2fty5Cz8vSrsHjx6Vu9gEYULbPUyB-ttCFy9%2BDpmwQw%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 5432 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Making a Table in a python filter [not found] ` <398d2024-9d0a-4921-a03c-d8ae60c161edn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-27 17:55 ` John MacFarlane @ 2020-11-30 6:51 ` christi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [not found] ` <d67ad98b-df03-402f-b2ce-e15480108ec4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 1 sibling, 1 reply; 6+ messages in thread From: christi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org @ 2020-11-30 6:51 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1909 bytes --] I have been working on a library that essentially eases the creation of pandoc tables in Python. (It converts the AST in an internal representation with additional helpers.) You might find it easier to create your table there and just call a method to convert it to an AST. There's some complication as there's hint of yet another change in the AST so I paused the project a bit. But probably I will release it in the coming week with lesser features than I initially planned. But if you want to do it now, yes, panflute AST is the way to go. You should not construct the AST directly. My library also builds on top of panflute. On Friday, November 27, 2020 at 5:14:19 AM UTC-8 thomas....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > I have been playing with a python filter which will take code blocks > containing logical formulae, e.g., ('P and Q') and produce a truth table. I > have done this for LaTeX output. I use the truth-table-generator python > package to create the LaTeX table, and then the filter returns a RawBlock > with that LaTeX code. > > The python package will also return tables in Markdown. Is there a simple > way for the filter to turn that Markdown string into a Pandoc Table object? > The filter could then return the Table, and it would then work for any > output format. > > I see in principle how I could write a function that takes a string a > returns a table. But it seems to me that it's likely that somebody has > already done this. > -- 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/d67ad98b-df03-402f-b2ce-e15480108ec4n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 2528 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <d67ad98b-df03-402f-b2ce-e15480108ec4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Making a Table in a python filter [not found] ` <d67ad98b-df03-402f-b2ce-e15480108ec4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-11-30 18:22 ` Thomas Hodgson 0 siblings, 0 replies; 6+ messages in thread From: Thomas Hodgson @ 2020-11-30 18:22 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 2924 bytes --] Thanks. I would be interested in your library, when it's done. I got my simple filter to work: https://gitlab.com/-/snippets/2044228 On Mon, 30 Nov 2020 at 07:51, christi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org < christian.kolen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > I have been working on a library that essentially eases the creation of > pandoc tables in Python. (It converts the AST in an internal representation > with additional helpers.) > > You might find it easier to create your table there and just call a method > to convert it to an AST. > > There's some complication as there's hint of yet another change in the AST > so I paused the project a bit. But probably I will release it in the coming > week with lesser features than I initially planned. > > But if you want to do it now, yes, panflute AST is the way to go. You > should not construct the AST directly. My library also builds on top of > panflute. > > On Friday, November 27, 2020 at 5:14:19 AM UTC-8 thomas....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > wrote: > >> >> I have been playing with a python filter which will take code blocks >> containing logical formulae, e.g., ('P and Q') and produce a truth table. I >> have done this for LaTeX output. I use the truth-table-generator python >> package to create the LaTeX table, and then the filter returns a RawBlock >> with that LaTeX code. >> >> The python package will also return tables in Markdown. Is there a simple >> way for the filter to turn that Markdown string into a Pandoc Table object? >> The filter could then return the Table, and it would then work for any >> output format. >> >> I see in principle how I could write a function that takes a string a >> returns a table. But it seems to me that it's likely that somebody has >> already done this. >> > -- > 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/yAgboqNanPA/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/d67ad98b-df03-402f-b2ce-e15480108ec4n%40googlegroups.com > <https://groups.google.com/d/msgid/pandoc-discuss/d67ad98b-df03-402f-b2ce-e15480108ec4n%40googlegroups.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/CAFtWZznh2fTwjY8h5%2B%3DQSL4yV3sFS8o_ofy0gT8STMPiXxSo3w%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 4362 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-11-30 18:22 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-11-27 13:14 Making a Table in a python filter Thomas Hodgson [not found] ` <398d2024-9d0a-4921-a03c-d8ae60c161edn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-27 17:55 ` John MacFarlane [not found] ` <m2mtz2r8f5.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2020-11-28 16:42 ` Thomas Hodgson [not found] ` <133a8de0-0976-4a95-b778-a5d4ce66fd4an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-28 17:39 ` Thomas Hodgson 2020-11-30 6:51 ` christi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org [not found] ` <d67ad98b-df03-402f-b2ce-e15480108ec4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-30 18:22 ` Thomas Hodgson
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).