[英]Is there a plugin / something already built into Jekyll which can generate html tags?
Hey guys is there a plugin I am missing or method I cannot find to use within Jekyll so I don't have to manually write a bunch of html tags? 大家好,我有一个缺少的插件,或者找不到在Jekyll中使用的方法,因此不必手动编写一堆html标签?
Example would be {% a href="blah %} 例如{%a href =“ blah%}
This would render out 这将导致
<a href="blah"></a>
Simple answer is no, there's no stuff built in but there are provisions for you to extend Jekyll for you needs . 简单的答案是不,没有内置的东西,但是有一些规定可以根据您的需要扩展Jekyll 。 Unless, someone else knows better, I'm willing to be proven wrong.
除非别人知道得更多,否则我愿意证明自己是错误的。 You have two options that I can think of though ...
我有两个可以想到的选择...
Option 1: Use markdown, it's built in 选项1:使用markdown,它是内置的
Instead of what you are trying to do. 而不是您要尝试做的事情。 Liquid (what you are using) doesn't seem to support
<a>
tags - see here for more info from their docs Liquid(您使用的是什么)似乎不支持
<a>
标记-有关其文档的更多信息, 请参见此处
The GitHub guides provide details on how to use Markdown; GitHub指南提供了有关如何使用Markdown的详细信息;
Though the above links are for GitHub, the apply on Jekyll as well since Tom Preston-Werner (co-founder of GitHub) is the guy who wrote Jekyll. 尽管上面的链接是针对GitHub的,但由于Tom的共同创始人Tom Preston-Werner (GitHub的共同创始人)是Jekyll的作者,因此也适用于Jekyll。 Probably because it was born out of an internal need in GitHub, and figured there's no harm open-sourcing it.
可能是因为它是基于GitHub的内部需求而产生的,并且认为开放源代码并没有什么害处。
Oh, and this might be better because, if you are using GitHub pages ... they don't run any custom scripts. 哦,这可能会更好,因为,如果您使用的是GitHub页面……它们不会运行任何自定义脚本。
Option 2: Write a custom tag 选项2:编写自定义标签
There's some documentation in the official Jekyll site on the plugin page . Jekyll官方网站 的插件页面上有一些文档。 Something like this:
像这样:
# 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)
And you'd have something like this ... 而且你会有类似的东西...
<!-- Usage -->
{% a_tag 'http://example.com' %}
<!-- Output -->
<a href="http://example.com"></a>
I must admit, I haven't tested this just giving a high level explanation of what I'd try out from what I can garner from the docs. 我必须承认,我还没有进行过测试,只是对我可以从文档中获得的经验进行了深入的解释。 Try it out and see if it'll work and fix any errors that may spew out (I loosely typed this).
尝试一下,看看它是否可以解决所有可能出现的错误(我输入的内容很松散)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.