Remove HTML tags from a String in Dart

前端 未结 5 1800
傲寒
傲寒 2020-12-17 09:00

I’ve been trying to achieve this for a while, I have a string which contains a lot of HTML tags in it which is in some encoded form Like & lt; and & gt; (without th

5条回答
  •  半阙折子戏
    2020-12-17 09:16

    By just using

    import ‘package:html/parser.dart’;
    

    will get a problem, for those strings that includes
    and

    tags. Paragraph info is missing. May first replace
    to

    , then get List:

    import ‘package:html/parser.dart’  as dom; 
    
    htmlString = '

    first ... line.
    second.....line.

    '; List cleanStrings = new List(); List ps = parse(htmlString.replaceAll('
    ', '

    '))).querySelectorAll('p'); if (ps.isNotEmpty) ps.forEach((f) { (f.text != '') cleanStrings.add(f.text); });

提交回复
热议问题