xhtml - 将文本转换为 Liquid 模板中的段落

标签 xhtml template-engine liquid shopify

我正在尝试使用 Liquid 模板语言将原始字符串转换为 html。我想做的就是转换这个:

Hello. This
is a text.

Please convert me.

进入此:

<p>Hello. This<br />
is a text.</p>
<p>Please convert me.</p>

我尝试过的

{{ mytextvariable | newline_to_br | replace: "<br />\n<br />", "</p><p>" | replace: "<p></p>", "" | prepend: '<p>' | append: '</p>' }}

但这给了我(注意双 <br /> ):

<p>Hello. This<br />
is a text.<br />
<br />
Please convert me.</p>

站点注释

这将用于 Shopify 网站。

最佳答案

使用 newline_to_br 时,您将用换行标记替换新行,因此第一个替换不会替换任何内容,换行符消失了。

关于xhtml - 将文本转换为 Liquid 模板中的段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11892420/

相关文章:

node.js - 如何转义 node.js 中的 EJS 模板代码以在客户端进行评估?

java - 将 Freemarker 集成到 Spring mvc 时出错

ruby-on-rails - Shopify如何确保其液体模板安全(避免使用XSS)?

html - 使布局可扩展的最佳做法是什么?

css - 在 XHTML 页面上定位对象

javascript - 如何在ui内生成不同的div id :repeat for javascript code

html - HTML 中的目标值 blank,self,parent,top 有什么区别?

java - 是否有一个库可以将任何字符串转换为符合代码约定的有效类名

javascript - 如何在 Shopify 的产品卡(显示在着陆页和产品系列页面上)中添加指向产品变体的链接?

html - 定义布局时液体变量停止工作