标签允许用户快速轻松地将代码片段插入到他们的帖子中。
¥A tag allows users to quickly and easily insert snippets into their posts.
概要
¥Synopsis
hexo.extend.tag.register( |
两个参数将传递到标签函数中:args
和 content
。args
包含传递到标签插件的参数,content
是来自标签插件的封装内容。
¥Two arguments will be passed into the tag function: args
and content
. args
contains the arguments passed into the tag plugin and content
is the wrapped content from the tag plugin.
自从 Hexo 3 引入异步渲染以来,我们就使用 Nunjucks 进行渲染。行为可能与 Swig 中的行为略有不同。
¥Since the introduction of asynchronous rendering in Hexo 3, we are using Nunjucks for rendering. The behavior may be somewhat different from that in Swig.
取消注册标签
¥Unregister Tags
使用 unregister()
用自定义函数替换现有的 标签插件。
¥Use unregister()
to replace existing tag plugins with custom functions.
hexo.extend.tag.unregister(name); |
示例
¥Example
const tagFn = (args, content) => { |
选项
¥Options
ends
使用结束标签。默认情况下,此选项为 false
。
¥Use end tags. This option is false
by default.
async
启用异步模式。默认情况下,此选项为 false
。
¥Enable async mode. This option is false
by default.
示例
¥Examples
不带结束标签
¥Without End Tags
插入 Youtube 视频。
¥Insert a Youtube video.
hexo.extend.tag.register("youtube", function (args) { |
带结束标签
¥With End Tags
插入引言。
¥Insert a pull quote.
hexo.extend.tag.register( |
异步渲染
¥Async Rendering
插入文件。
¥Insert a file.
var fs = require("hexo-fs"); |
前言和用户配置
¥Front-matter and user configuration
以下任何选项均有效:
¥Any of the following options is valid:
hexo.extend.tag.register('foo', function (args) { |
hexo.extend.tag.register("foo", require("./lib/foo")(hexo)); |
module.exports = hexo => { |