dart-lang / dart-pad

An online Dart editor with support for console, web, and Flutter apps
https://dartpad.dev
BSD 3-Clause "New" or "Revised" License
1.67k stars 550 forks source link

Add support for package html #2970

Open insinfo opened 1 month ago

insinfo commented 1 month ago

Add support for package html https://pub.dev/packages/html

since dart:html cannot be used in the backend and several use cases for this package, to analyze html files to obtain certain text, web crawler, Generating HTML etc

Example

import 'package:html/parser.dart' as parser;
import 'package:html/dom.dart';

void main() {
  // Example HTML string
  String htmlString = '''
    <html>
      <body>
        <div>Inscrição Estadual: 123456789</div>
        <div>Other content</div>
      </body>
    </html>
  ''';

  // Parse the HTML string
  Document document = parser.parse(htmlString);

  // Find the tag containing 'Inscrição Estadual'
  Element? tag = document.querySelector('body')?.children.firstWhere(
        (element) => element.text.contains('Inscrição Estadual'),
      );

  // Print the found tag or a message if not found
  if (tag != null) {
    print('Found tag: ${tag.outerHtml}');
  } else {
    print('Tag with "Inscrição Estadual" not found.');
  }
}

image

AkashKeote commented 1 month ago

i would like to work on this project please assign me