【问题标题】:Is there a plugin / something already built into Jekyll which can generate html tags?Jekyll 中是否有可以生成 html 标签的插件/东西?
【发布时间】:2014-03-29 02:06:53
【问题描述】:

大家好,有没有我遗漏的插件或者我找不到在 Jekyll 中使用的方法,所以我不必手动编写一堆 html 标签?

例如 {% a href="blah %}

这会渲染出来

 <a href="blah"></a>

【问题讨论】:

    标签: ruby jekyll jekyll-extensions


    【解决方案1】:

    简单的答案是否定的,没有内置的东西,但有给你extend Jekyll for you needs 的规定。除非,其他人知道得更好,否则我愿意被证明是错误的。你有两个我能想到的选择......

    选项1:使用markdown,它是内置的

    而不是您正在尝试做的事情。 Liquid(您正在使用的)似乎不支持 &lt;a&gt; 标签 - see here 从他们的文档中获取更多信息

    GitHub 指南提供了有关如何使用 Markdown 的详细信息;

    虽然上面的链接是针对 GitHub 的,但由于 Tom Preston-Werner(GitHub 的联合创始人)是 Jekyll 的作者,Jekyll 上的申请也是如此。可能是因为它是出于 GitHub 的内部需求而诞生的,并且认为开源它没有害处。

    哦,这可能会更好,因为如果您使用的是 GitHub 页面……它们不会运行任何自定义脚本。

    选项 2:编写自定义标签

    the plugin page 上的官方Jekyll site 中有一些文档。像这样的:

    # Define the custom tag, 'a_tag'
    module Jekyll
      class RenderHyperlinkTag < Liquid::Tag
    
        def initialize(tag_name, text, tokens)
          super
          @url = text
        end
    
        # At a minimum, liquid tags must implement render which outputs
        # the contents of the tag
        def render(context)
          "<a href=\"#{@url}\"></a>"
        end
      end
    end
    
    # Register the new tag, 'a_tag'
    Liquid::Template.register_tag('a_tag', Jekyll::RenderHyperlinkTag)
    

    你会有这样的东西......

    <!-- Usage -->
    {% a_tag 'http://example.com' %}
    
    <!-- Output -->
    <a href="http://example.com"></a>
    

    我必须承认,我没有对此进行测试,只是对我将从文档中获得的内容进行高级解释。试一试,看看它是否能正常工作并修复任何可能出现的错误(我打错字了)。

    【讨论】:

    • 这不是我想要的。它最类似于我可以在模板中使用的 rails 标签助手。
    • @amchang87 用第二个选项更新了答案。告诉我进展如何。
    • 我同意选项 #2,我只是希望在我必须开始编写自己的东西之前,有人能开箱即用,谢谢。
    猜你喜欢
    • 2012-06-19
    • 2011-08-19
    • 2013-01-13
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    相关资源
    最近更新 更多