ReedSun commented on issue #45:
URL:
https://github.com/apache/incubator-weex-ui/issues/45#issuecomment-699457634
> @hizhengfu 👌. Thank U,
> 终于解决了这个问题.我顺便把一个文本里有图标和文字都有的情况,也处理了
>
> ```
> decode(text) {
> // 正则匹配 图标和文字混排
> // eg: 我去上学校,天天不迟到
> let regExp = /&#x[a-z]\d{3,4};?/;
> if (regExp.test(text)) {
> return text.replace(new RegExp(regExp, 'g'), function
(iconText) {
> let replace = iconText.replace(/&#x/, '0x').replace(/;$/,
'');
> return String.fromCharCode(replace);
> });
> } else {
> return text;
> }
> }
> ```
@phoenixsky 感谢!不过代码里的正则有点问题,不能匹配到类似于 `` 这样的内容,我完善了一下。
```
function decode(value) {
const regExp = /&#x[a-fA-F\d]{1,4};?/;
if (regExp.test(value)) {
return value.replace(new RegExp(regExp, 'g'), iconText =>
String.fromCharCode(iconText.replace(/&#x/, '0x').replace(/;$/, '')));
}
return value;
},
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]