Skip to content

Commit b6df02a

Browse files
committed
Fix handling of non-properties in drawers
1 parent b4987db commit b6df02a

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/src/org/grammar.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,9 @@ class OrgContentGrammarDefinition extends GrammarDefinition {
818818

819819
Parser drawerContent() {
820820
final end = ref0(drawerEnd);
821-
return (ref0(property) | ref0(nonDrawerElements) | ref1(textRun, end))
821+
return (ref0(property) |
822+
ref0(nonDrawerElements) |
823+
ref1(textRun, ref0(property) | ref0(nonDrawerElements) | end))
822824
.starLazy(end);
823825
}
824826

test/org/parser/drawer_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,43 @@ a
9999
expect(property2.isEmpty, isFalse);
100100
expect(property2.isNotEmpty, isTrue);
101101
});
102+
test('real and invalid value property', () {
103+
final result = parser.parse(''':FOOBAR:
104+
:foo:k
105+
:foo: bar
106+
:END:''');
107+
final drawer = result.value as OrgDrawer;
108+
expect(drawer.properties().length, 1);
109+
final body = drawer.body;
110+
final invalid = body.children[0] as OrgPlainText;
111+
expect(invalid.content, ':foo:k\n');
112+
final valid = body.children[1] as OrgProperty;
113+
expect(valid.key, ':foo:');
114+
expect(valid.isEmpty, isFalse);
115+
expect(valid.isNotEmpty, isTrue);
116+
expect(valid.value!.toMarkup(), 'bar');
117+
});
118+
test('property and text run', () {
119+
final result = parser.parse(''':FOOBAR:
120+
a *b* /c/
121+
:foo: bar
122+
:END:''');
123+
final drawer = result.value as OrgDrawer;
124+
expect(drawer.properties().length, 1);
125+
final body = drawer.body;
126+
final first = body.children[0] as OrgPlainText;
127+
expect(first.content, 'a ');
128+
final second = body.children[1] as OrgMarkup;
129+
expect(second.style, OrgStyle.bold);
130+
expect(second.toMarkup(), '*b*');
131+
final third = body.children[3] as OrgMarkup;
132+
expect(third.style, OrgStyle.italic);
133+
expect(third.toMarkup(), '/c/');
134+
final property = body.children[5] as OrgProperty;
135+
expect(property.key, ':foo:');
136+
expect(property.isEmpty, isFalse);
137+
expect(property.isNotEmpty, isTrue);
138+
expect(property.value!.toMarkup(), 'bar');
139+
});
102140
});
103141
}

0 commit comments

Comments
 (0)