我正在尝试使用 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/