You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hugo columns短码内图片无法渲染,如何解决?

解决Hugo columns短码内图片不渲染的问题

下面是几种可行的解决方式:

  • 直接使用HTML图片标签:把columns短码内的Markdown图片语法替换成原生HTML标签,无需修改模板即可让图片正常显示。示例代码:

    {{< columns >}}
    
    The top-right corner of the home page shows your email address and can be used to access your profile.
    
    <---&gt;
    
    <img src="top-right.png" alt="email-address">
    
    {{< /columns >}}
    
  • 修改columns短码模板:找到站点中columns短码的模板文件(路径一般为layouts/shortcodes/columns.html),将输出内容的{{ .Inner }}替换为{{ .Inner | markdownify }},确保Hugo解析短码内部的Markdown语法。修改后的模板示例:

    {{ $columns := split .Inner "<---&gt;" }}
    <div class="flex flex-wrap">
      {{ range $columns }}
        <div class="flex-even markdown-inner" style="flex-grow: 1;">
          {{ . | markdownify }}
        </div>
      {{ end }}
    </div>
    

    调整后,短码内的所有Markdown语法(包括图片)都会被正确渲染。

  • 改用Hugo内置figure短码:将Markdown图片语法替换为Hugo的figure短码,利用短码嵌套的特性实现解析。示例代码:

    {{< columns >}}
    
    The top-right corner of the home page shows your email address and can be used to access your profile.
    
    <---&gt;
    
    {{< figure src="top-right.png" alt="email-address" >}}
    
    {{< /columns >}}
    

内容的提问来源于stack exchange,提问作者mikeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 15:15:58