Jade:段落内的链接
我正在尝试用 Jade 编写几个段落,但发现段落内有链接时很困难。
我能想到的最好的办法,我想知道是否有一种方法可以用更少的标记来做到这一点:
p
span.
this is the start
of the para.
a(href="http://example.com") a link
span.
and this is the rest of
the paragraph.
I'm trying to author a few paragraphs with Jade, but finding it difficult when there are links inside a paragraph.
The best I can come up with, and I'm wondering if there's a way to do it with less markup:
p
span.
this is the start
of the para.
a(href="http://example.com") a link
span.
and this is the rest of
the paragraph.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
从jade 1.0开始,有一种更简单的方法来处理这个问题,不幸的是我在官方文档中找不到它。
您可以使用以下语法添加内联元素:
因此,在 ap 中不进入多行的示例将类似于:
您还可以执行嵌套内联元素:
As of jade 1.0 there's an easier way to deal with this, unfortunately I can't find it anywhere in the official documentation.
You can add inline elements with the following syntax:
So, an example without going into multiple lines in a p, would be something like:
You can also do nested inline elements:
您可以使用 Markdown 过滤器并使用 Markdown(以及允许的 HTML)来编写段落。
或者,您似乎可以简单地输出 HTML 而不会出现任何问题:
我自己并没有意识到这一点,只是使用 jade 命令行工具对其进行了测试。看起来效果很好。
编辑:
看起来它实际上可以完全在 Jade 中完成,如下所示:
不要忘记在 para 末尾有一个额外的空格(尽管你看不到它。以及在
| 和
之间。否则它会看起来就像这样para.a linkand
而不是para a link and
You can use a markdown filter and use markdown (and allowed HTML) to write your paragraph.
Alternatively it seems like you can simply ouput HTML without any problems:
I wasn't aware of this myself and just tested it using the jade command line tool. It seems to work just fine.
EDIT:
It seems it can actually be done entirely in Jade as follows:
Don't forget an extra space at the end of para (although you can't see it. and between
| and
. Otherwise it will look like thispara.a linkand
notpara a link and
另一种方法:
Another way to do it:
另一种完全不同的方法是创建一个过滤器,它首先替换链接,然后用jade进行渲染第二个
渲染:
完整的工作示例:index.js(使用nodejs运行)
更通用的解决方案将渲染迷你子块玉石在一个独特的块中(可能由诸如
${jade comes here}
之类的东西来标识),所以......这可以用与上面完全相同的方式实现。
通用解决方案的工作示例:
Another completely different approach, would be to create a filter, which has first stab at replacing links, and then renders with jade second
Renders:
Full working example: index.js (run with nodejs)
A more general solution would render mini sub-blocks of jade in a unique block (maybe identified by something like
${jade goes here}
), so...This could be implemented in exactly the same way as above.
Working example of general solution:
如果您的链接来自可以使用的数据源:
请参阅插值
If your links come from a data source you can use:
See interpolation
编辑:此功能已实现并已关闭问题,请参阅上面的答案。
我发布了一个问题,将此功能添加到 Jade
https://github.com/visionmedia/ jade/issues/936
不过还没有时间实现它,更多的 +1 可能会有所帮助!
Edit: This feature was implemented and issue closed, see answer above.
I've posted an issue to get this feature added into Jade
https://github.com/visionmedia/jade/issues/936
Haven't had time to implement it though, more +1s may help !
这是我能想到的最好的
渲染...
工作正常,但感觉有点像黑客 - 确实应该有一个语法!
This is the best I can come up with
Renders...
Works ok, but feels like a bit of a hack - there really should be a syntax for this!
我没有意识到玉石每个标签都需要一行。我想我们可以节省空间。如果可以理解的话就更好了 ul>li>a[class="emmet"]{text}
I did not realize that jade requires a line per tag. I thought we can save space. Much better if this can be understood ul>li>a[class="emmet"]{text}
我必须在链接后面直接添加一个句点,如下所示:
This is your test [link].
我这样解决了它:
I had to add a period directly behind a link, like this:
This is your test [link].
I solved it like this:
根据 Daniel Baulig 的建议,下面与动态参数一起使用
As suggested by Daniel Baulig, used below with dynamic params
事实证明(至少现在)有一个非常简单的选择
Turns out there is (now at least) a perfectly simple option
有史以来最简单的事情;)但我自己也为此苦苦挣扎了几秒钟。无论如何,您需要使用 HTML 实体来表示“@”符号 ->
@
如果您想包含链接,假设您/某个电子邮件地址使用以下链接:
Most simplest thing ever ;) but I was struggling with this myself for a few seconds. Anywho, you need to use an HTML entity for the "@" sign ->
@
If you want to in include a link, let's say your/some email address use this: