-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.dart
58 lines (55 loc) · 1.45 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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());
}
}