2

I have a javascript string that I need to split by format type written inside the string so that I can output bold and italic text in jade such that

"Hello {b World b}{i and everyone i} else! And {i hello to you i}. 1 < 5."

would output:

Hello World and everyone else! And hello to you. 1 < 5

The string contains an indeterminate amount of these tags (0+) in any order, but I only care about "i" and "b" tags. I've tried a simple string.replace and tried injecting html:

- line = line.replace("{b ", "<b>");
- line = line.replace(" b}", "</b>");
- line = line.replace("{i ", "<i>");
- line = line.replace(" i}", "</i>");
| #{line}

But the jade template tries to be smart and outputs:

"Hello <b>World</b><i>and everyone</i> else! And <i>hello to you</i>. 1 < 5"

because it converts each to

&lt; and &gt;

Note that the string may contain < or > inside. I'm totally stuck.

4

1 回答 1

0

来自GitHub 自述文件

我们还可以使用未转义的变体 !{html},因此以下将产生一个文字脚本标记:

- var html = "<script></script>"
| !{html}
于 2013-06-20T21:12:41.647 回答