public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Parsing a list
@ 2023-02-16  4:50 Ken Perry
       [not found] ` <39a03df1-6228-449f-8f20-1b5b92248cecn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Ken Perry @ 2023-02-16  4:50 UTC (permalink / raw)
  To: pandoc-discuss


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


We use Pandoc as a backend for a Braille word processor. to support file 
types that we don't currently support.   We have most of the filter working 
for our file type but the lists are not working right   I can't seem to get 
the nested lists to come out right.  I am trying to get the attributes of a 
list in a LUA filter to give me the same information I can see when I 
output to JSON.  Currently I am using an ugly list like this to test with:

Broken list 

 

1. Item 1

2.  Item 2

3.  Item 3

1.  item 7

2.  Item 8

a. Item a

b. Item b

                     i.   Item i

                   ii.   Item ii

1. Item I

2. Item ii

3. Item 9

4. Item 10



When I run it in the native json I get :


,Header 3 ("broken-list",[],[]) [Str "Broken",Space,Str "list"]
,OrderedList (1,Decimal,Period)
 [[Para [Str "Item",Space,Str "1"]]
 ,[Para [Str "Item",Space,Str "2"]]
 ,[Para [Str "Item",Space,Str "3"]]]
,OrderedList (7,Decimal,Period)
 [[Para [Str "item",Space,Str "7"]]
 ,[Para [Str "Item",Space,Str "8"]
  ,OrderedList (1,LowerAlpha,DefaultDelim)
   [[Para [Str "Item",Space,Str "a"]]
   ,[Para [Str "Item",Space,Str "b"]
    ,OrderedList (1,LowerRoman,DefaultDelim)
     [[Para [Str "Item",Space,Str "i"]]
     ,[Para [Str "Item",Space,Str "ii"]
      ,OrderedList (1,Decimal,DefaultDelim)
       [[Para [Str "Item",Space,Str "I"]]
       ,[Para [Str "Item",Space,Str "ii"]]]]]]]]
 ,[Para [Str "Item",Space,Str "9"]]
 ,[Para [Str "Item",Space,Str "10"]]]]


I am trying to parse this with LUA with the function:


function OrderedList(items)
  local newItems = {}
  local listItems = ''
  local itemCtr = 1
  beginTag  = '<CONTAINER bb:type="LIST" bb:listType="NORMAL" 
bb:listLevel="0">'
   endTag    = '</CONTAINER>'
  for _, item in pairs(items) do
    if nil ~= item and string.len(item) > 0 then
      item = removeTags(item)
      -- listItems = listItems .. '<BLOCK bb:type="LIST_ITEM" 
bb:itemLevel="0">'.. itemCtr .. '. ' .. item .. '</BLOCK>'
      print ('fuck' .. itemCtr .. '. ' .. item) 
      table.insert(newItems,'<BLOCK bb:type="LIST_ITEM" 
bb:itemLevel="0">'.. itemCtr .. '. ' .. item .. '</BLOCK>')
      itemCtr = itemCtr + 1
    end
  end
  newItems.bullet = true
  return BulletList(newItems)
end

I know I can adjust the above LUA if I cna just figure out how to get the 
start value, and the style out of the native into the LUA.  Can someone 
tell me the line of code I need to ge the attributes.  I have tried things 
like:


items.attributes

items.listAttributes


I even checked the item before I output the json and saw that tthe 
attributes are on the main list.  I can't seem to get the LUA function to 
see the things like starting value and I don't know what I have to do so 
that I can parse the levels correctly.  All help is welcome.  Heck if 
someone has something that can take the above docx list and output it as a 
text list that is all I need.  I can wrap that in our tags.    I  have been 
looking for any examples of LUA filters that make multi  level broken lists 
into anything and I can not find an example.  


Thanks for any help.



 

-- 
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/39a03df1-6228-449f-8f20-1b5b92248cecn%40googlegroups.com.

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

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

* Re: Parsing a list
       [not found] ` <39a03df1-6228-449f-8f20-1b5b92248cecn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-02-16  6:38   ` Bastien DUMONT
  2023-02-18  7:41     ` kperry-rhKcP+tiLR7by3iVrkZq2A
  0 siblings, 1 reply; 3+ messages in thread
From: Bastien DUMONT @ 2023-02-16  6:38 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Doesn't items.listAttributes.start, items.listAttributes.style and items.listAttributes.delimiter yield what you are looking for?

By the way, you can replace `if nil ~= item` with `if item`: in Lua, a nil value evaluates to false and any non-nil and non-false value evaluates to true.

Le Wednesday 15 February 2023 à 08:50:11PM, Ken Perry a écrit :
> 
> We use Pandoc as a backend for a Braille word processor. to support file types
> that we don't currently support.   We have most of the filter working for our
> file type but the lists are not working right   I can't seem to get the nested
> lists to come out right.  I am trying to get the attributes of a list in a LUA
> filter to give me the same information I can see when I output to JSON. 
> Currently I am using an ugly list like this to test with:
> 
> Broken list
> 
>  
> 
> 1. Item 1
> 
> 2.  Item 2
> 
> 3.  Item 3
> 
> 1.  item 7
> 
> 2.  Item 8
> 
> a. Item a
> 
> b. Item b
> 
>                      i.   Item i
> 
>                    ii.   Item ii
> 
> 1. Item I
> 
> 2. Item ii
> 
> 3. Item 9
> 
> 4. Item 10
> 
> 
> 
> When I run it in the native json I get :
> 
> 
> ,Header 3 ("broken-list",[],[]) [Str "Broken",Space,Str "list"]
> ,OrderedList (1,Decimal,Period)
>  [[Para [Str "Item",Space,Str "1"]]
>  ,[Para [Str "Item",Space,Str "2"]]
>  ,[Para [Str "Item",Space,Str "3"]]]
> ,OrderedList (7,Decimal,Period)
>  [[Para [Str "item",Space,Str "7"]]
>  ,[Para [Str "Item",Space,Str "8"]
>   ,OrderedList (1,LowerAlpha,DefaultDelim)
>    [[Para [Str "Item",Space,Str "a"]]
>    ,[Para [Str "Item",Space,Str "b"]
>     ,OrderedList (1,LowerRoman,DefaultDelim)
>      [[Para [Str "Item",Space,Str "i"]]
>      ,[Para [Str "Item",Space,Str "ii"]
>       ,OrderedList (1,Decimal,DefaultDelim)
>        [[Para [Str "Item",Space,Str "I"]]
>        ,[Para [Str "Item",Space,Str "ii"]]]]]]]]
>  ,[Para [Str "Item",Space,Str "9"]]
>  ,[Para [Str "Item",Space,Str "10"]]]]
> 
> 
> I am trying to parse this with LUA with the function:
> 
> 
> function OrderedList(items)
>   local newItems = {}
>   local listItems = ''
>   local itemCtr = 1
>   beginTag  = '<CONTAINER bb:type="LIST" bb:listType="NORMAL" bb:listLevel="0">
> '
>    endTag    = '</CONTAINER>'
>   for _, item in pairs(items) do
>     if nil ~= item and string.len(item) > 0 then
>       item = removeTags(item)
>       -- listItems = listItems .. '<BLOCK bb:type="LIST_ITEM" bb:itemLevel="0">
> '.. itemCtr .. '. ' .. item .. '</BLOCK>'
>       print ('fuck' .. itemCtr .. '. ' .. item)
>       table.insert(newItems,'<BLOCK bb:type="LIST_ITEM" bb:itemLevel="0">'..
> itemCtr .. '. ' .. item .. '</BLOCK>')
>       itemCtr = itemCtr + 1
>     end
>   end
>   newItems.bullet = true
>   return BulletList(newItems)
> end
> 
> 
> I know I can adjust the above LUA if I cna just figure out how to get the start
> value, and the style out of the native into the LUA.  Can someone tell me the
> line of code I need to ge the attributes.  I have tried things like:
> 
> 
> items.attributes
> 
> items.listAttributes
> 
> 
> I even checked the item before I output the json and saw that tthe attributes
> are on the main list.  I can't seem to get the LUA function to see the things
> like starting value and I don't know what I have to do so that I can parse the
> levels correctly.  All help is welcome.  Heck if someone has something that can
> take the above docx list and output it as a text list that is all I need.  I
> can wrap that in our tags.    I  have been looking for any examples of LUA
> filters that make multi  level broken lists into anything and I can not find an
> example.  
> 
> 
> Thanks for any help.
> 
> 
> 
>  
> 
> 
> --
> 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/39a03df1-6228-449f-8f20-1b5b92248cecn%40googlegroups.com.
> 
> References:
> 
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/39a03df1-6228-449f-8f20-1b5b92248cecn%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/Y%2B3PTvBjmu8Y9koD%40localhost.


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

* RE: Parsing a list
  2023-02-16  6:38   ` Bastien DUMONT
@ 2023-02-18  7:41     ` kperry-rhKcP+tiLR7by3iVrkZq2A
  0 siblings, 0 replies; 3+ messages in thread
From: kperry-rhKcP+tiLR7by3iVrkZq2A @ 2023-02-18  7:41 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw



I tried posting this so if you get two that is because I did not see it in my sent mail after sending it.  Here is what I have tried before the for loop to see if there is a style or start:

If items.listAttributes ~= nil and items.listAttributes.start ~= nill then
Log ("bbx start " .. items.listAttributes.start)
End

If items.listAttributes ~= nil and items.listAttributes.style ~= nill then
Log ("bbx style " .. items.listAttributes.style )
End

Neither of those logged to my log function.  Note the log function is well tested and just opens a file to append to since I can't catch standard out in this being run by a filter in in a Java program.  I log before and after the if with a string message and they show up.  So then I saw that there was a short hand possible in the pandoc API so I tried doing:

If items.start then
Log ("bbx start " .. items.start)
End

If items.style then
Log ("bbx style " .. items.style )
End

This should have printed logs for at least the last list for start and all the rest for style and nothing was logged. If I try with out the if statements it just throws an error and currently I am not sure how to catch that error since again I am running it in a Java program that executes it.  I am going to look into getting that error message but I am assuming it will say that the style or start is nil but that doesn't exactly make since because in the JSON they are always set to something.  AmI doing something wrong in the above if statements.  I code in way to many programming languages and LUA is not one of my strong points.  I could send you the whole bbx and my test file if you think it will help you help me.

Ken



-----Original Message-----
From: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> On Behalf Of Bastien DUMONT
Sent: Thursday, February 16, 2023 1:38 AM
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Parsing a list

Doesn't items.listAttributes.start, items.listAttributes.style and items.listAttributes.delimiter yield what you are looking for?

By the way, you can replace `if nil ~= item` with `if item`: in Lua, a nil value evaluates to false and any non-nil and non-false value evaluates to true.

Le Wednesday 15 February 2023 à 08:50:11PM, Ken Perry a écrit :
> 
> We use Pandoc as a backend for a Braille word processor. to support 
> file types that we don't currently support.   We have most of the 
> filter working for our file type but the lists are not working right   
> I can't seem to get the nested lists to come out right.  I am trying 
> to get the attributes of a list in a LUA filter to give me the same information I can see when I output to JSON.
> Currently I am using an ugly list like this to test with:
> 
> Broken list
> 
>  
> 
> 1. Item 1
> 
> 2.  Item 2
> 
> 3.  Item 3
> 
> 1.  item 7
> 
> 2.  Item 8
> 
> a. Item a
> 
> b. Item b
> 
>                      i.   Item i
> 
>                    ii.   Item ii
> 
> 1. Item I
> 
> 2. Item ii
> 
> 3. Item 9
> 
> 4. Item 10
> 
> 
> 
> When I run it in the native json I get :
> 
> 
> ,Header 3 ("broken-list",[],[]) [Str "Broken",Space,Str "list"] 
> ,OrderedList (1,Decimal,Period)
>  [[Para [Str "Item",Space,Str "1"]]
>  ,[Para [Str "Item",Space,Str "2"]]
>  ,[Para [Str "Item",Space,Str "3"]]]
> ,OrderedList (7,Decimal,Period)
>  [[Para [Str "item",Space,Str "7"]]
>  ,[Para [Str "Item",Space,Str "8"]
>   ,OrderedList (1,LowerAlpha,DefaultDelim)
>    [[Para [Str "Item",Space,Str "a"]]
>    ,[Para [Str "Item",Space,Str "b"]
>     ,OrderedList (1,LowerRoman,DefaultDelim)
>      [[Para [Str "Item",Space,Str "i"]]
>      ,[Para [Str "Item",Space,Str "ii"]
>       ,OrderedList (1,Decimal,DefaultDelim)
>        [[Para [Str "Item",Space,Str "I"]]
>        ,[Para [Str "Item",Space,Str "ii"]]]]]]]]
>  ,[Para [Str "Item",Space,Str "9"]]
>  ,[Para [Str "Item",Space,Str "10"]]]]
> 
> 
> I am trying to parse this with LUA with the function:
> 
> 
> function OrderedList(items)
>   local newItems = {}
>   local listItems = ''
>   local itemCtr = 1
>   beginTag  = '<CONTAINER bb:type="LIST" bb:listType="NORMAL" 
> bb:listLevel="0"> '
>    endTag    = '</CONTAINER>'
>   for _, item in pairs(items) do
>     if nil ~= item and string.len(item) > 0 then
>       item = removeTags(item)
>       -- listItems = listItems .. '<BLOCK bb:type="LIST_ITEM" 
> bb:itemLevel="0"> '.. itemCtr .. '. ' .. item .. '</BLOCK>'
>       print ('fuck' .. itemCtr .. '. ' .. item)
>       table.insert(newItems,'<BLOCK bb:type="LIST_ITEM" bb:itemLevel="0">'..
> itemCtr .. '. ' .. item .. '</BLOCK>')
>       itemCtr = itemCtr + 1
>     end
>   end
>   newItems.bullet = true
>   return BulletList(newItems)
> end
> 
> 
> I know I can adjust the above LUA if I cna just figure out how to get 
> the start value, and the style out of the native into the LUA.  Can 
> someone tell me the line of code I need to ge the attributes.  I have tried things like:
> 
> 
> items.attributes
> 
> items.listAttributes
> 
> 
> I even checked the item before I output the json and saw that tthe 
> attributes are on the main list.  I can't seem to get the LUA function 
> to see the things like starting value and I don't know what I have to 
> do so that I can parse the levels correctly.  All help is welcome.  
> Heck if someone has something that can take the above docx list and 
> output it as a text list that is all I need.  I can wrap that in our 
> tags.    I  have been looking for any examples of LUA filters that 
> make multi  level broken lists into anything and I can not find an example.
> 
> 
> Thanks for any help.
> 
> 
> 
>  
> 
> 
> --
> 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit 
> [2]https://groups.google.com/d/msgid/
> pandoc-discuss/39a03df1-6228-449f-8f20-1b5b92248cecn%40googlegroups.com.
> 
> References:
> 
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] 
> https://groups.google.com/d/msgid/pandoc-discuss/39a03df1-6228-449f-8f
> 20-1b5b92248cecn%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/Y%2B3PTvBjmu8Y9koD%40localhost.

-- 
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/004201d9436c%247845f580%2468d1e080%24%40blinksoft.com.


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

end of thread, other threads:[~2023-02-18  7:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-16  4:50 Parsing a list Ken Perry
     [not found] ` <39a03df1-6228-449f-8f20-1b5b92248cecn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-02-16  6:38   ` Bastien DUMONT
2023-02-18  7:41     ` kperry-rhKcP+tiLR7by3iVrkZq2A

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