Replace the rich text content in the applet with regular expressions to solve the problem of image deformation

        In the development of small programs, sometimes it is necessary to display the pictures edited by the rich text editor, but because the style of the pictures cannot be directly replaced by css in the small program, it is impossible to make the pictures self-adaptive. At this time, regular expressions are used to replace the rich text content The style can solve this problem;

The above picture ⬆️ is the content of the rich text returned by the interface before replacement, and the regularization is executed

// 修改富文本图片
formatRichText(html){
	let regex=/width:(.+?)\"/g;
	let newContent= html.replace(regex,'width:100%;height:auto;"');
	return newContent;
}

Replace the content between "width:" and " to complete the replacement

 

Guess you like

Origin blog.csdn.net/weixin_42252416/article/details/124888428