rich-text使用記錄

that.content = item.content.replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p').replace(/<p>/ig,
     '<p style="font-size: 15Px; line-height: 25Px;">')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
    .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img$1 style="width: 80%;height:400upx border-radius: 8Px;"');

方法一                     這種用法導致我解析出錯率頻發   

 

 

const regex = new RegExp('<img', 'gi');
     richtext= richtext.replace(regex, `< img style="max-width: 100%;"`);

 

    方法二                          圖片太大,脫離文檔流

 

const regex = new RegExp('<img', '
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章