问题
I am trying to setup a Telegram Instant View for a website.
i have a text with a lot of break-lines \n
and no <br>
so
i need a solution to replace every \n
to <br>
回答1:
Try @replace function:
@replace("\\n", "<br>"): $body//p
回答2:
There is no way (in the Instant View DSL) to replace a part of a text node with an HTML tag (i.e. element node). Any HTML you insert as text will be escaped.
回答3:
As I remember, if you debug $paragraph/text()
, there will be a lot of text nodes, that are separated with \n
in the original markup:
[0]: first line
[1]: second line
So, the only thing you need to do is just @after(<br>): $paragraph/text()
.
It's better not to make a big long paragraph with <br>
inside — split text on small <p>
aragraphs.
来源:https://stackoverflow.com/questions/44238180/how-to-replace-n-to-br-in-telegram-instant-view