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 READMEから

エスケープされていないバリアント !{html} を利用することもできるため、以下はリテラル スクリプト タグになります。

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