<rich-text>
Image styles and text indentation issues
<rich-text nodes="{{content}}"></rich-text>
/ / the content
' I am paragraph 1
& NBSP; I am a paragraph 2 < / p > < p > < img SRC = "https://test1.image" Alt = "" width =" 1440 "height =" 1080 "/ > < / p > < p > & have spent I am a paragraph 3 < / p > < p > < img SRC = "https://test2.image" Alt = "" width =" 1440 "height =" 1080 "/ > < / p > < p > < img SRC =" https://test3.image" alt="" width="1015" height="571" />
'
Copy the code
But the small program & NBSP does not work, there is no indentation effect. content.replace(/ /g,”\xa0″) can solve the problem
The final code is:
// Reset img style, indent p tag
resetCss: function (content) {
let reg = /(style|class)="[^"]+"/gi;
let img = /<img[^>]+>/gi;
let res;
// Remove the img original style
if (img.test(content)) {
res = content.match(img);
for (let i = 0; i < res.length; i++) {
content = content.replace(res[i], res[i].replace(reg, "")); }}// Set the img style and indent
return content
.replace(/\<img/gi.')
.replace(/ /g."\xa0")},Copy the code