Well, couldn't help but give it a shot. Here's a short filter that does the trick. Will work at arbitrary depth. https://gist.github.com/jdutant/549ef06074d3ae00b78ca6ec8ed2cfe1 function fixList(elem) local changed = false local newList = pandoc.List:new() local function isSubList(list) return #list == 1 and (list[1].t == 'BulletList' or list[1].t == 'OrderedList') end for _,item in ipairs(elem.c) do if #newList > 0 and isSubList(item) then -- append item's sublist to the last item of newList changed = true newList[#newList]:insert(item[1]) else -- otherwise append item to newList newList:insert(item) end end if changed then elem.c = newList end return changed and elem or nil end return {{ OrderedList = fixList, BulletList = fixList, }} On Monday, February 27, 2023 at 12:33:54 AM UTC JDTS wrote: > > Thanks, I'll investigate this. The HTML structure is generated and > therefore quite uniform, so it may be possible to do the munging there. > On Sunday, February 26, 2023 at 10:47:36 AM UTC-5 Julien Dutant wrote: > >> From my labelled-lists filter ( >> https://github.com/dialoa/dialectica-filters/blob/main/labelled-lists/labelled-lists.lua), >> here is a filter + function that checks whether every item in a bullet list >> starts with a Span element. >> >> ```lua >> >> --- is_custom_labelled_list: Look for custom labels markup >> -- Custom label markup requires each item starting with a span >> -- containing the label >> -- @param element pandoc BulletList element >> function is_custom_labelled_list (element) >> local is_cl_list = true >> >> -- the content of BulletList is a List of List of Blocks >> for _,blocks in ipairs(element.c) do >> -- check that the first element of the first block is Span >> if not( blocks[1].c[1].t == 'Span' ) then >> is_cl_list = false >> break >> end >> end >> return is_cl_list >> >> end >> >> return {{ >> BulletList = function(element) >> if is_custom_labelled_list(element) then >> return pandoc.Para(pandoc.Str('Was a list of the required kind!))) >> end >> end, }} >> >> ``` >> >> The difficulty with manipulating lists is to follow their intricate >> structure: a BulletList element as a content (element.c) that is a pandoc >> List. Each item in it (element.c[1], element.c[2]) is of Blocks type, i.e. >> a pandoc.List where the each element is a block. In your case you should >> check that the list item only contains one block of type ordered list: >> >> if #elem.c[i] == 1 then list_item_contains_one_block_only = true end >> >> and check that this block is of type OrderedList: >> if #elem.c[i]==1 and elem.c[i].t == 'OrderedList' then ... >> >> you should then add that block to the previous item, and remove the >> current item. >> >> Hope this helps, >> >> J >> >> On Saturday, February 25, 2023 at 10:06:45 PM UTC JDTS wrote: >> >>> Thanks. Any pointers to lua filters that do something similar? >>> >>> On Saturday, February 25, 2023 at 10:01:08 AM UTC-5 Julien Dutant wrote: >>> >>>> Looks feasible. Pandoc converts the first html to: >>>> >>>> [ BulletList >>>> [ [ Plain >>>> [ ... Inlines ] >>>> ] >>>> , [ BulletList >>>> [ [ Plain >>>> [ ... Inlines ] >>>> ] >>>> , [ Plain >>>> [ ... Inlines ] >>>> ] >>>> ] >>>> ] >>>> , [ Plain >>>> [ Inlines ] >>>> ] >>>> ] >>>> ] >>>> >>>> I.e., the sublist is converted to its own list item. So the filter >>>> should pick up list, check if any item within them consists of a lone >>>> sublist, and if so, move it to the previous item. (And best, apply the >>>> filter recursively to that sublist itself.) >>>> >>>> On Saturday, February 25, 2023 at 2:26:04 PM UTC JDTS wrote: >>>> >>>>> The Apple Notes app produces (via AppleScript) HTML for notes with >>>>> nested lists structured like: >>>>> >>>>> >>>>> >>>>> As you can see, the sublist is incorrectly positioned. It should be >>>>> positioned *within* the
  • Level 1 element 1 item, ala: >>>>> >>>>> >>>>> >>>>> Is there a straightforward way with Lua filters to fix this at the AST >>>>> level, for arbitrary-depth sublist nesting? >>>>> >>>> -- 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/a299184a-2b46-4940-a634-bdb656bfa15dn%40googlegroups.com.