* Table Captions in pandoc > 2.10 @ 2020-08-05 19:33 Leonard Rosenthol 2020-08-05 20:34 ` Albert Krewinkel 0 siblings, 1 reply; 4+ messages in thread From: Leonard Rosenthol @ 2020-08-05 19:33 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 1230 bytes --] I had used the table-short-captions.lua filter ( https://github.com/pandoc/lua-filters/blob/056178e835023a4e40a05557bb740423788e4d44/table-short-captions/table-short-captions.lua) as a starting point to support auto-numbering tables for Docx & ICML output. Had it working great for Pandoc 2.9... Just updated to 2.10 and finding that tbl.caption doesn't work any longer - for setting or getting :(. I found a code snippet, somewhere - can't find it any longer - that shows that for version > 2.10, you need to handle both a caption.short and a caption.long. But there seems to be *nothing* in the docs about this - and I can't figure out how to set it properly. I am trying to set it to a list of a RawInline - as that worked in 2.9 - but no luck here. what am I missing? Thanks, Leonard -- 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/CALu%3Dv3JH4a5LQbxcKzo%3Dt8L2oCjYs52Es7NLur6un%2B14mvHU%3Dw%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 1808 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Table Captions in pandoc > 2.10 2020-08-05 19:33 Table Captions in pandoc > 2.10 Leonard Rosenthol @ 2020-08-05 20:34 ` Albert Krewinkel [not found] ` <87mu38g7bt.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Albert Krewinkel @ 2020-08-05 20:34 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Did you try with the latest version of that filter? It was updated about three weeks ago to fix that issue. Leonard Rosenthol writes: > I had used the table-short-captions.lua filter ( > https://github.com/pandoc/lua-filters/blob/056178e835023a4e40a05557bb740423788e4d44/table-short-captions/table-short-captions.lua) > as a starting point to support auto-numbering tables for Docx & ICML > output. Had it working great for Pandoc 2.9... > > Just updated to 2.10 and finding that tbl.caption doesn't work any longer - > for setting or getting :(. I found a code snippet, somewhere - can't > find it any longer - that shows that for version > 2.10, you need to handle > both a caption.short and a caption.long. But there seems to be *nothing* > in the docs about this - and I can't figure out how to set it properly. I > am trying to set it to a list of a RawInline - as that worked in 2.9 - but > no luck here. > > what am I missing? > > Thanks, > Leonard -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <87mu38g7bt.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>]
* Re: Table Captions in pandoc > 2.10 [not found] ` <87mu38g7bt.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> @ 2020-08-05 21:34 ` Leonard Rosenthol [not found] ` <CALu=v3+h+PZzYkyjWhy_WpncUjMGcLeHwe3J3wzY=--i=q=SvQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Leonard Rosenthol @ 2020-08-05 21:34 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 5001 bytes --] Yes, though with some adjustments. Here is my method. ``` local function do_table(tbl) local caption if PANDOC_VERSION >= {2,10} then caption = pandoc.List(tbl.caption.long) else caption = tbl.caption end -- Escape if there is no caption present. if not caption or #caption == 0 then debug("No Caption") return nil else debug("Has Caption: " .. pandoc.utils.stringify(caption)) end local label if PANDOC_VERSION >= {2,10} then _, _, captionTxt, label = string.find(pandoc.utils.stringify(caption), "(.+){#(.+)}") else -- Try find the properties block local is_properties_span = function (inl) debug("props (" .. inl.t .. "): " .. pandoc.utils.stringify(inl)) return (inl.t) and (inl.t == "Span") -- is span and (inl.content) and (#inl.content == 0) -- is empty span end local propspan, idx = caption:find_if(is_properties_span) -- If we couldn't find properties, escape. if not propspan then debug("No propspan") return nil end -- Otherwise, parse it all label, short_caption, unlisted = parse_table_attrs(propspan.attr) caption[idx] = nil end debug("Label: "..label) -- if we get here, then we have a table that needs a number -- Put label back into caption, with new name & number if label then TABLE_COUNT = TABLE_COUNT + 1 local tableLbl = string.format("Table %d: ", TABLE_COUNT) if PANDOC_VERSION >= {2,10} then caption = { pandoc.Str(tableLbl), pandoc.Str(captionTxt) } debug("new Caption: " .. pandoc.utils.stringify(caption)) else caption:insert( 1, pandoc.Str(tableLbl) ) end caption = make_bookmark(label, caption) end if false then return tbl end -- set new caption if PANDOC_VERSION >= {2,10} then tbl.caption.long = caption tbl.caption.short = nil -- short_caption -- and pandoc.read(short_caption, FORMAT).blocks[1].content -- or nil debug("Long Caption: " .. pandoc.utils.stringify(tbl.caption.long)) -- debug("Short Caption: "..pandoc.utils.stringify(tbl.caption.short)) else tbl.caption = caption debug("Caption: "..pandoc.utils.stringify(tbl.caption)) end -- Place new table if PANDOC_VERSION >= {2,10} then -- return pandoc.Table( caption, tbl.aligns, tbl.widths, tbl.headers, tbl.rows ) -- return tbl local result = List:new{} result:extend {tbl} return result else local result = List:new{} if short_caption or unlisted then result:extend {defshortcapt(short_caption)} end result:extend {tbl} if short_caption or unlisted then result:extend {undefshortcapt} end return result end end ``` You can see all the debugging code adn tests that I've tried. The big differences from what the existing filter does is that rather than an empty span, I just use the text inline in the caption such as "Table: A Caption {#key}". And then my make_bookmark() routine just returns a `{pandoc.RawInline( "openxml", text)}` (where text is some openxml code). This worked perfectly for older Pandocs and fails in Compiled with pandoc-types 1.21, texmath 0.12.0.2, skylighting 0.8.5 On MacOS X Thanks in advance, Leonard On Wed, Aug 5, 2020 at 4:34 PM Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> wrote: > Did you try with the latest version of that filter? It was updated about > three weeks ago to fix that issue. > > Leonard Rosenthol writes: > > > I had used the table-short-captions.lua filter ( > > > https://github.com/pandoc/lua-filters/blob/056178e835023a4e40a05557bb740423788e4d44/table-short-captions/table-short-captions.lua > ) > > as a starting point to support auto-numbering tables for Docx & ICML > > output. Had it working great for Pandoc 2.9... > > > > Just updated to 2.10 and finding that tbl.caption doesn't work any > longer - > > for setting or getting :(. I found a code snippet, somewhere - can't > > find it any longer - that shows that for version > 2.10, you need to > handle > > both a caption.short and a caption.long. But there seems to be > *nothing* > > in the docs about this - and I can't figure out how to set it properly. > I > > am trying to set it to a list of a RawInline - as that worked in 2.9 - > but > > no luck here. > > > > what am I missing? > > > > Thanks, > > Leonard > > > -- > Albert Krewinkel > GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 > > -- > You received this message because you are subscribed to the Google Groups > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/87mu38g7bt.fsf%40zeitkraut.de > . > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CALu%3Dv3%2Bh%2BPZzYkyjWhy_WpncUjMGcLeHwe3J3wzY%3D--i%3Dq%3DSvQ%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 13502 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <CALu=v3+h+PZzYkyjWhy_WpncUjMGcLeHwe3J3wzY=--i=q=SvQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Table Captions in pandoc > 2.10 [not found] ` <CALu=v3+h+PZzYkyjWhy_WpncUjMGcLeHwe3J3wzY=--i=q=SvQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2020-08-06 2:24 ` Leonard Rosenthol 0 siblings, 0 replies; 4+ messages in thread From: Leonard Rosenthol @ 2020-08-06 2:24 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 8316 bytes --] Following up on my own issue... I broke down and read the source code & current documentation in git (vs. the public site) The issue appears to be that the Docx writer is not fully compliant with the new Caption object (which is in the git docs but not the public site. In the Docx writer it tries to convert the block-based LongCaption into a simple string (the old style caption) and it doesn't work correctly. I filed an issue about it - https://github.com/jgm/pandoc/issues/6594 In the meantime, knowing what the issue is - I worked around it by creating my own Div ahead of the table that acts (and is properly styled as) the caption. So now my do_table() method looks like: ``` local function do_table(tbl) local caption if PANDOC_VERSION >= {2,10} then caption = pandoc.List(tbl.caption.long) else caption = tbl.caption end -- Escape if there is no caption present. if not caption or #caption == 0 then debug("No Caption") return nil else -- debug("Has Caption: " .. pandoc.utils.stringify(caption)) end local label if PANDOC_VERSION >= {2,10} then _, _, captionTxt, label = string.find(pandoc.utils.stringify(caption), "(.+){#(.+)}") else -- Try find the properties block local is_properties_span = function (inl) return (inl.t) and (inl.t == "Span") -- is span and (inl.content) and (#inl.content == 0) -- is empty span end local propspan, idx = caption:find_if(is_properties_span) -- If we couldn't find properties, escape. if not propspan then debug("No propspan") return nil end -- Otherwise, parse it all label, short_caption, unlisted = parse_table_attrs(propspan.attr) caption[idx] = nil end -- debug("Label: "..label) -- if we get here, then we have a table that needs a number -- Put label back into caption, with new name & number if label then TABLE_COUNT = TABLE_COUNT + 1 local tableLbl = string.format("Table %d: ", TABLE_COUNT) if PANDOC_VERSION >= {2,10} then caption = { pandoc.Str(tableLbl), pandoc.Str(captionTxt) } captionTxt = pandoc.utils.stringify(caption) -- debug("new Caption: " .. captionTxt) else caption:insert( 1, pandoc.Str(tableLbl) ) end caption = make_bookmark(label, caption) short_caption = caption end -- set new caption if PANDOC_VERSION >= {2,10} then tbl.caption.long = pandoc.Para( captionTxt ) tbl.caption.short = short_caption -- debug("Long Caption: " .. pandoc.utils.stringify(tbl.caption.long)) -- debug("Short Caption: "..pandoc.utils.stringify(tbl.caption.short)) else tbl.caption = caption -- debug("Caption: "..pandoc.utils.stringify(tbl.caption)) end -- Place new table local result = List:new{} -- this block is required as the current Docx exporter doesn't handle the new -- style of captions correctly! if PANDOC_VERSION >= {2,10} then local caption_div = pandoc.Div({}) caption_div["attr"]["attributes"]["custom-style"] = "Table Caption" caption_div.content = { pandoc.Para(caption) } result:extend{ caption_div } end result:extend {tbl} return result end ``` On Wed, Aug 5, 2020 at 5:34 PM Leonard Rosenthol <leonardr-bM6h3K5UM15l57MIdRCFDg@public.gmane.org> wrote: > Yes, though with some adjustments. > > Here is my method. > > ``` > local function do_table(tbl) > local caption > if PANDOC_VERSION >= {2,10} then > caption = pandoc.List(tbl.caption.long) > else > caption = tbl.caption > end > > -- Escape if there is no caption present. > if not caption or #caption == 0 then > debug("No Caption") > return nil > else > debug("Has Caption: " .. pandoc.utils.stringify(caption)) > end > > local label > if PANDOC_VERSION >= {2,10} then > _, _, captionTxt, label = string.find(pandoc.utils.stringify(caption), > "(.+){#(.+)}") > else > -- Try find the properties block > local is_properties_span = function (inl) > debug("props (" .. inl.t .. "): " .. pandoc.utils.stringify(inl)) > > return (inl.t) and (inl.t == "Span") -- is span > and (inl.content) and (#inl.content == 0) -- is empty span > end > local propspan, idx = caption:find_if(is_properties_span) > > -- If we couldn't find properties, escape. > if not propspan then > debug("No propspan") > return nil > end > > -- Otherwise, parse it all > label, short_caption, unlisted = parse_table_attrs(propspan.attr) > > caption[idx] = nil > end > debug("Label: "..label) > -- if we get here, then we have a table that needs a number > -- Put label back into caption, with new name & number > if label then > TABLE_COUNT = TABLE_COUNT + 1 > local tableLbl = string.format("Table %d: ", TABLE_COUNT) > if PANDOC_VERSION >= {2,10} then > caption = { pandoc.Str(tableLbl), pandoc.Str(captionTxt) } > debug("new Caption: " .. pandoc.utils.stringify(caption)) > else > caption:insert( 1, pandoc.Str(tableLbl) ) > end > caption = make_bookmark(label, caption) > end > > if false then > return tbl > end > > -- set new caption > if PANDOC_VERSION >= {2,10} then > tbl.caption.long = caption > tbl.caption.short = nil > -- short_caption > -- and pandoc.read(short_caption, FORMAT).blocks[1].content > -- or nil > > debug("Long Caption: " .. pandoc.utils.stringify(tbl.caption.long)) > -- debug("Short Caption: "..pandoc.utils.stringify(tbl.caption.short)) > else > tbl.caption = caption > debug("Caption: "..pandoc.utils.stringify(tbl.caption)) > end > > -- Place new table > if PANDOC_VERSION >= {2,10} then > -- return pandoc.Table( caption, tbl.aligns, tbl.widths, tbl.headers, > tbl.rows ) > -- return tbl > local result = List:new{} > result:extend {tbl} > return result > else > local result = List:new{} > if short_caption or unlisted then > result:extend {defshortcapt(short_caption)} > end > result:extend {tbl} > if short_caption or unlisted then > result:extend {undefshortcapt} > end > return result > end > end > ``` > > You can see all the debugging code adn tests that I've tried. > > The big differences from what the existing filter does is that rather than > an empty span, I just use the text inline in the caption such as "Table: A > Caption {#key}". > > And then my make_bookmark() routine just returns a `{pandoc.RawInline( > "openxml", text)}` (where text is some openxml code). > > This worked perfectly for older Pandocs and fails in > Compiled with pandoc-types 1.21, texmath 0.12.0.2, skylighting 0.8.5 > On MacOS X > > Thanks in advance, > Leonard > > > On Wed, Aug 5, 2020 at 4:34 PM Albert Krewinkel < > albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> wrote: > >> Did you try with the latest version of that filter? It was updated about >> three weeks ago to fix that issue. >> >> Leonard Rosenthol writes: >> >> > I had used the table-short-captions.lua filter ( >> > >> https://github.com/pandoc/lua-filters/blob/056178e835023a4e40a05557bb740423788e4d44/table-short-captions/table-short-captions.lua >> ) >> > as a starting point to support auto-numbering tables for Docx & ICML >> > output. Had it working great for Pandoc 2.9... >> > >> > Just updated to 2.10 and finding that tbl.caption doesn't work any >> longer - >> > for setting or getting :(. I found a code snippet, somewhere - can't >> > find it any longer - that shows that for version > 2.10, you need to >> handle >> > both a caption.short and a caption.long. But there seems to be >> *nothing* >> > in the docs about this - and I can't figure out how to set it >> properly. I >> > am trying to set it to a list of a RawInline - as that worked in 2.9 - >> but >> > no luck here. >> > >> > what am I missing? >> > >> > Thanks, >> > Leonard >> >> >> -- >> Albert Krewinkel >> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "pandoc-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/pandoc-discuss/87mu38g7bt.fsf%40zeitkraut.de >> . >> > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CALu%3Dv3K87LKJ%2BvkWKnSOJQyJZwewixqHOVJbkDw7c3PJXe0dSg%40mail.gmail.com. [-- Attachment #2: Type: text/html, Size: 22242 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-06 2:24 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-08-05 19:33 Table Captions in pandoc > 2.10 Leonard Rosenthol 2020-08-05 20:34 ` Albert Krewinkel [not found] ` <87mu38g7bt.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> 2020-08-05 21:34 ` Leonard Rosenthol [not found] ` <CALu=v3+h+PZzYkyjWhy_WpncUjMGcLeHwe3J3wzY=--i=q=SvQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2020-08-06 2:24 ` Leonard Rosenthol
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).