* How to indent a block when exporting to reStructuredText @ 2020-11-29 21:54 Denis Bitouzé [not found] ` <875z5n7rsg.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-11-29 21:54 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Hi, (Disclaimer: I'm a pandoc beginner.) I have to convert DokuWiki files containing some unusual (meaning from plugins) tags that are exported verbatim to reStructuredText. For instance, one of these tags is: ┌──── │ <note> │ Foo │ │ Bar │ </note> └──── and I'd like to export it to reStructuredText as: ┌──── │ .. note:: │ Foo │ │ Bar └──── that is, the tag's content has to be indented with 2 consecutive spaces. I guess this can be done with a lua filter but I must admit I have no idea how to: - identify such a tag (its beginning and its end), - express the content has to be indented with 2 spaces. Any help would be welcome. Thanks. -- Denis -- 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/875z5n7rsg.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <875z5n7rsg.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <875z5n7rsg.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-11-30 0:37 ` John MacFarlane [not found] ` <m2o8jfof2r.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: John MacFarlane @ 2020-11-30 0:37 UTC (permalink / raw) To: Denis Bitouzé, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> writes: > I guess this can be done with a lua filter but I must admit I have no > idea how to: > > - identify such a tag (its beginning and its end), > - express the content has to be indented with 2 spaces. This second part is easy. Pandoc will convert ``` Div ("",["note"],[]) [...blocks...] ``` to a `.. note::` directive in rst. So you just need to get the blocks between the note tags and put them in a Div with class "note"; you don't need to worry about rendering raw rst. As for the first part: Use `pandoc -t native` to tell you how pandoc is parsing the dokuwiki: ``` % pandoc -f dokuwiki -t native <note> a b </note> ^D [Para [Str "<note>"] ,Para [Str "a"] ,Para [Str "b"] ,Para [Str "</note>"]] ``` So, if the note directives are all going to occur at the outer level (not nested in a list item or such), then you just need to iterate through the blocks till you find this starting Para, and collect blocks til you find the ending one. Hope that's clear, but feel free to ask follow ups. -- 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/m2o8jfof2r.fsf%40MacBook-Pro.hsd1.ca.comcast.net. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <m2o8jfof2r.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <m2o8jfof2r.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> @ 2020-11-30 8:38 ` Denis Bitouzé [not found] ` <87eekbjl2a.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-11-30 8:38 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Le 29/11/20 à 16h37, John MacFarlane a écrit : > Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> writes: > >> I guess this can be done with a lua filter but I must admit I have no >> idea how to: >> >> - identify such a tag (its beginning and its end), > >> - express the content has to be indented with 2 spaces. > > This second part is easy. Pandoc will convert > > ``` > Div ("",["note"],[]) [...blocks...] > ``` > > to a `.. note::` directive in rst. So you just need to get > the blocks between the note tags and put them in a Div with > class "note"; you don't need to worry about rendering raw rst. I'm not sure to understand but "you don't need to worry" is a good news! :) > As for the first part: > > Use `pandoc -t native` to tell you how pandoc is parsing the > dokuwiki: > > ``` > % pandoc -f dokuwiki -t native I wasn't aware: nice! > <note> > > a > > b > > </note> > ^D > [Para [Str "<note>"] > ,Para [Str "a"] > ,Para [Str "b"] > ,Para [Str "</note>"]] > ``` > > So, if the note directives are all going to occur at the > outer level (not nested in a list item or such), then > you just need to iterate through the blocks till you find > this starting Para, and collect blocks til you find the > ending one. Hope that's clear, but feel free to ask > follow ups. I'm really sorry: even if I understand the principle, I've absolutely no idea how to implement it (and all the examples I read either Pandoc Lua Filters examples or elsewhere didn't help me). A little help would be welcome! Thanks! -- Denis -- 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/87eekbjl2a.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <87eekbjl2a.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <87eekbjl2a.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-11-30 19:47 ` Denis Bitouzé [not found] ` <877dq2iq4d.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-11-30 19:47 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Le 30/11/20 à 09h38, Denis Bitouzé a écrit : > Le 29/11/20 à 16h37, John MacFarlane a écrit : > >> Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> writes: >> >>> I guess this can be done with a lua filter but I must admit I have no >>> idea how to: >>> >>> - identify such a tag (its beginning and its end), >> >>> - express the content has to be indented with 2 spaces. >> >> This second part is easy. Pandoc will convert >> >> ``` >> Div ("",["note"],[]) [...blocks...] >> ``` >> >> to a `.. note::` directive in rst. So you just need to get >> the blocks between the note tags and put them in a Div with >> class "note"; you don't need to worry about rendering raw rst. > > I'm not sure to understand but "you don't need to worry" is a good > news! :) > >> As for the first part: >> >> Use `pandoc -t native` to tell you how pandoc is parsing the >> dokuwiki: >> >> ``` >> % pandoc -f dokuwiki -t native > > I wasn't aware: nice! > >> <note> >> >> a >> >> b >> >> </note> >> ^D >> [Para [Str "<note>"] >> ,Para [Str "a"] >> ,Para [Str "b"] >> ,Para [Str "</note>"]] >> ``` >> >> So, if the note directives are all going to occur at the >> outer level (not nested in a list item or such), then >> you just need to iterate through the blocks till you find >> this starting Para, and collect blocks til you find the >> ending one. Hope that's clear, but feel free to ask >> follow ups. > > I'm really sorry: even if I understand the principle, I've absolutely no > idea how to implement it (and all the examples I read either Pandoc Lua > Filters examples or elsewhere didn't help me). A little help would be > welcome! I'm sorry to send again this message but I'm afraid it will get lost in the flow of this mailing list :) Would somebody kindly give me a starting point? I carefully read the pandoc filters docs and had a look at many examples out there but I've absolutely no idea how to: - find the starting Para, - collect blocks til I find the ending Para, - put these collected blocks (when I'll succeed to collect them) in a Div with class "note". That is how I'm lost :$ Thanks again! -- Denis -- 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/877dq2iq4d.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <877dq2iq4d.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <877dq2iq4d.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-12-01 18:55 ` John MacFarlane [not found] ` <m2czztxsnf.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: John MacFarlane @ 2020-12-01 18:55 UTC (permalink / raw) To: Denis Bitouzé, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> writes: > Would somebody kindly give me a starting point? I carefully read the > pandoc filters docs and had a look at many examples out there but I've > absolutely no idea how to: > > - find the starting Para, > - collect blocks til I find the ending Para, > - put these collected blocks (when I'll succeed to collect them) in > a Div with class "note". Something like this (untested and surely buggy, you'll have to debug and fix): function isNoteStart(block) return block.t == 'Para' and block.c == ??? <- fill in end function isNoteEnd(block) return block.t == 'Para' and block.c == ??? <- fill in end function Pandoc(el) local inNote = false local contents = {} local note = {} for _,block in el.blocks: if isNoteEnd(block) then inNote = false contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) elseif isNoteStart(block) then inNote = true note = {} elseif inNote then note:insert(block) else contents:insert(block) end el.blocks = contents return Pandoc(el) end -- 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/m2czztxsnf.fsf%40MacBook-Pro.hsd1.ca.comcast.net. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <m2czztxsnf.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <m2czztxsnf.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> @ 2020-12-02 10:28 ` Denis Bitouzé [not found] ` <871rg8fqo3.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-12-02 10:28 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Le 01/12/20 à 10h55, John MacFarlane a écrit : > Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> writes: > >> Would somebody kindly give me a starting point? I carefully read the >> pandoc filters docs and had a look at many examples out there but I've >> absolutely no idea how to: >> >> - find the starting Para, >> - collect blocks til I find the ending Para, >> - put these collected blocks (when I'll succeed to collect them) in >> a Div with class "note". > > Something like this (untested and surely buggy, you'll have to debug > and fix): Many thanks! > function isNoteStart(block) > return block.t == 'Para' and block.c == ??? <- fill in > end > > function isNoteEnd(block) > return block.t == 'Para' and block.c == ??? <- fill in > end > > function Pandoc(el) > > local inNote = false > local contents = {} > local note = {} > for _,block in el.blocks: > if isNoteEnd(block) then > inNote = false > contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) > elseif isNoteStart(block) then > inNote = true > note = {} > elseif inNote then > note:insert(block) > else > contents:insert(block) > end > el.blocks = contents > return Pandoc(el) > > end Indeed, it's buggy and, unfortunately, I'm unable to debug it (impossible to get `moddebug` working on my Linux box: `luasocket` issues). AFAICT, there are two points I suppose I succeeded to debug: 1. `for _,block in el.blocks:` should be `for _,block in el.blocks do` 2. there was a missing `end` at the end of the script. Also, I filled in the `block.c=???` with (not sure about this): - `block.c == 'Str "<note>"'` for `isNoteStart` - `block.c == 'Str "</note>"'` for `isNoteEnd` So now, I have: - as `test.lua`: --8<---------------cut here---------------start------------->8--- function isNoteStart(block) return block.t == 'Para' and block.c == 'Str "<note>"' end function isNoteEnd(block) return block.t == 'Para' and block.c == 'Str "</note>"' end function Pandoc(el) local inNote = false local contents = {} local note = {} for _,block in pairs(el.blocks) do if isNoteEnd(block) then inNote = false contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) elseif isNoteStart(block) then inNote = true note = {} elseif inNote then note:insert(block) else contents:insert(block) end el.blocks = contents return Pandoc(el) end end --8<---------------cut here---------------end--------------->8--- - as `test.txt` --8<---------------cut here---------------start------------->8--- <note> Foo Bar </note> --8<---------------cut here---------------end--------------->8--- but, when I run: --8<---------------cut here---------------start------------->8--- pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test.lua --8<---------------cut here---------------end--------------->8--- I get the error message: ┌──── │ Error running filter test.lua: │ test.lua:24: attempt to call a nil value (method 'insert') │ stack traceback: │ test.lua:24: in function 'Pandoc' └──── Any help would be very welcome. Thanks! -- Denis -- 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/871rg8fqo3.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <871rg8fqo3.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <871rg8fqo3.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-12-02 15:16 ` EBkysko [not found] ` <0d1533ca-8cf8-4a50-8318-a770eaaf2d31n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-02 15:16 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2054 bytes --] A few comments, if I may: - for your present error message, it's because note and contents are just 'plain' Lua tables, so you should use Lua's `table.insert` to insert items in them; if you want to use the notation `contents:insert` and `note:insert`, you must initialize them as `List`: `contents = pandoc.List()`, `note = pandoc.List()`. See module-pandoc.list <https://pandoc.org/lua-filters.html#module-pandoc.list> - use `ipairs` rather than `pairs` to be sure you get the list of blocks in the right order. See Lua documentation <https://www.lua.org/manual/5.3/manual.html#6.1>. - for the block checks, the content of `Para` is a list of `Inlines` (see `Para` <https://pandoc.org/lua-filters.html#type-para>), so `block.c` is a table, not a string, and the comparison must be done with the first `Inline`, or rather what it contains. - in your test example, `<note>` is immediately followed by `Foo`; notice how jm's example was a bit different, with a blank line between the two. Check the native output of your example and see it is not a simple `Para` with only one `Inline`. If in your documents there is no blank line after the `<note>` (and before the `</note>`), you'll have to handle those situations a bit more carefully. - return the constructor `pandoc.Pandoc` in the end; it takes two arguments, the `blocks` and the `meta`; if the `meta` is not given, it assumes it gets the `blocks` only. See Pandoc constructor <https://pandoc.org/lua-filters.html#pandoc>. - move you `el.blocks = contents` and `return pandoc.Pandoc...` out of the `for` loop. I left details open for you to study and complete. -- 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/0d1533ca-8cf8-4a50-8318-a770eaaf2d31n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 2475 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <0d1533ca-8cf8-4a50-8318-a770eaaf2d31n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <0d1533ca-8cf8-4a50-8318-a770eaaf2d31n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-02 16:23 ` EBkysko 2020-12-02 16:47 ` Denis Bitouzé 1 sibling, 0 replies; 32+ messages in thread From: EBkysko @ 2020-12-02 16:23 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 573 bytes --] a detail/correction: for the block check for `</note>`, comparison would be for the last `Inline` (which is same as first only if `Para` has only one `Inline`). -- 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/060f6435-b931-4361-969e-82708b81036cn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 888 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: How to indent a block when exporting to reStructuredText [not found] ` <0d1533ca-8cf8-4a50-8318-a770eaaf2d31n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-02 16:23 ` EBkysko @ 2020-12-02 16:47 ` Denis Bitouzé [not found] ` <87360oduiq.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 1 sibling, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-12-02 16:47 UTC (permalink / raw) To: EBkysko; +Cc: pandoc-discuss Le 02/12/20 à 07h16, EBkysko a écrit : > A few comments, if I may: Of course, many thanks for your advices! > - for your present error message, it's because note and contents are just > 'plain' Lua tables, so you should use Lua's `table.insert` to insert items > in them; if you want to use the notation `contents:insert` and > `note:insert`, you must initialize them as `List`: `contents = > pandoc.List()`, `note = pandoc.List()`. See module-pandoc.list > <https://pandoc.org/lua-filters.html#module-pandoc.list> Seems to fail (see at the end). > - use `ipairs` rather than `pairs` to be sure you get the list of blocks in > the right order. See Lua documentation > <https://www.lua.org/manual/5.3/manual.html#6.1>. OK. > - for the block checks, the content of `Para` is a list of `Inlines` (see > `Para` <https://pandoc.org/lua-filters.html#type-para>), so `block.c` is a > table, not a string, and the comparison must be done with the first > `Inline`, or rather what it contains. If I understand well, it should then be: ┌──── │ block.c[1] == 'Str "<note>"' └──── and ┌──── │ block.c[1] == 'Str "</note>"' └──── > - in your test example, `<note>` is immediately followed by `Foo`; notice > how jm's example was a bit different, with a blank line between the two. > Check the native output of your example and see it is not a simple `Para` > with only one `Inline`. If in your documents there is no blank line after > the `<note>` (and before the `</note>`), Both cases could occur. > you'll have to handle those situations a bit more carefully. Unfortunately, I don't see what to do (though I noticed no blank line gives `SoftBreak` in the native output gives). > - return the constructor `pandoc.Pandoc` in the end; it takes two > arguments, the `blocks` and the `meta`; if the `meta` is not given, it > assumes it gets the `blocks` only. See Pandoc constructor > <https://pandoc.org/lua-filters.html#pandoc>. Not sure to understand :$ > - move you `el.blocks = contents` and `return pandoc.Pandoc...` out of the > `for` loop. OK, done. > I left details open for you to study and complete. Thanks :) > for the block check for `</note>`, comparison would be for the last > `Inline` (which is same as first only if `Para` has only one > `Inline`). I guess it is the same since `</note>` is always alone on a line. -------------------------------------------------- Here is my home work ;) If I understood well, the following filter should take into account your advices: --8<---------------cut here---------------start------------->8--- contents = pandoc.List() note = pandoc.List() function isNoteStart(block) return block.t == 'Para' and block.c[1] == 'Str "<note>"' end function isNoteEnd(block) return block.t == 'Para' and block.c[1] == 'Str "</note>"' end function Pandoc(el) local inNote = false local contents = {} local note = {} for _,block in ipairs(el.blocks) do if isNoteEnd(block) then inNote = false contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) elseif isNoteStart(block) then inNote = true note = {} elseif inNote then note:insert(block) else contents:insert(block) end end el.blocks = contents return pandoc.Pandoc(el) end --8<---------------cut here---------------end--------------->8--- But, unfortunately, it is not perfect since: --8<---------------cut here---------------start------------->8--- pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test.lua --8<---------------cut here---------------end--------------->8--- still returns the same error message: ┌──── │ Error running filter test.lua: │ test.lua:27: attempt to call a nil value (method 'insert') │ stack traceback: │ test.lua:27: in function 'Pandoc' └──── Many thanks again! -- Denis -- 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/87360oduiq.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <87360oduiq.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <87360oduiq.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-12-02 18:15 ` John MacFarlane [not found] ` <m2mtywoz0f.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2020-12-02 19:15 ` EBkysko 1 sibling, 1 reply; 32+ messages in thread From: John MacFarlane @ 2020-12-02 18:15 UTC (permalink / raw) To: Denis Bitouzé, EBkysko; +Cc: pandoc-discuss Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> writes: > If I understand well, it should then be: > > ┌──── > │ block.c[1] == 'Str "<note>"' > └──── > > and > > ┌──── > │ block.c[1] == 'Str "</note>"' > └──── Certainly neither. This would work if block.[1] were a string, but it's not. What you want is probably block.c[1].t == 'Str' and block.c[1].text == "</note>" . -- 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/m2mtywoz0f.fsf%40MacBook-Pro.hsd1.ca.comcast.net. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <m2mtywoz0f.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <m2mtywoz0f.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> @ 2020-12-03 9:16 ` Denis Bitouzé 0 siblings, 0 replies; 32+ messages in thread From: Denis Bitouzé @ 2020-12-03 9:16 UTC (permalink / raw) To: pandoc-discuss Le 02/12/20 à 10h15, John MacFarlane a écrit : > Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> writes: > > >> If I understand well, it should then be: >> >> ┌──── >> │ block.c[1] == 'Str "<note>"' >> └──── >> >> and >> >> ┌──── >> │ block.c[1] == 'Str "</note>"' >> └──── > > Certainly neither. This would work if block.[1] were a string, > but it's not. What you want is probably > > block.c[1].t == 'Str' and block.c[1].text == "</note>" Ah, OK, I understand a little better: thanks! -- Denis -- 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/87o8jbckqi.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: How to indent a block when exporting to reStructuredText [not found] ` <87360oduiq.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-02 18:15 ` John MacFarlane @ 2020-12-02 19:15 ` EBkysko [not found] ` <c210b412-3d47-45d5-a7e7-c55b1086d587n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 1 sibling, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-02 19:15 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2336 bytes --] > still returns the same error message because you left the `= {}` later in the code. for now, perhaps it might be better for you to use Lua's usual `table.insert(note,...)` notation etc. rather than using `List` and `:insert` notation... one step at a time... > If I understand well, it should then be... A good beginning. Actually, `block.c[1]` will be the first `Inline`, which is a `pandoc` element... It's not literally a string, it is an element of type `Str`... see the nuance? See jm's answer. As for `</note>`, as I said in my correction, it would be the last item, i.e. `block.c[#block.c]`, which is more adequate if `Para` has more than one `Inline` in its list. > Unfortunately, I don't see what to do If you look at the code, it discards the `block` when '<note>' is found for example. So you'd lose all that paragraph. For a more complex situation, like when the native output gives `Para [Str "<note>", SoftBreak, Str "Foo"]`, you need to discard '<note>' and 'SoftBreak' from the list, but keep 'Foo'. In general, you would *remove* the first item from the table `block.c`; after this, you can check if the *new* first item is really 'SoftBreak', and *remove* it also if true. You would then be left with a table containing only the rest of the para items, i.e. the `Para` without the '<note>' (and possibly without the 'SoftBreak'). This modified `Para` block should then be inserted in the new `note` table. Do similarly in the end for '</note>', but removing the last item(s) of the `Para` list of `Inline`s. I'll let you translate this into code! > Not sure to understand (about pandoc constructor) In the end, you want to create a new pandoc document with the new modified content, and for this you use `pandoc.Pandoc` constructor/creator. You will have filled the `content` table with a list of pandoc `Block` elements, which is what `pandoc.Pandoc` takes as first argument. -- 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/c210b412-3d47-45d5-a7e7-c55b1086d587n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 2802 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <c210b412-3d47-45d5-a7e7-c55b1086d587n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <c210b412-3d47-45d5-a7e7-c55b1086d587n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-03 10:11 ` Denis Bitouzé [not found] ` <87k0tzci6s.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-12-03 10:11 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Le 02/12/20 à 11h15, EBkysko a écrit : >> still returns the same error message > > because you left the `= {}` later in the code. > for now, perhaps it might be better for you to use Lua's usual > `table.insert(note,...)` notation etc. rather than using `List` and > `:insert` notation... one step at a time... OK. I still locally initialize `note` and `contents` with `pandoc.List()`. >> If I understand well, it should then be... > > A good beginning. Actually, `block.c[1]` will be the first `Inline`, which > is a `pandoc` element... It's not literally a string, it is an element of > type `Str`... see the nuance? > See jm's answer. Seen, and useful :) > As for `</note>`, as I said in my correction, it would be the last item, > i.e. `block.c[#block.c]`, which is more adequate if `Para` has more than > one `Inline` in its list. OK, done. >> Unfortunately, I don't see what to do > > If you look at the code, it discards the `block` when '<note>' is found for > example. Because of the line `note = {}` (that I replaced by `note = pandoc.List()`) > So you'd lose all that paragraph. Indeed, the resulting `test.rst` is empty, even with the line `note = pandoc.List()` is commented :$ > For a more complex situation, like when the native output gives `Para [Str > "<note>", SoftBreak, Str "Foo"]`, you need to discard '<note>' and > 'SoftBreak' from the list, but keep 'Foo'. OK. > In general, you would *remove* the first item from the table `block.c`; > after this, you can check if the *new* first item is really 'SoftBreak', > and *remove* it also if true. OK, I tried to generalize this in case there are other `SoftBreak`. > You would then be left with a table containing only the rest of the para > items, i.e. the `Para` without the '<note>' (and possibly without the > 'SoftBreak'). > This modified `Para` block should then be inserted in the new `note` table. > Do similarly in the end for '</note>', but removing the last item(s) of the > `Para` list of `Inline`s. > > I'll let you translate this into code! Here is my attempt to do that but, unfortunately, it still gives an empty resulting `test.rst` file: --8<---------------cut here---------------start------------->8--- function isNoteStart(block) return block.t == 'Para' and block.c[1].t == 'Str' and block.c[1].text == "<note>" end function isNoteEnd(block) return block.t == 'Para' and block.c[#block.c].t == 'Str' and block.c[#block.c].text == "</note>" end function Pandoc(el) local inNote = false local contents = pandoc.List() local note = pandoc.List() for _,block in ipairs(el.blocks) do if isNoteEnd(block) then table.remove(block.c, #block.c) inNote = false -- contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"note"}))) elseif isNoteStart(block) then inNote = true -- note = pandoc.List() table.remove(block.c, 1) for i=1,#block.c-1 do if block.c[i].t == 'SoftBreak' then table.remove(block.c, 1) end end elseif inNote then -- note:insert(block) table.insert(note,block) else -- contents:insert(block) table.insert(contents,block) end end el.blocks = contents return pandoc.Pandoc(el) end --8<---------------cut here---------------end--------------->8--- >> Not sure to understand (about pandoc constructor) > > In the end, you want to create a new pandoc document with the new modified > content, and for this you use `pandoc.Pandoc` constructor/creator. > You will have filled the `content` table with a list of pandoc `Block` > elements, which is what `pandoc.Pandoc` takes as first argument. I understand better now :) Many thanks again! -- Denis -- 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/87k0tzci6s.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <87k0tzci6s.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: How to indent a block when exporting to reStructuredText [not found] ` <87k0tzci6s.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-12-03 15:49 ` EBkysko [not found] ` <db1f8570-4afc-45ee-ac1f-0ae4435cf833n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-03 15:49 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1659 bytes --] Almost there! - most importantly, after removing the 'note' tags from the block, you forget to put the modified block in the `note` table, since it contains what's left of the paragraphs once the tag is removed; - also important, in `elseif isNoteStart` chunk, you should really uncomment the creation of a new `note` table, this is where the collection will begin for the current note; - in the loop to remove the SoftBreak's, I can guess you wanted to remove any SoftBreak at the start, but the loop really isn't doing that; I'll let you rethink about it. In fact, for now let's forget about the SoftBreak's and concentrate on obtaining a working `Div`; the SoftBreak's won't do any arm; - finally, as I said the pandoc.Pandoc constructor takes the new list of blocks as first (or only) argument, but you put back only the 'el', which is a table containing el.blocks and el.meta. So you either return `pandoc.Pandoc(contents)`, or `pandoc.Pandoc(contents, el.meta)` (if you put `el.blocks=contents`, you can use `el.blocks` rather than `contents`) - minor comment: `table.remove(block.c, #block.c)` works, but there's a simpler way to write it, I'll let you think about it. I think with these you should have a working code. -- 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/db1f8570-4afc-45ee-ac1f-0ae4435cf833n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 2021 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <db1f8570-4afc-45ee-ac1f-0ae4435cf833n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <db1f8570-4afc-45ee-ac1f-0ae4435cf833n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-03 17:34 ` Denis Bitouzé [not found] ` <874kl2dca6.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-12-03 17:34 UTC (permalink / raw) To: EBkysko; +Cc: pandoc-discuss Le 03/12/20 à 07h49, EBkysko a écrit : > Almost there! Finally! :) > - most importantly, after removing the 'note' tags from the block, you > forget to put the modified block in the `note` table, since it contains > what's left of the paragraphs once the tag is removed; Done. > - also important, in `elseif isNoteStart` chunk, you should really > uncomment the creation of a new `note` table, this is where the collection > will begin for the current note; Done. > - in the loop to remove the SoftBreak's, I can guess you wanted to remove > any SoftBreak at the start, but the loop really isn't doing that; I guess it should have been: --8<---------------cut here---------------start------------->8--- if block.c[i].t == 'SoftBreak' then table.remove(block.c[i], 1) --8<---------------cut here---------------end--------------->8--- instead of --8<---------------cut here---------------start------------->8--- if block.c[i].t == 'SoftBreak' then table.remove(block.c, 1) --8<---------------cut here---------------end--------------->8--- > I'll let you rethink about it. You're a true hard but fair teacher! ;) > In fact, for now let's forget about the SoftBreak's and concentrate on > obtaining a working `Div`; the SoftBreak's won't do any arm; OK. > - finally, as I said the pandoc.Pandoc constructor takes the new list of > blocks as first (or only) argument, but you put back only the 'el', which > is a table containing el.blocks and el.meta. So you either return > `pandoc.Pandoc(contents)`, or `pandoc.Pandoc(contents, el.meta)` (if you > put `el.blocks=contents`, you can use `el.blocks` rather than `contents`) OK. > - minor comment: `table.remove(block.c, #block.c)` works, but there's a > simpler way to write it, I'll let you think about it. You're a true hard but fair teacher! ;) I hoped Lua worked as Python and that: ┌──── │ table.remove(block.c, -1) └──── would work, but that's not the case. So, sorry, I don't see, even after a look at: ┌──── │ https://www.lua.org/manual/5.3/manual.html#6.6 └──── > I think with these you should have a working code. Almost! :) With the following `test.lua` file: --8<---------------cut here---------------start------------->8--- function isNoteStart(block) return block.t == 'Para' and block.c[1].t == 'Str' and block.c[1].text == "<note>" end function isNoteEnd(block) return block.t == 'Para' and block.c[#block.c].t == 'Str' and block.c[#block.c].text == "</note>" end function Pandoc(el) local inNote = false local contents = pandoc.List() local note = pandoc.List() for _,block in ipairs(el.blocks) do if isNoteEnd(block) then table.remove(block.c, #block.c) inNote = false -- contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"note"}))) elseif isNoteStart(block) then inNote = true note = pandoc.List() table.remove(block.c, 1) table.insert(note,block) -- for i=1,#block.c-1 do -- if block.c[i].t == 'SoftBreak' then -- table.remove(block.c[i], 1) -- end -- end elseif inNote then -- note:insert(block) table.insert(note,block) else -- contents:insert(block) table.insert(contents,block) end end return pandoc.Pandoc(contents, el.meta) end --8<---------------cut here---------------end--------------->8--- the following `test.txt` file: --8<---------------cut here---------------start------------->8--- <note> Foo bar baz 1 Foo bar baz 2 Foo bar baz 3 <code latex> Foo bar baz 4 Foo bar baz 5 </code> </note> <note> Foo bar baz 6 Foo bar baz 7 Foo bar baz 8 Foo bar baz 9 Foo bar baz 10 </note> --8<---------------cut here---------------end--------------->8--- and the command: --8<---------------cut here---------------start------------->8--- pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test.lua --8<---------------cut here---------------end--------------->8--- the resulting `test.rst` file is missing the last two lines of the second note: --8<---------------cut here---------------start------------->8--- .. note:: Foo bar baz 1 Foo bar baz 2 Foo bar baz 3 .. code:: latex Foo bar baz 4 Foo bar baz 5 .. note:: Foo bar baz 6 Foo bar baz 7 Foo bar baz 8 --8<---------------cut here---------------end--------------->8--- I first thought the culprit was: --8<---------------cut here---------------start------------->8--- table.remove(block.c, #block.c) --8<---------------cut here---------------end--------------->8--- but AFAICS, it hasn't any effect. Thanks again! -- Denis -- 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/874kl2dca6.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <874kl2dca6.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <874kl2dca6.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-12-03 20:17 ` BPJ [not found] ` <CADAJKhANzMvwhURnVUh49xZzRQFKUnpyCyeZtp+nQ7Nc82ZmVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-03 20:20 ` EBkysko 1 sibling, 1 reply; 32+ messages in thread From: BPJ @ 2020-12-03 20:17 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 7232 bytes --] If I may show a correct way to check what kind of element you got: ``````lua local function is_first_str (el, wanted) if 'Para' == el.tag then if #el.content > 0 then if 'Str' == el.content[1].tag then if wanted == el.content[1].text then return true end end end end return false end `````` armed with this you can do something like this: ``````lua function Blocks (old) local new = {} local i = 1 while i <= #old do if is_first_str(old[i], '<note>') then note = {} i = i+1 while not is_first_str(old[i], '</note>') do note[#note+1] = old[i] i = i + 1 end new[#new+1] = pandoc. Div(note, {class = 'note'}) else new[#new+1] = old[i] i = i + 1 end end return new end `````` Put these two functions in a file and you have a filter which should do what you want. HTH, /bpj -- Better --help|less than helpless Den tors 3 dec. 2020 18:35Denis Bitouzé <denis.bitouze@univ-littoral.fr> skrev: > Le 03/12/20 à 07h49, EBkysko a écrit : > > > Almost there! > > Finally! :) > > > - most importantly, after removing the 'note' tags from the block, you > > forget to put the modified block in the `note` table, since it contains > > what's left of the paragraphs once the tag is removed; > > Done. > > > - also important, in `elseif isNoteStart` chunk, you should really > > uncomment the creation of a new `note` table, this is where the > collection > > will begin for the current note; > > Done. > > > - in the loop to remove the SoftBreak's, I can guess you wanted to > remove > > any SoftBreak at the start, but the loop really isn't doing that; > > I guess it should have been: > > --8<---------------cut here---------------start------------->8--- > if block.c[i].t == 'SoftBreak' then > table.remove(block.c[i], 1) > --8<---------------cut here---------------end--------------->8--- > > instead of > > --8<---------------cut here---------------start------------->8--- > if block.c[i].t == 'SoftBreak' then > table.remove(block.c, 1) > --8<---------------cut here---------------end--------------->8--- > > > I'll let you rethink about it. > > You're a true hard but fair teacher! ;) > > > In fact, for now let's forget about the SoftBreak's and concentrate on > > obtaining a working `Div`; the SoftBreak's won't do any arm; > > OK. > > > - finally, as I said the pandoc.Pandoc constructor takes the new list of > > blocks as first (or only) argument, but you put back only the 'el', > which > > is a table containing el.blocks and el.meta. So you either return > > `pandoc.Pandoc(contents)`, or `pandoc.Pandoc(contents, el.meta)` (if > you > > put `el.blocks=contents`, you can use `el.blocks` rather than `contents`) > > OK. > > > - minor comment: `table.remove(block.c, #block.c)` works, but there's a > > simpler way to write it, I'll let you think about it. > > You're a true hard but fair teacher! ;) > > I hoped Lua worked as Python and that: > > ┌──── > │ table.remove(block.c, -1) > └──── > > would work, but that's not the case. So, sorry, I don't see, even after > a look at: > > ┌──── > │ https://www.lua.org/manual/5.3/manual.html#6.6 > └──── > > > I think with these you should have a working code. > > Almost! :) > > With the following `test.lua` file: > > --8<---------------cut here---------------start------------->8--- > function isNoteStart(block) > return block.t == 'Para' and block.c[1].t == 'Str' and block.c[1].text > == "<note>" > end > > function isNoteEnd(block) > return block.t == 'Para' and block.c[#block.c].t == 'Str' and > block.c[#block.c].text == "</note>" > end > > function Pandoc(el) > > local inNote = false > local contents = pandoc.List() > local note = pandoc.List() > for _,block in ipairs(el.blocks) do > if isNoteEnd(block) then > table.remove(block.c, #block.c) > inNote = false > -- contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) > table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"note"}))) > elseif isNoteStart(block) then > inNote = true > note = pandoc.List() > table.remove(block.c, 1) > table.insert(note,block) > -- for i=1,#block.c-1 do > -- if block.c[i].t == 'SoftBreak' then > -- table.remove(block.c[i], 1) > -- end > -- end > elseif inNote then > -- note:insert(block) > table.insert(note,block) > else > -- contents:insert(block) > table.insert(contents,block) > end > end > return pandoc.Pandoc(contents, el.meta) > end > --8<---------------cut here---------------end--------------->8--- > > the following `test.txt` file: > > --8<---------------cut here---------------start------------->8--- > <note> > Foo bar baz 1 > Foo bar baz 2 > > Foo bar baz 3 > > <code latex> > Foo bar baz 4 > Foo bar baz 5 > </code> > </note> > > <note> > Foo bar baz 6 > Foo bar baz 7 > > Foo bar baz 8 > > Foo bar baz 9 > Foo bar baz 10 > </note> > --8<---------------cut here---------------end--------------->8--- > > and the command: > > --8<---------------cut here---------------start------------->8--- > pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test.lua > --8<---------------cut here---------------end--------------->8--- > > the resulting `test.rst` file is missing the last two lines of the > second note: > > --8<---------------cut here---------------start------------->8--- > .. note:: > > Foo bar baz 1 Foo bar baz 2 > > Foo bar baz 3 > > .. code:: latex > > Foo bar baz 4 > Foo bar baz 5 > > .. note:: > > Foo bar baz 6 Foo bar baz 7 > > Foo bar baz 8 > --8<---------------cut here---------------end--------------->8--- > > I first thought the culprit was: > > --8<---------------cut here---------------start------------->8--- > table.remove(block.c, #block.c) > --8<---------------cut here---------------end--------------->8--- > > but AFAICS, it hasn't any effect. > > Thanks again! > -- > Denis > > -- > 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/874kl2dca6.fsf%40example.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/CADAJKhANzMvwhURnVUh49xZzRQFKUnpyCyeZtp%2BnQ7Nc82ZmVQ%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 10267 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <CADAJKhANzMvwhURnVUh49xZzRQFKUnpyCyeZtp+nQ7Nc82ZmVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <CADAJKhANzMvwhURnVUh49xZzRQFKUnpyCyeZtp+nQ7Nc82ZmVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2020-12-03 21:03 ` EBkysko [not found] ` <7b398756-0b85-490b-b05e-8fd4fcaaecd5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-03 21:06 ` BPJ 1 sibling, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-03 21:03 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1035 bytes --] @BP Using `Blocks` would indeed be a good way for nested notes, or notes inside other blocks, a more general solution. A few notes : - After the inner `while` is done, the index i still caries its value to the outer `while`, and can produce an extra unwanted `</note>` paragraph. Should increase `i` again before the `else`. - This will miss an example like: ``` <note> Foo Bar </note> ``` where there's no blank line(s) after/before the tags; you must remove the tags and insert what's left in the `note` table. - Because of the above, you should rather have an `is_last_str` function for the inner `while`. -- 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/7b398756-0b85-490b-b05e-8fd4fcaaecd5n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1590 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <7b398756-0b85-490b-b05e-8fd4fcaaecd5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <7b398756-0b85-490b-b05e-8fd4fcaaecd5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-03 22:00 ` EBkysko [not found] ` <6221eae9-b70a-4f53-b512-7655c2ac6858n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-04 8:43 ` [SOCIAL]Re: " Denis Bitouzé 1 sibling, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-03 22:00 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 657 bytes --] Correcting myself: no, *not* for nested notes. On Thursday, December 3, 2020 at 4:03:09 PM UTC-5 EBkysko wrote: > @BP > > Using `Blocks` would indeed be a good way for nested notes, or notes > inside other blocks, a more general solution. > > -- 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/6221eae9-b70a-4f53-b512-7655c2ac6858n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1203 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <6221eae9-b70a-4f53-b512-7655c2ac6858n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <6221eae9-b70a-4f53-b512-7655c2ac6858n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-04 9:28 ` BPJ [not found] ` <CADAJKhDptqz5OCCDNxXL6p6qDBk0kKkpr-y+8+ikZmspxC0ULA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: BPJ @ 2020-12-04 9:28 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 3042 bytes --] It works for nested notes if you have the loop function call itself when it sees `<note>`, passing the next index number and an inside-note state flag as (extra) second and third arguments, and returning the list of collected blocks and the next index number when it sees `</note>`. The below (untested) code should be able to handle nested notes to any depth. Depending on whether `<note>` and `</note>` are always the only thing in a Para and/or Str you may want to do `table.remove(el.content[i], pos)` or `el.content[i][pos].text:gsub('%<%/?note%>',"")`, remove anchors on the patterns in the `is_string_match` calls and push the matching Para onto `new`. ``````lua local function is_str_match (el, pat, pos) if 'Para' == el.tag then if #el.content > 0 then if 'Str' == el.content[1].tag then pos = pos or #el.content if el.content[pos].text:match(pat) then return true end end end end return false end local function collect_notes (old, i, inside_note) local new = {} local i = i or 1 while i < #old do if is_str_match(old[i], '^%<%/note%>$') then assert inside_note, "Saw unbalanced end-of-note" return new, i+1 elseif is_str_match(old[i], '^%<note%>$', 1) then i = i+1 local note note, i = collect_notes(old, i+1, true) if #note > 0 then new[#new+1] = pandoc. Div(note, {class = 'note'}) end else new[#new+1] = old[i] i = i + 1 end end assert not(inside_note), "Saw unbalanced start-of-note" return new end function Blocks (old) local new = collect_notes(old, 1, false) return new end `````` -- Better --help|less than helpless Den tors 3 dec. 2020 23:00EBkysko <ebkysko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev: > Correcting myself: no, *not* for nested notes. > > On Thursday, December 3, 2020 at 4:03:09 PM UTC-5 EBkysko wrote: > >> @BP >> >> Using `Blocks` would indeed be a good way for nested notes, or notes >> inside other blocks, a more general solution. >> >> -- > 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/6221eae9-b70a-4f53-b512-7655c2ac6858n%40googlegroups.com > <https://groups.google.com/d/msgid/pandoc-discuss/6221eae9-b70a-4f53-b512-7655c2ac6858n%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/CADAJKhDptqz5OCCDNxXL6p6qDBk0kKkpr-y%2B8%2BikZmspxC0ULA%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 5508 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <CADAJKhDptqz5OCCDNxXL6p6qDBk0kKkpr-y+8+ikZmspxC0ULA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <CADAJKhDptqz5OCCDNxXL6p6qDBk0kKkpr-y+8+ikZmspxC0ULA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2020-12-04 9:37 ` BPJ [not found] ` <CADAJKhAHahcvktOyqyY+EB87DJSqo3aaVT7eeBtpDvCcfka5Vg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-04 14:50 ` EBkysko 1 sibling, 1 reply; 32+ messages in thread From: BPJ @ 2020-12-04 9:37 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 3420 bytes --] Oops! Remove the `i = i+1` just after the `elseif`, since `i` is incremented in the recursive call just after! -- Better --help|less than helpless Den fre 4 dec. 2020 10:28BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev: > It works for nested notes if you have the loop function call itself when > it sees > `<note>`, passing the next index number and an inside-note state flag as > (extra) > second and third arguments, and returning the list of collected blocks and > the > next index number when it sees `</note>`. > The below (untested) code should be able to handle nested notes to any > depth. > Depending on whether `<note>` and `</note>` are always the only thing in a > Para and/or Str you may want to do `table.remove(el.content[i], pos)` or > `el.content[i][pos].text:gsub('%<%/?note%>',"")`, remove anchors on > the patterns in the `is_string_match` calls and push the matching > Para onto `new`. > > ``````lua > local function is_str_match (el, pat, pos) > if 'Para' == el.tag then > if #el.content > 0 then > if 'Str' == el.content[1].tag then > pos = pos or #el.content > if el.content[pos].text:match(pat) then > return true > end > end > end > end > return false > end > > local function collect_notes (old, i, inside_note) > local new = {} > local i = i or 1 > while i < #old do > if is_str_match(old[i], '^%<%/note%>$') then > assert inside_note, "Saw unbalanced end-of-note" > return new, i+1 > elseif is_str_match(old[i], '^%<note%>$', 1) then > i = i+1 > local note > note, i = collect_notes(old, i+1, true) > if #note > 0 then > new[#new+1] = pandoc. Div(note, {class = 'note'}) > end > else > new[#new+1] = old[i] > i = i + 1 > end > end > assert not(inside_note), "Saw unbalanced start-of-note" > return new > end > > function Blocks (old) > local new = collect_notes(old, 1, false) > return new > end > `````` > > -- > Better --help|less than helpless > > Den tors 3 dec. 2020 23:00EBkysko <ebkysko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev: > >> Correcting myself: no, *not* for nested notes. >> >> On Thursday, December 3, 2020 at 4:03:09 PM UTC-5 EBkysko wrote: >> >>> @BP >>> >>> Using `Blocks` would indeed be a good way for nested notes, or notes >>> inside other blocks, a more general solution. >>> >>> -- >> 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/6221eae9-b70a-4f53-b512-7655c2ac6858n%40googlegroups.com >> <https://groups.google.com/d/msgid/pandoc-discuss/6221eae9-b70a-4f53-b512-7655c2ac6858n%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/CADAJKhAHahcvktOyqyY%2BEB87DJSqo3aaVT7eeBtpDvCcfka5Vg%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 6202 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <CADAJKhAHahcvktOyqyY+EB87DJSqo3aaVT7eeBtpDvCcfka5Vg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <CADAJKhAHahcvktOyqyY+EB87DJSqo3aaVT7eeBtpDvCcfka5Vg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2020-12-04 20:51 ` Denis Bitouzé [not found] ` <878sadxpkk.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-12-04 20:51 UTC (permalink / raw) To: pandoc-discuss Le 04/12/20 à 10h37, BPJ a écrit : > Oops! Remove the `i = i+1` just after the `elseif`, since `i` is > incremented in the recursive call just after! Many thanks for your help! I have taken into account the corrections given by @EBkysko (otherwise I had incomprehensible compile errors), but: --8<---------------cut here---------------start------------->8--- pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test.lua --8<---------------cut here---------------end--------------->8--- returns: ┌──── │ Error running filter test.lua: │ test.lua:20: syntax error near 'inside_note └──── and the culprit is: ┌──── │ assert inside_note, "Saw unbalanced end-of-note" └──── I tested with: ┌──── │ assert(inside_note, "Saw unbalanced end-of-note") └──── no compile error now :) but, with the following input file `test.txt`: --8<---------------cut here---------------start------------->8--- <note> Foo bar baz 1 Foo bar baz 2 Foo bar baz 3 <code latex> Foo bar baz 4 Foo bar baz 5 </code> </note> <note> Foo bar baz 6 Foo bar baz 7 Foo bar baz 8 Foo bar baz 9 Foo bar baz 10 </note> --8<---------------cut here---------------end--------------->8--- the resulting `test.rst` is missing some lines (the first two of the first note, and the last two of the last note): --8<---------------cut here---------------start------------->8--- .. note:: Foo bar baz 3 .. code:: latex Foo bar baz 4 Foo bar baz 5 .. note:: Foo bar baz 8 --8<---------------cut here---------------end--------------->8--- For the moment, I have to look in detail your code in order to extend it to the new cases I didn't consider first (as already told to @EBkysko): - the filter didn't work when there weren't blank lines between `<note>` and`</note>` since, in such a case, these strings were both in the same `Para`, - in my real documents, there were other "notes": - `<note tip>` - `<note warning>` - `<note important>`. Many thanks again! -- Denis -- 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/878sadxpkk.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <878sadxpkk.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <878sadxpkk.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-12-05 22:48 ` BPJ 0 siblings, 0 replies; 32+ messages in thread From: BPJ @ 2020-12-05 22:48 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 3430 bytes --] It turned out to be harder than I thought but I'm working on it. I may not have time tomorrow but I'll probably fix it by Monday. -- Better --help|less than helpless Den fre 4 dec. 2020 21:52Denis Bitouzé <denis.bitouze-PToOLB6qFnLddoiwg0DPyg@public.gmane.org> skrev: > Le 04/12/20 à 10h37, BPJ a écrit : > > > Oops! Remove the `i = i+1` just after the `elseif`, since `i` is > > incremented in the recursive call just after! > > Many thanks for your help! > > I have taken into account the corrections given by @EBkysko (otherwise > I had incomprehensible compile errors), but: > > --8<---------------cut here---------------start------------->8--- > pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test.lua > --8<---------------cut here---------------end--------------->8--- > > returns: > > ┌──── > │ Error running filter test.lua: > │ test.lua:20: syntax error near 'inside_note > └──── > > and the culprit is: > > ┌──── > │ assert inside_note, "Saw unbalanced end-of-note" > └──── > > I tested with: > > ┌──── > │ assert(inside_note, "Saw unbalanced end-of-note") > └──── > > no compile error now :) but, with the following input file `test.txt`: > > --8<---------------cut here---------------start------------->8--- > <note> > Foo bar baz 1 > Foo bar baz 2 > > Foo bar baz 3 > > <code latex> > Foo bar baz 4 > Foo bar baz 5 > </code> > </note> > > <note> > Foo bar baz 6 > Foo bar baz 7 > > Foo bar baz 8 > > Foo bar baz 9 > Foo bar baz 10 > </note> > --8<---------------cut here---------------end--------------->8--- > > the resulting `test.rst` is missing some lines (the first two of the > first note, and the last two of the last note): > > --8<---------------cut here---------------start------------->8--- > .. note:: > > Foo bar baz 3 > > .. code:: latex > > Foo bar baz 4 > Foo bar baz 5 > > .. note:: > > Foo bar baz 8 > --8<---------------cut here---------------end--------------->8--- > > For the moment, I have to look in detail your code in order to extend it > to the new cases I didn't consider first (as already told to @EBkysko): > - the filter didn't work when there weren't blank lines between `<note>` > and`</note>` since, in such a case, these strings were both in the same > `Para`, > - in my real documents, there were other "notes": > - `<note tip>` > - `<note warning>` > - `<note important>`. > > Many thanks again! > -- > Denis > > -- > 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/878sadxpkk.fsf%40example.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/CADAJKhCGc5Xd%3DeqchzoJ8ydj%3DvDjumXktN17KiAVWrTppuKCoQ%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 4668 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <CADAJKhDptqz5OCCDNxXL6p6qDBk0kKkpr-y+8+ikZmspxC0ULA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-04 9:37 ` BPJ @ 2020-12-04 14:50 ` EBkysko 1 sibling, 0 replies; 32+ messages in thread From: EBkysko @ 2020-12-04 14:50 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 836 bytes --] @BP: works with a few corrections: - in is_str_match: `el.content[1]` should be `el.content[pos]` - in is_str_match: `pos = pos or #el.content` should be moved before the `if 'Str'...` - in collect_notes: `while i < #old` should be `while i <= #old` ('</note>` could be in last para) - assert args should be within parenthesis On Friday, December 4, 2020 at 4:29:03 AM UTC-5 BP wrote: > It works for nested notes.... > -- 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/ac0cbc5c-8107-456e-8994-dc89619078d2n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1515 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <7b398756-0b85-490b-b05e-8fd4fcaaecd5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-03 22:00 ` EBkysko @ 2020-12-04 8:43 ` Denis Bitouzé 1 sibling, 0 replies; 32+ messages in thread From: Denis Bitouzé @ 2020-12-04 8:43 UTC (permalink / raw) To: EBkysko; +Cc: pandoc-discuss Le 03/12/20 à 13h03, EBkysko a écrit : > Using `Blocks` would indeed be a good way for nested notes, or notes inside > other blocks, a more general solution. Isn't `Blocks` an arbitrary name of a function? -- Denis -- 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/87im9iarlq.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <CADAJKhANzMvwhURnVUh49xZzRQFKUnpyCyeZtp+nQ7Nc82ZmVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-03 21:03 ` EBkysko @ 2020-12-03 21:06 ` BPJ [not found] ` <CADAJKhAM88Cm+-G9oVGM0eJUpPpUUpCkPVQrabNSqKXJOY7r-w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 1 sibling, 1 reply; 32+ messages in thread From: BPJ @ 2020-12-03 21:06 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 8457 bytes --] Sorry I forgot to localize some variables. Corrected below. ``````lua local function is_first_str (el, wanted) if 'Para' == el.tag then if #el.content > 0 then if 'Str' == el.content[1].tag then if wanted == el.content[1].text then return true end end end end return false end function Blocks (old) local new = {} local i = 1 while i < #old do if is_first_str(old[i], '<note>') then local note = {} i = i+1 while not is_first_str(old[i], '</note>') do note[#note+1] = old[i] i = i + 1 end new[#new+1] = pandoc. Div(note, {class = 'note'}) else new[#new+1] = old[i] i = i + 1 end end return new end `````` -- Better --help|less than helpless Den tors 3 dec. 2020 21:17BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev: > If I may show a correct way to check what kind of element you got: > > ``````lua > local function is_first_str (el, wanted) > if 'Para' == el.tag then > if #el.content > 0 then > if 'Str' == el.content[1].tag then > if wanted == el.content[1].text then > return true > end > end > end > end > return false > end > `````` > > armed with this you can do something like this: > > ``````lua > function Blocks (old) > local new = {} > local i = 1 > while i <= #old do > if is_first_str(old[i], '<note>') then > note = {} > i = i+1 > while not is_first_str(old[i], '</note>') do > note[#note+1] = old[i] > i = i + 1 > end > new[#new+1] = pandoc. Div(note, {class = 'note'}) > else > new[#new+1] = old[i] > i = i + 1 > end > end > return new > end > `````` > > Put these two functions in a file and you have a filter which should do > what you > want. > > HTH, > > /bpj > > > -- > Better --help|less than helpless > > Den tors 3 dec. 2020 18:35Denis Bitouzé <denis.bitouze@univ-littoral.fr> > skrev: > >> Le 03/12/20 à 07h49, EBkysko a écrit : >> >> > Almost there! >> >> Finally! :) >> >> > - most importantly, after removing the 'note' tags from the block, you >> > forget to put the modified block in the `note` table, since it contains >> > what's left of the paragraphs once the tag is removed; >> >> Done. >> >> > - also important, in `elseif isNoteStart` chunk, you should really >> > uncomment the creation of a new `note` table, this is where the >> collection >> > will begin for the current note; >> >> Done. >> >> > - in the loop to remove the SoftBreak's, I can guess you wanted to >> remove >> > any SoftBreak at the start, but the loop really isn't doing that; >> >> I guess it should have been: >> >> --8<---------------cut here---------------start------------->8--- >> if block.c[i].t == 'SoftBreak' then >> table.remove(block.c[i], 1) >> --8<---------------cut here---------------end--------------->8--- >> >> instead of >> >> --8<---------------cut here---------------start------------->8--- >> if block.c[i].t == 'SoftBreak' then >> table.remove(block.c, 1) >> --8<---------------cut here---------------end--------------->8--- >> >> > I'll let you rethink about it. >> >> You're a true hard but fair teacher! ;) >> >> > In fact, for now let's forget about the SoftBreak's and concentrate >> on >> > obtaining a working `Div`; the SoftBreak's won't do any arm; >> >> OK. >> >> > - finally, as I said the pandoc.Pandoc constructor takes the new list >> of >> > blocks as first (or only) argument, but you put back only the 'el', >> which >> > is a table containing el.blocks and el.meta. So you either return >> > `pandoc.Pandoc(contents)`, or `pandoc.Pandoc(contents, el.meta)` (if >> you >> > put `el.blocks=contents`, you can use `el.blocks` rather than >> `contents`) >> >> OK. >> >> > - minor comment: `table.remove(block.c, #block.c)` works, but there's a >> > simpler way to write it, I'll let you think about it. >> >> You're a true hard but fair teacher! ;) >> >> I hoped Lua worked as Python and that: >> >> ┌──── >> │ table.remove(block.c, -1) >> └──── >> >> would work, but that's not the case. So, sorry, I don't see, even after >> a look at: >> >> ┌──── >> │ https://www.lua.org/manual/5.3/manual.html#6.6 >> └──── >> >> > I think with these you should have a working code. >> >> Almost! :) >> >> With the following `test.lua` file: >> >> --8<---------------cut here---------------start------------->8--- >> function isNoteStart(block) >> return block.t == 'Para' and block.c[1].t == 'Str' and block.c[1].text >> == "<note>" >> end >> >> function isNoteEnd(block) >> return block.t == 'Para' and block.c[#block.c].t == 'Str' and >> block.c[#block.c].text == "</note>" >> end >> >> function Pandoc(el) >> >> local inNote = false >> local contents = pandoc.List() >> local note = pandoc.List() >> for _,block in ipairs(el.blocks) do >> if isNoteEnd(block) then >> table.remove(block.c, #block.c) >> inNote = false >> -- contents:insert(pandoc.Div(note, pandoc.Attr("",{"note"}))) >> table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"note"}))) >> elseif isNoteStart(block) then >> inNote = true >> note = pandoc.List() >> table.remove(block.c, 1) >> table.insert(note,block) >> -- for i=1,#block.c-1 do >> -- if block.c[i].t == 'SoftBreak' then >> -- table.remove(block.c[i], 1) >> -- end >> -- end >> elseif inNote then >> -- note:insert(block) >> table.insert(note,block) >> else >> -- contents:insert(block) >> table.insert(contents,block) >> end >> end >> return pandoc.Pandoc(contents, el.meta) >> end >> --8<---------------cut here---------------end--------------->8--- >> >> the following `test.txt` file: >> >> --8<---------------cut here---------------start------------->8--- >> <note> >> Foo bar baz 1 >> Foo bar baz 2 >> >> Foo bar baz 3 >> >> <code latex> >> Foo bar baz 4 >> Foo bar baz 5 >> </code> >> </note> >> >> <note> >> Foo bar baz 6 >> Foo bar baz 7 >> >> Foo bar baz 8 >> >> Foo bar baz 9 >> Foo bar baz 10 >> </note> >> --8<---------------cut here---------------end--------------->8--- >> >> and the command: >> >> --8<---------------cut here---------------start------------->8--- >> pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test.lua >> --8<---------------cut here---------------end--------------->8--- >> >> the resulting `test.rst` file is missing the last two lines of the >> second note: >> >> --8<---------------cut here---------------start------------->8--- >> .. note:: >> >> Foo bar baz 1 Foo bar baz 2 >> >> Foo bar baz 3 >> >> .. code:: latex >> >> Foo bar baz 4 >> Foo bar baz 5 >> >> .. note:: >> >> Foo bar baz 6 Foo bar baz 7 >> >> Foo bar baz 8 >> --8<---------------cut here---------------end--------------->8--- >> >> I first thought the culprit was: >> >> --8<---------------cut here---------------start------------->8--- >> table.remove(block.c, #block.c) >> --8<---------------cut here---------------end--------------->8--- >> >> but AFAICS, it hasn't any effect. >> >> Thanks again! >> -- >> Denis >> >> -- >> 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/874kl2dca6.fsf%40example.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/CADAJKhAM88Cm%2B-G9oVGM0eJUpPpUUpCkPVQrabNSqKXJOY7r-w%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 12452 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <CADAJKhAM88Cm+-G9oVGM0eJUpPpUUpCkPVQrabNSqKXJOY7r-w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <CADAJKhAM88Cm+-G9oVGM0eJUpPpUUpCkPVQrabNSqKXJOY7r-w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2020-12-04 8:42 ` Denis Bitouzé 0 siblings, 0 replies; 32+ messages in thread From: Denis Bitouzé @ 2020-12-04 8:42 UTC (permalink / raw) To: BPJ; +Cc: pandoc-discuss Le 03/12/20 à 22h06, BPJ a écrit : > Sorry I forgot to localize some variables. Corrected below. Ma,y thanks for your help! > ``````lua > local function is_first_str (el, wanted) > if 'Para' == el.tag then > if #el.content > 0 then > if 'Str' == el.content[1].tag then > if wanted == el.content[1].text then > return true > end > end > end > end > return false > end > > function Blocks (old) > local new = {} > local i = 1 > while i < #old do > if is_first_str(old[i], '<note>') then > local note = {} > i = i+1 > while not is_first_str(old[i], '</note>') do > note[#note+1] = old[i] > i = i + 1 > end > new[#new+1] = pandoc. Div(note, {class = 'note'}) I guess the space in `pandoc. Div` has to be removed, or is it harmless? > else > new[#new+1] = old[i] > i = i + 1 > end > end > return new > end > `````` Running: --8<---------------cut here---------------start------------->8--- pandoc -f dokuwiki test.txt -o test.rst --lua-filter=test-bis.lua --8<---------------cut here---------------end--------------->8--- with `test-bis.lua` containing your code and the following `test.txt` file: --8<---------------cut here---------------start------------->8--- <note> Foo bar baz 1 Foo bar baz 2 Foo bar baz 3 <code latex> Foo bar baz 4 Foo bar baz 5 </code> </note> <note> Foo bar baz 6 Foo bar baz 7 Foo bar baz 8 Foo bar baz 9 Foo bar baz 10 </note> --8<---------------cut here---------------end--------------->8--- gave me the error: ┌──── │ Error running filter test-bis.lua: │ test-bis.lua:2: attempt to index a nil value (local 'el') │ stack traceback: │ test-bis.lua:2: in upvalue 'is_first_str' │ test-bis.lua:21: in function 'Blocks └──── So I tried to circumvent by replacing: ┌──── │ if 'Para' == el.tag then └──── by: ┌──── │ if not el and 'Para' == el.tag then └──── No more error but not the expected result: ┌──── │ <note> Foo bar baz 1 Foo bar baz 2 │ │ Foo bar baz 3 │ │ .. code:: latex │ │ Foo bar baz 4 │ Foo bar baz 5 │ │ </note> │ │ <note> Foo bar baz 6 Foo bar baz 7 │ │ Foo bar baz 8 └──── Thanks again! -- Denis -- 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/87mtyuarnw.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <874kl2dca6.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-03 20:17 ` BPJ @ 2020-12-03 20:20 ` EBkysko [not found] ` <0a5a4d99-e862-43c4-8664-4b1b60f36e00n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 1 sibling, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-03 20:20 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1502 bytes --] > the resulting `test.rst` file is missing the last two lines of the second note you forgot to insert the modified `block` into the `note` table in the `if isNoteEnd(block)` chunk. Insert it, and you're done! > I guess it should have been... (about removing SoftBreaks) well, no... take an example, a pen and paper, and do (symbolically) what your loop is doing... Or if you're used to python, imagine you have a list `["a", "a", "a", ... , "a", "b", "c", "d", "e"]' with an indefinite number of "a"'s in the front, and write a program to remove all the "a"'s. The logic you found could help you for `block.c`. > I hoped Lua worked as Python... (about table.remove) Unfortunately, no, although the '-1' index trick works in Lua for some string functions. Check `table.remove` in the Lua documentation for tables <https://www.lua.org/manual/5.3/manual.html#6.6>. If you're more comfortable with Python, have you thought about python filters <https://pandoc.org/filters.html#but-i-dont-want-to-learn-haskell>? You could use panflute <http://scorreia.com/software/panflute/>. -- 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/0a5a4d99-e862-43c4-8664-4b1b60f36e00n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 2062 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <0a5a4d99-e862-43c4-8664-4b1b60f36e00n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <0a5a4d99-e862-43c4-8664-4b1b60f36e00n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-03 22:44 ` EBkysko [not found] ` <ef8524a3-956b-4e42-adeb-761197c42d08n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-04 8:25 ` Denis Bitouzé 1 sibling, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-03 22:44 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 893 bytes --] ... and anyways, there will be only one `SoftBreak` *at most* after/before the tag. So forget about the python exercise I proposed :) Question about the format: could you have this format for a note: ``` <note>a simple note</note> ``` In that case there's no soft brake to eliminate. So check if there's one, eliminate if so. On Thursday, December 3, 2020 at 3:20:28 PM UTC-5 EBkysko wrote: > > I guess it should have been... (about removing SoftBreaks) > > well, no... > > -- 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/ef8524a3-956b-4e42-adeb-761197c42d08n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1560 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <ef8524a3-956b-4e42-adeb-761197c42d08n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <ef8524a3-956b-4e42-adeb-761197c42d08n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-04 8:46 ` Denis Bitouzé [not found] ` <87eek6arh1.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: Denis Bitouzé @ 2020-12-04 8:46 UTC (permalink / raw) To: EBkysko; +Cc: pandoc-discuss Le 03/12/20 à 14h44, EBkysko a écrit : > ... and anyways, there will be only one `SoftBreak` *at most* after/before > the tag. So forget about the python exercise I proposed :) I didn't see any proposed exercise :) > Question about the format: could you have this format for a note: > > ``` > <note>a simple note</note> > ``` > > In that case there's no soft brake to eliminate. No: `<note>` and `</note>` are always alone on their lines. > So check if there's one, eliminate if so. Why is it so important to remove these soft breaks? -- Denis -- 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/87eek6arh1.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <87eek6arh1.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org>]
* Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <87eek6arh1.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> @ 2020-12-04 14:31 ` EBkysko [not found] ` <8c84d892-5412-4fd4-9718-70866142d19dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 32+ messages in thread From: EBkysko @ 2020-12-04 14:31 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1086 bytes --] > you told me "you need to discard [...] 'SoftBreak' from the list" that was in the *initial* example, with *that* particular list: the soft break between the tag and succeeding string (or preceding, for end tag) wasn't meant to be general, so don't remove "all". > besides, you told me "the SoftBreak's won't do any arm": I'm a bit lost it won't... but it's weird having it there; the writer probably discards it > Isn't `Blocks` an arbitrary name of a function? see Filters on element sequence <https://pandoc.org/lua-filters.html#filters-on-element-sequences> > `<note>` and `</note>` are always alone on their lines good: won't have to check another variation -- 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/8c84d892-5412-4fd4-9718-70866142d19dn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1480 bytes --] ^ permalink raw reply [flat|nested] 32+ messages in thread
[parent not found: <8c84d892-5412-4fd4-9718-70866142d19dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: [SOCIAL]Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <8c84d892-5412-4fd4-9718-70866142d19dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-12-04 20:28 ` Denis Bitouzé 0 siblings, 0 replies; 32+ messages in thread From: Denis Bitouzé @ 2020-12-04 20:28 UTC (permalink / raw) To: pandoc-discuss Le 04/12/20 à 06h31, EBkysko a écrit : >> you told me "you need to discard [...] 'SoftBreak' from the list" > > that was in the *initial* example, with *that* particular list: the soft > break between the tag and succeeding string (or preceding, for end tag) > > wasn't meant to be general, so don't remove "all". OK. >> besides, you told me "the SoftBreak's won't do any arm": I'm a bit lost > > it won't... but it's weird having it there; the writer probably > discards it Indeed, AFAICS. >> Isn't `Blocks` an arbitrary name of a function? > > see Filters on element sequence > <https://pandoc.org/lua-filters.html#filters-on-element-sequences> Thanks for the pointer. Currently, I don't see the added value compared to `Pandoc`: maybe later, when I'll more experienced :) >> `<note>` and `</note>` are always alone on their lines > > good: won't have to check another variation In fact, I encountered other troubles: - the filter didn't work when there weren't blank lines between `<note>` and`</note>` since, in such a case, these strings were both in the same `Para`, - in my real documents, there were other "notes": - `<note tip>` - `<note warning>` - `<note important>`. For the record, here is a Lua filter which seems to work (though probably not as efficient as it could be): --8<---------------cut here---------------start------------->8--- function isNoteStart(block) -- return block.t == 'Para' and block.c[1].t == 'Str' and block.c[1].text == "<note>" return block.t == 'Para' and block.c[1].t == 'Str' and string.match(block.c[1].text, "<note") end function isNoteEnd(block) return block.t == 'Para' and block.c[#block.c].t == 'Str' and block.c[#block.c].text == "</note>" end function isNoteStartEnd(block) return block.t == 'Para' and block.c[1].t == 'Str' and string.match(block.c[1].text, "<note") and block.c[#block.c].text == "</note>" end function isSpecialAdmonition (block) if block.c[3].text == "warning>" then isWarning = true table.remove(block.c, 3) elseif block.c[3].text == "tip>" then isTip = true table.remove(block.c, 3) elseif block.c[3].text == "important>" then isImportant = true table.remove(block.c, 3) elseif block.c[2].tag == 'Space' then table.remove(block.c, 3) table.remove(block.c, 2) end end function insertPandocDiv (contents,note) if isWarning then table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"warning"}))) isWarning = false elseif isTip then table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"tip"}))) isTip = false elseif isImportant then table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"important"}))) isImportant = false else table.insert(contents,pandoc.Div(note, pandoc.Attr("",{"note"}))) end end isWarning = false isTip = false isImportant = false function Pandoc(el) local inNote = false local contents = pandoc.List() local note = pandoc.List() for _,block in ipairs(el.blocks) do if isNoteStartEnd(block) then isSpecialAdmonition (block) note = pandoc.List() table.remove(block.c, 1) table.remove(block.c) table.insert(note,block) insertPandocDiv (contents,note) elseif isNoteEnd(block) then table.remove(block.c, #block.c) table.insert(note,block) inNote = false insertPandocDiv (contents,note) elseif isNoteStart(block) then inNote = true isSpecialAdmonition (block) note = pandoc.List() table.remove(block.c, 1) table.insert(note,block) -- for i=1,#block.c-1 do -- if block.c[i].t == 'SoftBreak' then -- table.remove(block.c[i], 1) -- end -- end elseif inNote then table.insert(note,block) else table.insert(contents,block) end end return pandoc.Pandoc(contents, el.meta) end --8<---------------cut here---------------end--------------->8--- Thanks everybody for the great help! -- Denis -- 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/87czzpxqmg.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [SOCIAL]Re: [SOCIAL]Re: How to indent a block when exporting to reStructuredText [not found] ` <0a5a4d99-e862-43c4-8664-4b1b60f36e00n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-03 22:44 ` EBkysko @ 2020-12-04 8:25 ` Denis Bitouzé 1 sibling, 0 replies; 32+ messages in thread From: Denis Bitouzé @ 2020-12-04 8:25 UTC (permalink / raw) To: EBkysko; +Cc: pandoc-discuss Le 03/12/20 à 12h20, EBkysko a écrit : >> the resulting `test.rst` file is missing the last two lines of the second >> note > > you forgot to insert the modified `block` into the `note` table in the `if > isNoteEnd(block)` chunk. Insert it, and you're done! Indeed! Finally... :) >> I guess it should have been... (about removing SoftBreaks) > > well, no... take an example, a pen and paper, and do (symbolically) what > your loop is doing... > Or if you're used to python, imagine you have a list `["a", "a", "a", ... , > "a", "b", "c", "d", "e"]' with an indefinite number of "a"'s in the front, > and write a program to remove all the "a"'s. The logic you found could help > you for `block.c`. In fact: - my aim wasn't to remove any `SoftBreak` /at the start/ but any in the `Para` block's list (and I didn't consider the case where multiple consecutive occurrences of it could arise), - I guess `SoftBreak` stands for line breaks and I don't understand why: - you told me "you need to discard [...] 'SoftBreak' from the list" (besides, you told me "the SoftBreak's won't do any arm": I'm a bit lost ;), - they are discarded from the output: ┌──── │ Foo bar baz 1 │ Foo bar baz 2 └──── is exported as: ┌──── │ Foo bar baz 1 Foo bar baz 2 └──── even when the code supposed to remove them is commented. >> I hoped Lua worked as Python... (about table.remove) > > Unfortunately, no, although the '-1' index trick works in Lua for some > string functions. > Check `table.remove` in the Lua documentation for tables > <https://www.lua.org/manual/5.3/manual.html#6.6>. Indeed, I didn't look carefully enough (sorry): ┌──── │ table.remove(block.c) └──── does the trick. > If you're more comfortable with Python, have you thought about python > filters <https://pandoc.org/filters.html#but-i-dont-want-to-learn-haskell>? > You could use panflute <http://scorreia.com/software/panflute/>. Despite the beginner's mistakes I made, I guess my problem is more with the logic of Pandoc parser (e.g. what is a table, what is not) than the Lua language (though I'm missing some of its syntax tricks). Many thanks again! -- Denis -- 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/87r1o6asg2.fsf%40example.com. ^ permalink raw reply [flat|nested] 32+ messages in thread
end of thread, other threads:[~2020-12-05 22:48 UTC | newest] Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-11-29 21:54 How to indent a block when exporting to reStructuredText Denis Bitouzé [not found] ` <875z5n7rsg.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-11-30 0:37 ` John MacFarlane [not found] ` <m2o8jfof2r.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2020-11-30 8:38 ` Denis Bitouzé [not found] ` <87eekbjl2a.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-11-30 19:47 ` Denis Bitouzé [not found] ` <877dq2iq4d.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-01 18:55 ` John MacFarlane [not found] ` <m2czztxsnf.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2020-12-02 10:28 ` Denis Bitouzé [not found] ` <871rg8fqo3.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-02 15:16 ` EBkysko [not found] ` <0d1533ca-8cf8-4a50-8318-a770eaaf2d31n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-02 16:23 ` EBkysko 2020-12-02 16:47 ` Denis Bitouzé [not found] ` <87360oduiq.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-02 18:15 ` John MacFarlane [not found] ` <m2mtywoz0f.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2020-12-03 9:16 ` Denis Bitouzé 2020-12-02 19:15 ` EBkysko [not found] ` <c210b412-3d47-45d5-a7e7-c55b1086d587n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-03 10:11 ` Denis Bitouzé [not found] ` <87k0tzci6s.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-03 15:49 ` EBkysko [not found] ` <db1f8570-4afc-45ee-ac1f-0ae4435cf833n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-03 17:34 ` [SOCIAL]Re: " Denis Bitouzé [not found] ` <874kl2dca6.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-03 20:17 ` BPJ [not found] ` <CADAJKhANzMvwhURnVUh49xZzRQFKUnpyCyeZtp+nQ7Nc82ZmVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-03 21:03 ` EBkysko [not found] ` <7b398756-0b85-490b-b05e-8fd4fcaaecd5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-03 22:00 ` EBkysko [not found] ` <6221eae9-b70a-4f53-b512-7655c2ac6858n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-04 9:28 ` BPJ [not found] ` <CADAJKhDptqz5OCCDNxXL6p6qDBk0kKkpr-y+8+ikZmspxC0ULA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-04 9:37 ` BPJ [not found] ` <CADAJKhAHahcvktOyqyY+EB87DJSqo3aaVT7eeBtpDvCcfka5Vg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-04 20:51 ` [SOCIAL]Re: " Denis Bitouzé [not found] ` <878sadxpkk.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-05 22:48 ` BPJ 2020-12-04 14:50 ` EBkysko 2020-12-04 8:43 ` [SOCIAL]Re: " Denis Bitouzé 2020-12-03 21:06 ` BPJ [not found] ` <CADAJKhAM88Cm+-G9oVGM0eJUpPpUUpCkPVQrabNSqKXJOY7r-w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-12-04 8:42 ` [SOCIAL]Re: " Denis Bitouzé 2020-12-03 20:20 ` EBkysko [not found] ` <0a5a4d99-e862-43c4-8664-4b1b60f36e00n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-03 22:44 ` EBkysko [not found] ` <ef8524a3-956b-4e42-adeb-761197c42d08n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-04 8:46 ` [SOCIAL]Re: " Denis Bitouzé [not found] ` <87eek6arh1.fsf-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org> 2020-12-04 14:31 ` EBkysko [not found] ` <8c84d892-5412-4fd4-9718-70866142d19dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-12-04 20:28 ` [SOCIAL]Re: " Denis Bitouzé 2020-12-04 8:25 ` Denis Bitouzé
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).