public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* pandoc.write helper function for Lua filters?
@ 2019-02-14 20:25 msprev
       [not found] ` <9b10bca2-42b9-4c8b-84ca-21a39daee407-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: msprev @ 2019-02-14 20:25 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1272 bytes --]

The pandoc.read helper function is incredibly useful in Lua filters. Is 
there any chance of adding a counterpart to expose similar functionality 
for writers, e.g. a pandoc.write function that takes as arguments a pandoc 
document and output format and yields as output a string of formatted text? 

I've wanted to write a Lua filter to extract bits of the ast and kick them 
out, for external use, as strings of html or strings of markdown. More 
generally, when writing Lua filters, it would be incredibly useful for 
diagnostic/debugging purposes to be able to print out bits of the ast to 
the terminal as a string (e.g. in native output format) to make sure the 
filter is working as expected.

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/9b10bca2-42b9-4c8b-84ca-21a39daee407%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1706 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pandoc.write helper function for Lua filters?
       [not found] ` <9b10bca2-42b9-4c8b-84ca-21a39daee407-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-02-15  8:51   ` BPJ
       [not found]     ` <CADAJKhBMeaaJZSXMSwhprGZvmYOLrDcLCk8iHkhpTJpkwZS8fw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2019-02-15  9:39   ` Albert Krewinkel
  1 sibling, 1 reply; 5+ messages in thread
From: BPJ @ 2019-02-15  8:51 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 2392 bytes --]

You can shell out to pandoc to do that, even though it is of course
probably slower than what a built-in function would be. The Perl Pandoc
wrapper does just that. <https://metacpan.org/pod/Pandoc> The pipe function
in Lua filters should make that fairly easy.

Den tors 14 feb. 2019 21:26 skrev msprev <msprevak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:

> The pandoc.read helper function is incredibly useful in Lua filters. Is
> there any chance of adding a counterpart to expose similar functionality
> for writers, e.g. a pandoc.write function that takes as arguments a pandoc
> document and output format and yields as output a string of formatted text?
>
> I've wanted to write a Lua filter to extract bits of the ast and kick them
> out, for external use, as strings of html or strings of markdown. More
> generally, when writing Lua filters, it would be incredibly useful for
> diagnostic/debugging purposes to be able to print out bits of the ast to
> the terminal as a string (e.g. in native output format) to make sure the
> filter is working as expected.
>
> --
> 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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/9b10bca2-42b9-4c8b-84ca-21a39daee407%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/9b10bca2-42b9-4c8b-84ca-21a39daee407%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhBMeaaJZSXMSwhprGZvmYOLrDcLCk8iHkhpTJpkwZS8fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 3475 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pandoc.write helper function for Lua filters?
       [not found]     ` <CADAJKhBMeaaJZSXMSwhprGZvmYOLrDcLCk8iHkhpTJpkwZS8fw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-02-15  9:04       ` msprev
  0 siblings, 0 replies; 5+ messages in thread
From: msprev @ 2019-02-15  9:04 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 845 bytes --]

Shelling out would not solve this problem. In order to shell out to a pandoc executable you would need to serialise the ast into a format that it can read (markdown, html, native, etc). But this is precisely the problem one needs a pandoc.write function to solve. 

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/cdf87cae-e5dc-454c-8c99-90d178736ab2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pandoc.write helper function for Lua filters?
       [not found] ` <9b10bca2-42b9-4c8b-84ca-21a39daee407-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-02-15  8:51   ` BPJ
@ 2019-02-15  9:39   ` Albert Krewinkel
       [not found]     ` <afe71fef-e628-4a93-b843-8f18b3f59f9d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Albert Krewinkel @ 2019-02-15  9:39 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2127 bytes --]

It's on the agenda. We want to get things right, which takes time. Relevant 
GitHub issues and pull requests include:

   - https://github.com/jgm/pandoc/pull/5118
   - https://github.com/jgm/pandoc/issues/5221
   - https://github.com/jgm/pandoc/pull/5056

For now, I suggest to write a simple shell script filter which puts the 
output into a RawBlock element.

#!/bin/sh
FORMAT=$1
OUTPUT=$(pandoc --from=json --to=$FORMAT - | jq -aR --slurp .)
PANDOC_API_VERSION=$(pandoc --version | sed -ne 's/.*pandoc-types 
\([0-9.]*\).*/\1/p' | tr '.' ',')
printf '{"blocks":[{"t":"RawBlock", 
"c":["%s",%s]}],"meta":{},"pandoc-api-version":[%s]}\n' \
       $FORMAT "$OUTPUT" "$PANDOC_API_VERSION"

The filter can then be called from Lua via pandoc.utils.run_json_filter.

On Thursday, February 14, 2019 at 9:25:38 PM UTC+1, msprev wrote:
>
> The pandoc.read helper function is incredibly useful in Lua filters. Is 
> there any chance of adding a counterpart to expose similar functionality 
> for writers, e.g. a pandoc.write function that takes as arguments a pandoc 
> document and output format and yields as output a string of formatted text? 
>
> I've wanted to write a Lua filter to extract bits of the ast and kick them 
> out, for external use, as strings of html or strings of markdown. More 
> generally, when writing Lua filters, it would be incredibly useful for 
> diagnostic/debugging purposes to be able to print out bits of the ast to 
> the terminal as a string (e.g. in native output format) to make sure the 
> filter is working as expected.
>

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/afe71fef-e628-4a93-b843-8f18b3f59f9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 6399 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pandoc.write helper function for Lua filters?
       [not found]     ` <afe71fef-e628-4a93-b843-8f18b3f59f9d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-02-15 10:03       ` msprev
  0 siblings, 0 replies; 5+ messages in thread
From: msprev @ 2019-02-15 10:03 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 631 bytes --]

Thanks. That is good to know it’s on the agenda!

-- 
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/83f5f00a-d4c3-41c3-a613-c8779e53fef8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-15 10:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-14 20:25 pandoc.write helper function for Lua filters? msprev
     [not found] ` <9b10bca2-42b9-4c8b-84ca-21a39daee407-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-15  8:51   ` BPJ
     [not found]     ` <CADAJKhBMeaaJZSXMSwhprGZvmYOLrDcLCk8iHkhpTJpkwZS8fw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-15  9:04       ` msprev
2019-02-15  9:39   ` Albert Krewinkel
     [not found]     ` <afe71fef-e628-4a93-b843-8f18b3f59f9d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-02-15 10:03       ` msprev

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).