* Pandoc 2.18 - Custom writer working example @ 2022-06-01 23:01 Felix SOEDJEDE [not found] ` <8528d41a-d6dd-4ca7-b38a-13955a9d1eabn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Felix SOEDJEDE @ 2022-06-01 23:01 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1783 bytes --] Hello everyone, In Pandoc 2.18, custom writers were added: https://pandoc.org/custom-writers.html#new-style I tried to use it but it's not working and I don't know if it's an error or I'm using it the wrong way. I have a lua filter -- PANDOC_VERSION:must_be_at_least '2.18' print(PANDOC_DOCUMENT) function Writer(doc, opts) print('We enter don\'t enter "Writer"') return pandoc.write(doc, 'markdown', opts) end function Doc(body, meta, vars) print('We enter don\'t enter "Doc"') vars.date = vars.date or meta.data or os.date '%B %e, %Y' return body, vars end function Pandoc(doc) print('We enter "Pandoc"') end function Header(header) print('We enter "Header"') end -- Command used "pandoc --standalone --verbose --lua-filter=sample.lua --output=output.md sample.md" - None of *Doc*, *Writer* is called. - "print(PANDOC_DOCUMENT)" returns "nil" Some links - https://github.com/jgm/pandoc/pull/7897 (The MR to see "Writer" was implemented) - https://gist.github.com/tarleb/5a9c3fbfa47b0e6d3643efd8af2994b9 : exemple filter I tested but not working - https://groups.google.com/g/pandoc-discuss/c/Ti4Qsehn1Z8/m/Btu_uE6IBwAJ: Question asked but another person before the fonctionnality was released. It does not contains an answer to my question Question: Does anyone have a minimal working example for "Doc" or "Writer" I could use? Regards -- 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/8528d41a-d6dd-4ca7-b38a-13955a9d1eabn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 4170 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <8528d41a-d6dd-4ca7-b38a-13955a9d1eabn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Pandoc 2.18 - Custom writer working example [not found] ` <8528d41a-d6dd-4ca7-b38a-13955a9d1eabn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2022-06-02 5:27 ` Albert Krewinkel [not found] ` <87fskn6345.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Albert Krewinkel @ 2022-06-02 5:27 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Felix SOEDJEDE <soefelix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > In Pandoc 2.18, custom writers were added: > https://pandoc.org/custom-writers.html#new-style > > I tried to use it but it's not working and I don't know if it's an > error or I'm using it the wrong way. > > [...] > > Command used "pandoc --standalone --verbose --lua-filter=sample.lua > --output=output.md sample.md" Pandoc expects the custom writer to be given as the argument of `-t`/`--to`/`-w`/`--write`. pandoc --standalone --verbose --to=sample.lua ... > Does anyone have a minimal working example for "Doc" or "Writer" I > could use? Here's a custom Markdown writer. It's an experiment designed to show how a new writer might be structured. It's a bit slow though. https://gist.github.com/tarleb/5a9c3fbfa47b0e6d3643efd8af2994b9 -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <87fskn6345.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>]
* Re: Pandoc 2.18 - Custom writer working example [not found] ` <87fskn6345.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> @ 2022-06-02 8:10 ` Felix SOEDJEDE [not found] ` <cde6d369-8813-41ed-a1ea-253901014b46n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Felix SOEDJEDE @ 2022-06-02 8:10 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2258 bytes --] @Albert 1/ Writer Using *--to=sample.lua* works when *--standalone* is not present and . Otherwise I have this error: *Could not find data file templates/default.sample.lua* Using *--writer=sample.lua* does not work. Error: "Unknown option --writer." I now know why using "--to" did not work. 2/ Accessing variables in lua filter I would like to have access to "variables" in lua filter. Currently I have access to "metadata" when I use "*function Pandoc(doc) ... end*" In the doc: https://pandoc.org/custom-writers.html#a-custom-html-writer, I saw this "*function Doc(body, meta, vars) ... end*" but it's never called in my tests. I prefer not to use "*function Writer*" for now if possible. Do you have any tips or working examples for that one? Thanks Le jeudi 2 juin 2022 à 07:33:54 UTC+2, Albert Krewinkel a écrit : > > Felix SOEDJEDE <soef...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > In Pandoc 2.18, custom writers were added: > > https://pandoc.org/custom-writers.html#new-style > > > > I tried to use it but it's not working and I don't know if it's an > > error or I'm using it the wrong way. > > > > [...] > > > > Command used "pandoc --standalone --verbose --lua-filter=sample.lua > > --output=output.md sample.md" > > Pandoc expects the custom writer to be given as the argument of > `-t`/`--to`/`-w`/`--write`. > > pandoc --standalone --verbose --to=sample.lua ... > > > Does anyone have a minimal working example for "Doc" or "Writer" I > > could use? > > Here's a custom Markdown writer. It's an experiment designed to show how > a new writer might be structured. It's a bit slow though. > https://gist.github.com/tarleb/5a9c3fbfa47b0e6d3643efd8af2994b9 > > > -- > 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/cde6d369-8813-41ed-a1ea-253901014b46n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 3829 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <cde6d369-8813-41ed-a1ea-253901014b46n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Pandoc 2.18 - Custom writer working example [not found] ` <cde6d369-8813-41ed-a1ea-253901014b46n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2022-06-02 8:43 ` Albert Krewinkel [not found] ` <87bkvb5tay.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Albert Krewinkel @ 2022-06-02 8:43 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Hi Felix, Felix SOEDJEDE <soefelix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > 1/ Writer > Using --to=sample.lua works when --standalone is not present and . > Otherwise I have this error: Could not find data file > templates/default.sample.lua Ah, right. With `--standalone` pandoc is looking for a template that matches the writer name. There isn't one of course. Just omit it. > Using --writer=sample.lua does not work. > Error: "Unknown option --writer." Whoops, should have been `--write`. I'm cutting down on coffee, I guess it shows. 😬 > 2/ Accessing variables in lua filter > I would like to have access to "variables" in lua filter. If you use `function Writer(doc, opts)`, then the variables are available via `opts.variables`. > I prefer not to use "function Writer" for now if possible. > Do you have any tips or working examples for that one? Do you mean an example of a classic custom writers? Pandoc has an example built-in, it's available via pandoc --print-default-data-file=sample.lua Classic writers are generally a bit easier (IMHO). I'd recommend new- style writers if you either base the new writer on one that's already included in pandoc, or if you want to make use of the `pandoc.layout` module to get nicer looking output. Other than those cases, classic writers are frequently the better choice. Out of curiosity, what output format are planning to generate? Cheers, Albert -- 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/87bkvb5tay.fsf%40zeitkraut.de. ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <87bkvb5tay.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>]
* Re: Pandoc 2.18 - Custom writer working example [not found] ` <87bkvb5tay.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> @ 2022-06-02 14:40 ` Felix SOEDJEDE [not found] ` <56920de7-922c-4491-86ee-c981beb37b78n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Felix SOEDJEDE @ 2022-06-02 14:40 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 3094 bytes --] Hi Albert, > If you use `function Writer(doc, opts)`, then the variables are available via `opts.variables`. I will see if I can use it > Do you mean an example of a classic custom writers? Pandoc has an example built-in, it's available via > pandoc --print-default-data-file=sample.lua In the output of this command, I have "function Doc(body, metadata, variables) ..." but I've not found how to use it. My real need is that I want to be able to access variables in my lua filters. > Out of curiosity, what output format are planning to generate? Nothing extra. It's just markdown but with some formatting on header, images, etc. The markdown is used to keep documents contents in a readable while also keeping the styles which are relevant. The markdown can then be converted to pdf (via Lualatex), epub, and maybe any other format in the future. Thanks for your replies. I will take a step back and come back to it after few days. Le jeudi 2 juin 2022 à 11:05:50 UTC+2, Albert Krewinkel a écrit : > Hi Felix, > > Felix SOEDJEDE <soef...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > 1/ Writer > > Using --to=sample.lua works when --standalone is not present and . > > Otherwise I have this error: Could not find data file > > templates/default.sample.lua > > Ah, right. With `--standalone` pandoc is looking for a template that > matches the writer name. There isn't one of course. Just omit it. > > > Using --writer=sample.lua does not work. > > Error: "Unknown option --writer." > > Whoops, should have been `--write`. I'm cutting down on coffee, I guess > it shows. 😬 > > > 2/ Accessing variables in lua filter > > I would like to have access to "variables" in lua filter. > > If you use `function Writer(doc, opts)`, then the variables are > available via `opts.variables`. > > > I prefer not to use "function Writer" for now if possible. > > Do you have any tips or working examples for that one? > > Do you mean an example of a classic custom writers? Pandoc has an > example built-in, it's available via > > pandoc --print-default-data-file=sample.lua > > Classic writers are generally a bit easier (IMHO). I'd recommend new- > style writers if you either base the new writer on one that's already > included in pandoc, or if you want to make use of the `pandoc.layout` > module to get nicer looking output. Other than those cases, classic > writers are frequently the better choice. > > Out of curiosity, what output format are planning to generate? > > Cheers, > Albert > > -- > 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/56920de7-922c-4491-86ee-c981beb37b78n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 4071 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <56920de7-922c-4491-86ee-c981beb37b78n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Pandoc 2.18 - Custom writer working example [not found] ` <56920de7-922c-4491-86ee-c981beb37b78n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2022-06-02 16:40 ` Albert Krewinkel [not found] ` <87tu933tb0.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Albert Krewinkel @ 2022-06-02 16:40 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw; +Cc: Felix SOEDJEDE Felix SOEDJEDE <soefelix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > My real need is that I want to be able to access variables in my lua > filters. In that case there might be a simpler solution: The global PANDOC_WRITER_OPTIONS became available in pandoc 2.17. With that you can access variables in writers by indexing `PANDOC_WRITER_OPTIONS.variables`. To give a short example: if you call pandoc with pandoc --lua-filter=var-test.lua --variable foo=hello <<< '' where `var-test.lua` contains print(PANDOC_WRITER_OPTIONS.variables.foo) then you'll get `hello` printed to the terminal. HTH, Albert -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <87tu933tb0.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>]
* Re: Pandoc 2.18 - Custom writer working example [not found] ` <87tu933tb0.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> @ 2022-06-03 7:31 ` Felix SOEDJEDE 0 siblings, 0 replies; 7+ messages in thread From: Felix SOEDJEDE @ 2022-06-03 7:31 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1383 bytes --] Well that was easier than I thought. I did not try that. My bad 🤦🏽♂️. It's all good now Have a nice day Le jeudi 2 juin 2022 à 18:48:43 UTC+2, Albert Krewinkel a écrit : > > Felix SOEDJEDE <soef...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > My real need is that I want to be able to access variables in my lua > > filters. > > In that case there might be a simpler solution: The global > PANDOC_WRITER_OPTIONS became available in pandoc 2.17. With that you can > access variables in writers by indexing > `PANDOC_WRITER_OPTIONS.variables`. > > To give a short example: if you call pandoc with > > pandoc --lua-filter=var-test.lua --variable foo=hello <<< '' > > where `var-test.lua` contains > > print(PANDOC_WRITER_OPTIONS.variables.foo) > > then you'll get `hello` printed to the terminal. > > HTH, > Albert > > > -- > 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/35a61b60-d763-4d60-a545-cd5329f65883n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 2078 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-06-03 7:31 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-06-01 23:01 Pandoc 2.18 - Custom writer working example Felix SOEDJEDE [not found] ` <8528d41a-d6dd-4ca7-b38a-13955a9d1eabn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2022-06-02 5:27 ` Albert Krewinkel [not found] ` <87fskn6345.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 2022-06-02 8:10 ` Felix SOEDJEDE [not found] ` <cde6d369-8813-41ed-a1ea-253901014b46n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2022-06-02 8:43 ` Albert Krewinkel [not found] ` <87bkvb5tay.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 2022-06-02 14:40 ` Felix SOEDJEDE [not found] ` <56920de7-922c-4491-86ee-c981beb37b78n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2022-06-02 16:40 ` Albert Krewinkel [not found] ` <87tu933tb0.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 2022-06-03 7:31 ` Felix SOEDJEDE
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).