jr-util
Version:
这是MJR的JS工具库。定期更新
22 lines (21 loc) • 665 B
JavaScript
const g = (t) => {
if (typeof t != "string")
return t;
try {
let e = t.replace(/<img[^>]*>/gi, function(r, i) {
return r = r.replace(/width="[^"]+"/gi, "").replace(/width='[^']+'/gi, ""), r = r.replace(/height="[^"]+"/gi, "").replace(/height='[^']+'/gi, ""), r;
});
return e = e.replace(
/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/gi,
'<p style="margin-bottom:12px"'
), e = e.replace(/<br[^>]*\/>/gi, ""), e = e.replace(
/\<img/gi,
'<img style="max-width:100%;width:auto;height:auto;display:block;margin-top:10px;margin-bottom:10px;"'
), e;
} catch {
return t;
}
};
export {
g as formatRichText
};