react-native-rich-editor icon indicating copy to clipboard operation
react-native-rich-editor copied to clipboard

How to avoid divs

Open apgsn opened this issue 4 years ago • 4 comments

Hi, is there a way to have div-free html content produced by the editor? All other tags are meaningful and indicate a specific feature, but divs aren't, except for newlines which may as well be replaced by brs.

apgsn avatar Jan 18 '21 11:01 apgsn

IMO, there should be a setting to turn this off if not by default. For now I'm stripping them out manually.

sadikyalcin avatar Sep 01 '21 16:09 sadikyalcin

@sadikyalcin would you mind sharing your code? I've been messing around with regexes but they can't quite replicate the actual view, there are too many edge cases even for my limited toolbar (bold, lists and hr). I always end up adding some extra <br> here and there.

apgsn avatar Sep 06 '21 10:09 apgsn

@sadikyalcin would you mind sharing your code? I've been messing around with regexes but they can't quite replicate the actual view, there are too many edge cases even for my limited toolbar (bold, lists and hr). I always end up adding some extra <br> here and there.

Regexes never worked properly for me as well. Simple replaceAll with the below gave me the best result.

let body = html.replaceAll('<div></div>', '');
body = body.replaceAll('<div>', '');
body = body.replaceAll('</div>', '');

sadikyalcin avatar Sep 06 '21 10:09 sadikyalcin

do you have any other solution?

GeunwonChoi avatar Jan 04 '22 01:01 GeunwonChoi