12345678910111213141516171819202122232425262728 |
- class RichtextUtils {
- static String getHandleResult(String description) {
- if (description ==null || description.isEmpty) {
- return '';
- }
- String descriptionStr = description.replaceAllMapped(
- RegExp(r'<img\s+([^>]*?)style="([^"]*?)"([^>]*)>'),
- (match) {
-
- String imgTag = match.group(0)!;
-
- String style = match.group(2)!;
-
- String newStyle = style.replaceAll(RegExp(r'\s*width:\s*\d+%;?'), '').replaceAll(RegExp(r'\s*height:\s*\d+%;?'), '').trim();
-
- if (newStyle.isEmpty) {
- imgTag = imgTag.replaceAll(RegExp(r'\s+style="[^"]*?"'), '');
- } else {
- imgTag = imgTag.replaceAll(RegExp(r'style="[^"]*?"'), 'style="$newStyle"');
- }
- return imgTag;
- },
- );
- return descriptionStr;
- }
- }
|