reader_mode 0.2.1 copy "reader_mode: ^0.2.1" to clipboard
reader_mode: ^0.2.1 copied to clipboard

A Dart port of Mozilla's Readability.js content extraction library.

example/reader_mode_example.dart

// ignore_for_file: avoid_print

import 'package:reader_mode/reader_mode.dart';

void main() {
  // Example HTML content
  const html = '''
<!DOCTYPE html>
<html>
<head>
  <title>Example Article</title>
  <meta name="author" content="John Doe"/>
</head>
<body>
  <nav>Navigation links here</nav>
  <article>
    <h1>The Main Article Title</h1>
    <p>This is the first paragraph of the article content.
    It contains important information that readers want to see.</p>
    <p>This is another paragraph with more content. The Readability
    algorithm will extract this as the main content of the page.</p>
  </article>
  <aside>Sidebar content</aside>
  <footer>Footer content</footer>
</body>
</html>
''';

  // Method 1: Use the parse() convenience function (recommended)
  print('Parsing with parse() function...\n');
  final article = parse(
    html,
    baseUri: 'https://example.com/article',
  );
  if (article == null) {
    throw StateError('Failed to extract readable content');
  }

  print('Title: ${article.title}');
  print('Byline: ${article.byline}');
  print('Excerpt: ${article.excerpt}');
  print('Length: ${article.length} characters');
  print('\nContent:\n${article.content}');
}
0
likes
60
points
70
downloads

Publisher

verified publishermortz.dev

Weekly Downloads

A Dart port of Mozilla's Readability.js content extraction library.

Repository (GitHub)
View/report issues
Contributing

Topics

#html #parser #readability #content-extraction #article

License

unknown (license)

Dependencies

html

More

Packages that depend on reader_mode