简体   繁体   English

在 Pandoc 过滤器中嵌套额外的 Span 会使图像消失

[英]Nesting extra Span in Pandoc filter disappears the image

I am currently working on massaging the HTML output of a Pandoc filter due to some annoying restrictions in the CMS that is the eventual beneficiary of my hard work.由于 CMS 中的一些烦人的限制,我目前正在处理 Pandoc 过滤器的 HTML 输出,而这些限制是我辛勤工作的最终受益者。

My working filter (now with the obvious declarations) is as follows:我的工作过滤器(现在有明显的声明)如下:

local List = require 'pandoc.List'

local Emph = pandoc.Emph
local Quoted = pandoc.Quoted
local Span = pandoc.Span
local Str = pandoc.Str
local Strong = pandoc.Strong

local image_base = "http://my.website.example/images/"
local image_author = "Someone Not Stigma"

function process_images(el)
  el.src = el.src:gsub("^file:images/", image_base)
  el.caption = {
    Strong( Quoted( "DoubleQuote", el.caption ) ),
    Str(" by "),
    Emph(image_author)
  }
  return el
end

return {{Image = process_images}}

In the eventual HTML, this gives me a nice figure with img and figcaption element inside of it.在最终的 HTML 中,这给了我一个很好的图形,其中包含 img 和 figcaption 元素。 Wonderful.精彩的。 Unfortunately, my CMS destroys the figcaption (like it tends to destroy other stuff), and as such I figured I'd wrap everything in an extra span so I can style that one instead.不幸的是,我的 CMS 破坏了 figcaption(就像它往往会破坏其他东西一样),因此我想我会将所有内容都包装在一个额外的跨度中,这样我就可以为它设置样式。

function process_images(el)
  el.src = el.src:gsub("^file:images/", image_base)
  el.caption = {
    Span(
      {
        Strong( Quoted( "DoubleQuote", el.caption ) ),
        Str(" by "),
        Emph(image_author)
      },
      { class="img-caption" }
    )
  }
  return el
end

And yet somehow, this causes Pandoc to completely delete the image from the resulting HTML.然而不知何故,这会导致 Pandoc 从生成的 HTML 中完全删除图像。

I have tried replacing the table syntaxes with List({}) syntaxes, but that just gives me upvalue complaints.我曾尝试用 List({}) 语法替换表语法,但这只会给我带来高价值的抱怨。 I looked at the manual, but for as far I can tell I am doing everything right.我看了手册,但据我所知,我做的一切都是正确的。

What am I missing here?我在这里缺少什么?

I call pandoc as follows:我调用 pandoc 如下:

pandoc --from=markdown-tex_math_dollars "Content.pure.txt" --lua-filter=".\pandoc-filter.lua" --to=html5 --template=".\pandoc-template.txt" -o "Content.txt"

Extensions are .txt (because these files are not browser ready).扩展名是 .txt(因为这些文件不是浏览器就绪的)。 The template being used is rather lengthy (there's a fair bit of YAML variables and related markup), but be assured: $body$ can be found in there.所使用的模板相当冗长(有相当多的 YAML 变量和相关标记),但请放心:可以在其中找到 $body$。

I am not a wise man.我不是一个聪明人。 Always update to the latest version before posting questions, folks.在发布问题之前,请务必更新到最新版本,伙计们。

I was running an older version of Pandoc (v2.6), and upgrading to v2.9.1.1 suddenly made the output appear again.我正在运行旧版本的 Pandoc (v2.6),升级到 v2.9.1.1 突然使输出再次出现。 That's a lot of versions released in the span of about a year!在大约一年的时间里发布了很多版本!

(In my defense, my Pandoc-filter-fu is not particularly strong, so it makes sense to assume user error rather than program bug. Why is it that every time you assume bug, it is user error, and every time you assume user error, it is an outright bug?) (在我的辩护中,我的 Pandoc-filter-fu 不是特别强,所以假设用户错误而不是程序错误是有意义的。为什么每次假设错误都是用户错误,每次假设用户错误?错误,这是一个彻头彻尾的错误?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM