org_parser 6.1.0 copy "org_parser: ^6.1.0" to clipboard
org_parser: ^6.1.0 copied to clipboard

A pure-Dart parser for Emacs Org Mode (https://orgmode.org) markup

example/example.dart

import 'package:org_parser/org_parser.dart';

void main() {
  {
    // Parse a very simple document
    const docString = '''* TODO [#A] foo bar
baz buzz''';
    final doc = OrgDocument.parse(docString);
    final section = doc.sections[0];
    print(section.headline.keyword?.value);
    final title = section.headline.title!.children[0] as OrgPlainText;
    print(title.content);
    final paragraph = section.content!.children[0] as OrgParagraph;
    final body = paragraph.body.children[0] as OrgPlainText;
    print(body.content);
  }

  {
    // Extract TODOs from a document
    const docString = '''* TODO Go fishing
** Equipment
- Fishing rod
- Bait
- Hat
* TODO Eat lunch
** Restaurants
- Famous Ray's
- Original Ray's
* TODO Take a nap''';
    final doc = OrgDocument.parse(docString);
    doc.visitSections((section) {
      if (section.headline.keyword?.value == 'TODO') {
        final title = section.headline.title!.children
            .whereType<OrgPlainText>()
            .map((plainText) => plainText.content)
            .join();
        print("I'm going to ${title.toLowerCase()}");
      }
      return true;
    });
  }

  {
    // Edit a document
    final docString = '''* TODO [#A] foo bar
baz buzz''';
    final doc = OrgDocument.parse(docString);
    final newDoc = doc
        .edit()
        .goDown()
        .goDown()
        .goRight()
        .goDown()
        .replace(OrgPlainText('bazinga'))
        .commit();
    print(newDoc.toMarkup());
  }
}
4
likes
0
pub points
47%
popularity

Publisher

verified publishermadlon-kay.com

A pure-Dart parser for Emacs Org Mode (https://orgmode.org) markup

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

functional_zipper, petitparser

More

Packages that depend on org_parser