javascript - 如何增加博客片段中的字符长度而不是使用有限的长度 'data:post.snippet' ?

标签 javascript character blogger code-snippets

我目前正在使用“data:post.snippet”作为博客移动代码片段。

<div class='post-body' style='color:black;'>
  <b:if cond='data:post.snippet'><data:post.snippet/></b:if>
</div>

但是它的字符长度(140)太低了,标题和段落之间没有换行符。当在最开始有一个标题时,换行符是必要的。有人可以向我推荐一个 javascript 代码来替换上面的代码以解决这两个问题。

最佳答案

您可以使用 data:post.longSnippet 数据标签,它有 300-400 个字符的限制

<div class='post-body' style='color:black;'>
    <b:if cond='data:post.snippet'><data:post.longSnippet/></b:if>
</div>

否则,如果您想控制要在代码段中显示的文本的确切数量,则可以在 new themes 中使用新推出的运算符。

<div class='post-body' style='color:black;'>
    <b:eval expr='snippet(data:post.body, {length: 450, links: false})' />
</div>

snippet(string, options)

Produces a short snippet from an HTML string.

options: Object specifying the snippeting options, which are:

links: boolean for whether to preserve anchors/links in the snippet. Defaults to true.

linebreaks: boolean for whether to preserve linebreaks (tags) in the snippet. Defaults to true.

ellipsis: boolean for whether to append an ellipsis (…) to the end of the snippet. Defaults to true.

length: Number specifying the maximum length of the snippet.

关于javascript - 如何增加博客片段中的字符长度而不是使用有限的长度 'data:post.snippet' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34963026/

相关文章:

javascript - 如果使用 Redux 从 Firebase 获取数据,如何显示事件指示器

mysql - 字符编码错误的数据库

c - 在 C 中将整数的最后两位作为字符串返回

wordpress - blogger.com 博客的社交内容储物柜?是否可以

javascript - Knockout ObservableArray.replace() 函数不更新 'optionsText' 绑定(bind)

javascript - 道场和 Firebug

javascript - 带 url 加通用变量的 if 语句

javascript - 您能否将您的博客设置为仅显示 Blogger 中帖子的第一个标签?

html - 帖子内容不乱?

javascript - 如何不使用多部分编码上传文件? (可能使用八位位组或其他东西)