public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Use Writer in Lua Filter?
@ 2023-05-04  6:00 ThomasH
       [not found] ` <9dc956cf-74a3-4e25-b4bd-62aae6dcc3f4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: ThomasH @ 2023-05-04  6:00 UTC (permalink / raw)
  To: pandoc-discuss


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

Can I use one of the standard Writers in a Lua Filter? I would like to 
import the 'native' Writer and use it to serialize parts of the AST while 
in a filter function.

Thanks,
T.

-- 
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/9dc956cf-74a3-4e25-b4bd-62aae6dcc3f4n%40googlegroups.com.

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

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

* Re: Use Writer in Lua Filter?
       [not found] ` <9dc956cf-74a3-4e25-b4bd-62aae6dcc3f4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-05-04  6:07   ` Albert Krewinkel
       [not found]     ` <87jzxobp5d.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Albert Krewinkel @ 2023-05-04  6:07 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


ThomasH <therch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Can I use one of the standard Writers in a Lua Filter? I would like
> to import the 'native' Writer and use it to serialize parts of the
> AST while in a filter function.

The AST elements can be converted to strings with `tostring`. We
currently use the native form as string representation, so this should
suffice: `tostring(element)`. Note, however, that I plan to change this
in the future, and to provide a string representation that contains the
element's Lua fields and that is valid Lua code.

The alternative is to use `pandoc.write`, e.g.:

    print(pandoc.write(pandoc.Pandoc {element}))

-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


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

* Re: Use Writer in Lua Filter?
       [not found]     ` <87jzxobp5d.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2023-05-04  6:44       ` Albert Krewinkel
       [not found]         ` <87fs8cbnne.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Albert Krewinkel @ 2023-05-04  6:44 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> writes:

> The alternative is to use `pandoc.write`, e.g.:
>
>     print(pandoc.write(pandoc.Pandoc {element}))

The above is missing the second parameter:

    print(pandoc.write(pandoc.Pandoc {element}, 'native'))


-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


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

* Re: Use Writer in Lua Filter?
       [not found]         ` <87fs8cbnne.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2023-05-04 16:06           ` ThomasH
       [not found]             ` <4c078a54-2252-4253-b2a5-6348ecc1f916n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: ThomasH @ 2023-05-04 16:06 UTC (permalink / raw)
  To: pandoc-discuss


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

Great, that worked, thanks.

I just wished that would have been more apparent from the docs. I guessed 
something like 'tostring' might exist, and tried 'element:toString()' and 
similar without success. There are three mentionings of 'tostring' on the 
doc page for Lua filters, two in the section entitled "Global variables" 
where you would only spot them by chance. And one is in the section about 
the LogMessage type <https://pandoc.org/lua-filters.html#type-logmessage> 
where I figured LogMessage objects had a 'tostring' method, but didn't know 
how to use the LogMessage type in the first place.

Cheers,
T.
On Thursday, May 4, 2023 at 8:45:34 AM UTC+2 Albert Krewinkel wrote:

>
> Albert Krewinkel <albert...-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> writes:
>
> > The alternative is to use `pandoc.write`, e.g.:
> >
> > print(pandoc.write(pandoc.Pandoc {element}))
>
> The above is missing the second parameter:
>
> print(pandoc.write(pandoc.Pandoc {element}, 'native'))
>
>
> -- 
> 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/4c078a54-2252-4253-b2a5-6348ecc1f916n%40googlegroups.com.

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

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

* Re: Use Writer in Lua Filter?
       [not found]             ` <4c078a54-2252-4253-b2a5-6348ecc1f916n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-05-04 20:59               ` Albert Krewinkel
       [not found]                 ` <878re3bb7a.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Albert Krewinkel @ 2023-05-04 20:59 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


ThomasH <therch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I just wished that would have been more apparent from the docs.

The `tostring` function is the default Lua way to convert an object "to
a string in a human-readable format". Still, I made a mental note to add
better docs once we switch from a Haskell to a Lua representation as
`tostring` output.

The Haskell/native output will probably become available via show
methods, as in `block:show()`. This already works for Block elements,
but not for Inlines.


>> Albert Krewinkel <albert...-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> writes:
>>
>> > The alternative is to use `pandoc.write`, e.g.:
>> >
>> > print(pandoc.write(pandoc.Pandoc {element}))
>>
>> The above is missing the second parameter:
>>
>> print(pandoc.write(pandoc.Pandoc {element}, 'native'))


-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


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

* Re: Use Writer in Lua Filter?
       [not found]                 ` <878re3bb7a.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2023-05-05  8:03                   ` ThomasH
       [not found]                     ` <79a8dca6-9860-4109-b2e8-5841faa36cc0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: ThomasH @ 2023-05-05  8:03 UTC (permalink / raw)
  To: pandoc-discuss


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

Ah, ok, sorry, I've only come to Lua through Pandoc, so I'm often not aware 
of general Lua features. I will keep an eye open for the 'show' method.

T.

On Friday, May 5, 2023 at 7:26:41 AM UTC+2 Albert Krewinkel wrote:

>
> ThomasH <the...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > I just wished that would have been more apparent from the docs.
>
> The `tostring` function is the default Lua way to convert an object "to
> a string in a human-readable format". Still, I made a mental note to add
> better docs once we switch from a Haskell to a Lua representation as
> `tostring` output.
>
> The Haskell/native output will probably become available via show
> methods, as in `block:show()`. This already works for Block elements,
> but not for Inlines.
>
>
> >> Albert Krewinkel <albert...-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> writes:
> >>
> >> > The alternative is to use `pandoc.write`, e.g.:
> >> >
> >> > print(pandoc.write(pandoc.Pandoc {element}))
> >>
> >> The above is missing the second parameter:
> >>
> >> print(pandoc.write(pandoc.Pandoc {element}, 'native'))
>
>
> -- 
> 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/79a8dca6-9860-4109-b2e8-5841faa36cc0n%40googlegroups.com.

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

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

* Re: Use Writer in Lua Filter?
       [not found]                     ` <79a8dca6-9860-4109-b2e8-5841faa36cc0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-05-06  8:35                       ` BPJ
       [not found]                         ` <CADAJKhCKdyaTdjEVzAzc6+q9vDwGtbjLL_euCEP5G8GEcT9Diw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: BPJ @ 2023-05-06  8:35 UTC (permalink / raw)
  To: pandoc-discuss

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

Den fre 5 maj 2023 10:04ThomasH <therch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

> Ah, ok, sorry, I've only come to Lua through Pandoc, so I'm often not
> aware of general Lua features. I will keep an eye open for the 'show'
> method.
>
> T.
>

See

https://www.lua.org/manual/5.4/manual.html

https://learnxinyminutes.com/docs/lua/

Note that the latter seems to fail to mention that the full syntax for long
strings and comments includes balanced `=` characters between the brackets
so that you can include double brackets with or without a lower number of
`=` chars in the string, e.g.

``````lua
local foo = [===[ [==[ [=[ [[ foo ]] ]=] ]==] ]===]
``````

is a single string delimited by `[===[` and `]===]`

Also escapes like `\n` don't work in long strings.




> On Friday, May 5, 2023 at 7:26:41 AM UTC+2 Albert Krewinkel wrote:
>
>>
>> ThomasH <the...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>>
>> > I just wished that would have been more apparent from the docs.
>>
>> The `tostring` function is the default Lua way to convert an object "to
>> a string in a human-readable format". Still, I made a mental note to add
>> better docs once we switch from a Haskell to a Lua representation as
>> `tostring` output.
>>
>> The Haskell/native output will probably become available via show
>> methods, as in `block:show()`. This already works for Block elements,
>> but not for Inlines.
>>
>>
>> >> Albert Krewinkel <albert...-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> writes:
>> >>
>> >> > The alternative is to use `pandoc.write`, e.g.:
>> >> >
>> >> > print(pandoc.write(pandoc.Pandoc {element}))
>> >>
>> >> The above is missing the second parameter:
>> >>
>> >> print(pandoc.write(pandoc.Pandoc {element}, 'native'))
>>
>>
>> --
>> 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/79a8dca6-9860-4109-b2e8-5841faa36cc0n%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/79a8dca6-9860-4109-b2e8-5841faa36cc0n%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/CADAJKhCKdyaTdjEVzAzc6%2Bq9vDwGtbjLL_euCEP5G8GEcT9Diw%40mail.gmail.com.

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

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

* Re: Use Writer in Lua Filter?
       [not found]                         ` <CADAJKhCKdyaTdjEVzAzc6+q9vDwGtbjLL_euCEP5G8GEcT9Diw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2023-05-06  8:53                           ` BPJ
  2023-05-07 10:41                           ` ThomasH
  1 sibling, 0 replies; 9+ messages in thread
From: BPJ @ 2023-05-06  8:53 UTC (permalink / raw)
  To: bpj; +Cc: pandoc-discuss

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

Also assigning `nil` to a table key/index deletes that key/index. A table
value can't be `nil`:

``````lua
local t = { a = 1, b = 2, c = 3 }
for k,v in pairs(t) do
  print(k, v)
end
-- prints
-- a    1
-- b    2
-- c    3
-- but in a random order
t.b = nil
for k,v in pairs(t) do print(k,v) end
-- Doesn't print b    2 because it doesn't exist anymore!
``````

Den lör 6 maj 2023 10:35BPJ <bpj-J3H7GcXPSITLoDKTGw+V6w@public.gmane.org> skrev:

>
>
> Den fre 5 maj 2023 10:04ThomasH <therch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>
>> Ah, ok, sorry, I've only come to Lua through Pandoc, so I'm often not
>> aware of general Lua features. I will keep an eye open for the 'show'
>> method.
>>
>> T.
>>
>
> See
>
> https://www.lua.org/manual/5.4/manual.html
>
> https://learnxinyminutes.com/docs/lua/
>
> Note that the latter seems to fail to mention that the full syntax for
> long strings and comments includes balanced `=` characters between the
> brackets so that you can include double brackets with or without a lower
> number of `=` chars in the string, e.g.
>
> ``````lua
> local foo = [===[ [==[ [=[ [[ foo ]] ]=] ]==] ]===]
> ``````
>
> is a single string delimited by `[===[` and `]===]`
>
> Also escapes like `\n` don't work in long strings.
>
>
>
>
>> On Friday, May 5, 2023 at 7:26:41 AM UTC+2 Albert Krewinkel wrote:
>>
>>>
>>> ThomasH <the...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>>>
>>> > I just wished that would have been more apparent from the docs.
>>>
>>> The `tostring` function is the default Lua way to convert an object "to
>>> a string in a human-readable format". Still, I made a mental note to add
>>> better docs once we switch from a Haskell to a Lua representation as
>>> `tostring` output.
>>>
>>> The Haskell/native output will probably become available via show
>>> methods, as in `block:show()`. This already works for Block elements,
>>> but not for Inlines.
>>>
>>>
>>> >> Albert Krewinkel <albert...-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> writes:
>>> >>
>>> >> > The alternative is to use `pandoc.write`, e.g.:
>>> >> >
>>> >> > print(pandoc.write(pandoc.Pandoc {element}))
>>> >>
>>> >> The above is missing the second parameter:
>>> >>
>>> >> print(pandoc.write(pandoc.Pandoc {element}, 'native'))
>>>
>>>
>>> --
>>> 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/79a8dca6-9860-4109-b2e8-5841faa36cc0n%40googlegroups.com
>> <https://groups.google.com/d/msgid/pandoc-discuss/79a8dca6-9860-4109-b2e8-5841faa36cc0n%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/CADAJKhCiFbdbX7QdtODq3Vd3hemrObiFpi0W9fmf_hyS077T-g%40mail.gmail.com.

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

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

* Re: Use Writer in Lua Filter?
       [not found]                         ` <CADAJKhCKdyaTdjEVzAzc6+q9vDwGtbjLL_euCEP5G8GEcT9Diw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2023-05-06  8:53                           ` BPJ
@ 2023-05-07 10:41                           ` ThomasH
  1 sibling, 0 replies; 9+ messages in thread
From: ThomasH @ 2023-05-07 10:41 UTC (permalink / raw)
  To: pandoc-discuss


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



On Saturday, May 6, 2023 at 10:35:11 AM UTC+2 BPJ wrote:



Den fre 5 maj 2023 10:04ThomasH <the...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:

Ah, ok, sorry, I've only come to Lua through Pandoc, so I'm often not aware 
of general Lua features. I will keep an eye open for the 'show' method.

T.


See 

https://www.lua.org/manual/5.4/manual.html

https://learnxinyminutes.com/docs/lua/


Thanks for the pointers! Yes, I was going through the standard Lua 
documentation, but more focusing on specific questions I had rather than 
reading everything from top to bottom. But sometimes my anticipation goes 
the wrong way and I surely miss things.

T.
 

-- 
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/9dab3532-068a-4196-9065-3974997cf786n%40googlegroups.com.

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

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

end of thread, other threads:[~2023-05-07 10:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04  6:00 Use Writer in Lua Filter? ThomasH
     [not found] ` <9dc956cf-74a3-4e25-b4bd-62aae6dcc3f4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-05-04  6:07   ` Albert Krewinkel
     [not found]     ` <87jzxobp5d.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2023-05-04  6:44       ` Albert Krewinkel
     [not found]         ` <87fs8cbnne.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2023-05-04 16:06           ` ThomasH
     [not found]             ` <4c078a54-2252-4253-b2a5-6348ecc1f916n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-05-04 20:59               ` Albert Krewinkel
     [not found]                 ` <878re3bb7a.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2023-05-05  8:03                   ` ThomasH
     [not found]                     ` <79a8dca6-9860-4109-b2e8-5841faa36cc0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-05-06  8:35                       ` BPJ
     [not found]                         ` <CADAJKhCKdyaTdjEVzAzc6+q9vDwGtbjLL_euCEP5G8GEcT9Diw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-05-06  8:53                           ` BPJ
2023-05-07 10:41                           ` ThomasH

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