* how to know the BulletList context and indent properly when using custom lua write.
@ 2019-12-25 10:43 Lei Zhang
[not found] ` <e249e0e0-d71e-4476-9d1f-12f7d3f2acf5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Lei Zhang @ 2019-12-25 10:43 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1206 bytes --]
I am try to write a custom lua script to convert markdown syntax to
tiddlywiki.
I found the BulletList do not work as expected. You can get the code from
[0]
function BulletList(items)
local buffer = {}
for _, item in pairs(items) do
table.insert(buffer, "* " .. item)
end
return table.concat(buffer, "\n")
end
when render the markdown like below
* test
* test2
* test3
* test4
* test5
by using `pandoc -t md2tid.lua test.md`, i got
* test
* test2
* test3
* test4
* test5
But what i expected is
* test
** test2
** test3
* test4
* test5
The issue here is that i have no way to know what indent i should use in
the BulletList function.
any guys have idea to improve this? thanks a lot.
[0] https://github.com/jeffrey4l/pandoc-addons/blob/master/md2tid.lua#L217
--
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/e249e0e0-d71e-4476-9d1f-12f7d3f2acf5%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 4481 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to know the BulletList context and indent properly when using custom lua write.
[not found] ` <e249e0e0-d71e-4476-9d1f-12f7d3f2acf5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-12-25 12:19 ` Albert Krewinkel
[not found] ` <87v9q4r40i.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2019-12-26 20:22 ` John MacFarlane
1 sibling, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2019-12-25 12:19 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
The problem is that evaluation in the custom Lua writer happens
bottom-up, which is why the inner lists cannot know how many levels
there are above them.
That being said, there is a way to work around this, but it isn't
pretty. It works rather accidentally, due to the way function's are
called: Instead of defining the `BulletList` function on the top-level,
as one would normally do, return it via the metatable-lookup of the
global environment `_G`. This allows to alter state each time the
function is looked-up, which happens right before the items are
converted to string. This way, one can keep track of list-nesting.
E.g.:
-- table to keep track of list nesting
local bullets = {}
-- replacement for BulletList, returned via global metatable
function BulletList_ (items)
local buffer = {}
for _, item in pairs(items) do
table.insert(buffer, table.concat(bullets) .. ' ' .. item)
end
-- remove bullet inserted in metatable
table.remove(bullets)
return table.concat(buffer, '\n')
end
setmetatable(
_G,
{
__index = function (t, f)
if f == 'BulletList' then
table.insert(bullets, '*')
return BulletList_
end
error('missing function ' .. tostring(f))
end
}
)
I wouldn't normally recommend this approach, but I can't think of a
better way right now.
Cheers,
Albert
Lei Zhang writes:
> I am try to write a custom lua script to convert markdown syntax to
> tiddlywiki.
>
> I found the BulletList do not work as expected. You can get the code from
> [0]
>
> function BulletList(items)
> local buffer = {}
> for _, item in pairs(items) do
> table.insert(buffer, "* " .. item)
> end
> return table.concat(buffer, "\n")
> end
>
> when render the markdown like below
>
> * test
> * test2
> * test3
> * test4
> * test5
>
> by using `pandoc -t md2tid.lua test.md`, i got
>
> * test
>
> * test2
>
> * test3
> * test4
> * test5
>
> But what i expected is
>
> * test
> ** test2
> ** test3
> * test4
> * test5
>
> The issue here is that i have no way to know what indent i should use in
> the BulletList function.
>
> any guys have idea to improve this? thanks a lot.
>
>
> [0] https://github.com/jeffrey4l/pandoc-addons/blob/master/md2tid.lua#L217
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to know the BulletList context and indent properly when using custom lua write.
[not found] ` <87v9q4r40i.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2019-12-25 12:59 ` Lei Zhang
[not found] ` <06054cc1-6fa5-4c66-8c8e-7634c2059bd0-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Lei Zhang @ 2019-12-25 12:59 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 858 bytes --]
Thanks Albert,
Your solution works as expected. I pushed a patch to fix my issue [0].
There is another minor issue. There is always extra blank line between the
nested list. Do you have any idea on how to remove it?
```markdown
1. test0
1. test1
```
```tiddlywiki
# test0
## test1
```
What i expected
```tiddlywiki
# test0
## test1
```
[0]
https://github.com/jeffrey4l/pandoc-addons/commit/0071c33686cb1c3db62dac3698a81ad0c793b6ab
--
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/06054cc1-6fa5-4c66-8c8e-7634c2059bd0%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 1869 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to know the BulletList context and indent properly when using custom lua write.
[not found] ` <06054cc1-6fa5-4c66-8c8e-7634c2059bd0-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-12-26 9:15 ` Albert Krewinkel
[not found] ` <87tv5oqush.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2019-12-26 9:15 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Lei Zhang writes:
> There is another minor issue. There is always extra blank line between the
> nested list. Do you have any idea on how to remove it?
>
> ```markdown
> 1. test0
> 1. test1
> ```
>
>
> ```tiddlywiki
> # test0
>
> ## test1
>
> ```
>
> What i expected
>
> ```tiddlywiki
> # test0
> ## test1
> ```
One possibility is to let `Blocksep` return different results whether
one is in a list or not:
function Blocksep ()
return bullets[1] and "\n" or "\n\n"
end
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to know the BulletList context and indent properly when using custom lua write.
[not found] ` <87tv5oqush.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2019-12-26 9:24 ` Jeffrey Zhang
0 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Zhang @ 2019-12-26 9:24 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 1682 bytes --]
Cool, it works.
You are awesome , thanks a lots.
---
Regards,
Jeffrey Zhang
Blog: http://xcodest.me
On Thu, Dec 26, 2019 at 5:15 PM Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
wrote:
>
> Lei Zhang writes:
>
> > There is another minor issue. There is always extra blank line between
> the
> > nested list. Do you have any idea on how to remove it?
> >
> > ```markdown
> > 1. test0
> > 1. test1
> > ```
> >
> >
> > ```tiddlywiki
> > # test0
> >
> > ## test1
> >
> > ```
> >
> > What i expected
> >
> > ```tiddlywiki
> > # test0
> > ## test1
> > ```
>
> One possibility is to let `Blocksep` return different results whether
> one is in a list or not:
>
> function Blocksep ()
> return bullets[1] and "\n" or "\n\n"
> end
>
>
> --
> 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/87tv5oqush.fsf%40zeitkraut.de
> .
>
--
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/CAATxhGer1TUTYEkrNQiDZV%2B-CpmNrdHsmXhj18RuepXNaUds9A%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 3773 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to know the BulletList context and indent properly when using custom lua write.
[not found] ` <e249e0e0-d71e-4476-9d1f-12f7d3f2acf5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-12-25 12:19 ` Albert Krewinkel
@ 2019-12-26 20:22 ` John MacFarlane
[not found] ` <m2imm2hm6u.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2019-12-26 20:22 UTC (permalink / raw)
To: Lei Zhang, pandoc-discuss
Instead of just concat'ing a bullet with item, you could
try using match/replace to ensure that subsequent lines
of item are indented 2 spaces.
Lei Zhang <zhang.lei.fly-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> I am try to write a custom lua script to convert markdown syntax to
> tiddlywiki.
>
> I found the BulletList do not work as expected. You can get the code from
> [0]
>
> function BulletList(items)
> local buffer = {}
> for _, item in pairs(items) do
> table.insert(buffer, "* " .. item)
> end
> return table.concat(buffer, "\n")
> end
>
> when render the markdown like below
>
> * test
> * test2
> * test3
> * test4
> * test5
>
> by using `pandoc -t md2tid.lua test.md`, i got
>
> * test
>
> * test2
>
> * test3
> * test4
> * test5
>
> But what i expected is
>
> * test
> ** test2
> ** test3
> * test4
> * test5
>
> The issue here is that i have no way to know what indent i should use in
> the BulletList function.
>
> any guys have idea to improve this? thanks a lot.
>
>
> [0] https://github.com/jeffrey4l/pandoc-addons/blob/master/md2tid.lua#L217
>
> --
> 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/e249e0e0-d71e-4476-9d1f-12f7d3f2acf5%40googlegroups.com.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to know the BulletList context and indent properly when using custom lua write.
[not found] ` <m2imm2hm6u.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-12-27 1:37 ` Jeffrey Zhang
[not found] ` <CAATxhGcwEOa7NX23LK-vAPg=_rK-2gZW_Z5iQCpRNgO7KcEM-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Jeffrey Zhang @ 2019-12-27 1:37 UTC (permalink / raw)
To: John MacFarlane; +Cc: pandoc-discuss
[-- Attachment #1: Type: text/plain, Size: 2312 bytes --]
Hi John,
I am not very familiar with pandoc. Could you give a code example?
thanks a lot.
---
Regards,
Jeffrey Zhang
Blog: http://xcodest.me
On Fri, Dec 27, 2019 at 4:22 AM John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
>
> Instead of just concat'ing a bullet with item, you could
> try using match/replace to ensure that subsequent lines
> of item are indented 2 spaces.
>
> Lei Zhang <zhang.lei.fly-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > I am try to write a custom lua script to convert markdown syntax to
> > tiddlywiki.
> >
> > I found the BulletList do not work as expected. You can get the code
> from
> > [0]
> >
> > function BulletList(items)
> > local buffer = {}
> > for _, item in pairs(items) do
> > table.insert(buffer, "* " .. item)
> > end
> > return table.concat(buffer, "\n")
> > end
> >
> > when render the markdown like below
> >
> > * test
> > * test2
> > * test3
> > * test4
> > * test5
> >
> > by using `pandoc -t md2tid.lua test.md`, i got
> >
> > * test
> >
> > * test2
> >
> > * test3
> > * test4
> > * test5
> >
> > But what i expected is
> >
> > * test
> > ** test2
> > ** test3
> > * test4
> > * test5
> >
> > The issue here is that i have no way to know what indent i should use in
> > the BulletList function.
> >
> > any guys have idea to improve this? thanks a lot.
> >
> >
> > [0]
> https://github.com/jeffrey4l/pandoc-addons/blob/master/md2tid.lua#L217
> >
> > --
> > 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/e249e0e0-d71e-4476-9d1f-12f7d3f2acf5%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/CAATxhGcwEOa7NX23LK-vAPg%3D_rK-2gZW_Z5iQCpRNgO7KcEM-g%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 4975 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: how to know the BulletList context and indent properly when using custom lua write.
[not found] ` <CAATxhGcwEOa7NX23LK-vAPg=_rK-2gZW_Z5iQCpRNgO7KcEM-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2020-08-04 23:48 ` Diego Mesa
0 siblings, 0 replies; 8+ messages in thread
From: Diego Mesa @ 2020-08-04 23:48 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2618 bytes --]
Hello,
Did you ever manage to complete the TW5 writer? I am very interested in
getting TW "plugged in" to pandoc!
Thanks!
On Thursday, December 26, 2019 at 7:38:23 PM UTC-6, Jeffrey Zhang wrote:
>
> Hi John,
>
> I am not very familiar with pandoc. Could you give a code example?
> thanks a lot.
> ---
> Regards,
> Jeffrey Zhang
> Blog: http://xcodest.me
>
>
> On Fri, Dec 27, 2019 at 4:22 AM John MacFarlane <j...-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org
> <javascript:>> wrote:
>
>>
>> Instead of just concat'ing a bullet with item, you could
>> try using match/replace to ensure that subsequent lines
>> of item are indented 2 spaces.
>>
>> Lei Zhang <zhang...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> writes:
>>
>> > I am try to write a custom lua script to convert markdown syntax to
>> > tiddlywiki.
>> >
>> > I found the BulletList do not work as expected. You can get the code
>> from
>> > [0]
>> >
>> > function BulletList(items)
>> > local buffer = {}
>> > for _, item in pairs(items) do
>> > table.insert(buffer, "* " .. item)
>> > end
>> > return table.concat(buffer, "\n")
>> > end
>> >
>> > when render the markdown like below
>> >
>> > * test
>> > * test2
>> > * test3
>> > * test4
>> > * test5
>> >
>> > by using `pandoc -t md2tid.lua test.md`, i got
>> >
>> > * test
>> >
>> > * test2
>> >
>> > * test3
>> > * test4
>> > * test5
>> >
>> > But what i expected is
>> >
>> > * test
>> > ** test2
>> > ** test3
>> > * test4
>> > * test5
>> >
>> > The issue here is that i have no way to know what indent i should use
>> in
>> > the BulletList function.
>> >
>> > any guys have idea to improve this? thanks a lot.
>> >
>> >
>> > [0]
>> https://github.com/jeffrey4l/pandoc-addons/blob/master/md2tid.lua#L217
>> >
>> > --
>> > 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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>.
>> > To view this discussion on the web visit
>> https://groups.google.com/d/msgid/pandoc-discuss/e249e0e0-d71e-4476-9d1f-12f7d3f2acf5%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/7c2cd894-6789-42dd-b484-0dc1a5d5f14bo%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 6707 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-08-04 23:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-25 10:43 how to know the BulletList context and indent properly when using custom lua write Lei Zhang
[not found] ` <e249e0e0-d71e-4476-9d1f-12f7d3f2acf5-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-12-25 12:19 ` Albert Krewinkel
[not found] ` <87v9q4r40i.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2019-12-25 12:59 ` Lei Zhang
[not found] ` <06054cc1-6fa5-4c66-8c8e-7634c2059bd0-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-12-26 9:15 ` Albert Krewinkel
[not found] ` <87tv5oqush.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2019-12-26 9:24 ` Jeffrey Zhang
2019-12-26 20:22 ` John MacFarlane
[not found] ` <m2imm2hm6u.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-12-27 1:37 ` Jeffrey Zhang
[not found] ` <CAATxhGcwEOa7NX23LK-vAPg=_rK-2gZW_Z5iQCpRNgO7KcEM-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-08-04 23:48 ` Diego Mesa
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).