1

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>

Ehsan Dehghani
  • 111
  • 1
  • 2
  • 12

3 Answers3

2

Try @replace function:

@replace("\\n", "<br>"): $body//p
Sean Wei
  • 7,433
  • 1
  • 19
  • 39
0

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.

laughedelic
  • 6,230
  • 1
  • 32
  • 41
0

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.

xamgore
  • 1,723
  • 1
  • 15
  • 30