Skip to content

Commit 800459e

Browse files
authored
Merge pull request #16 from jjlee/honour-comments
Ignore commented clock expressions and SCHEDULED/DEADLINE/CLOSED markers
2 parents 7a45912 + 34fd9e2 commit 800459e

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

orgparse/date.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def from_str(cls, string):
421421
def compile_sdc_re(sdctype):
422422
brtype = 'inactive' if sdctype == 'CLOSED' else 'active'
423423
return re.compile(
424-
r'{0}:\s+{1}'.format(
424+
r'^(?!\#).*{0}:\s+{1}'.format(
425425
sdctype,
426426
gene_timestamp_regex(brtype, prefix='', nocookie=True)),
427427
re.VERBOSE)
@@ -551,7 +551,7 @@ def from_str(cls, line):
551551
)
552552

553553
_re = re.compile(
554-
r'CLOCK:\s+'
554+
r'^(?!#).*CLOCK:\s+'
555555
r'\[(\d+)\-(\d+)\-(\d+)[^\]\d]*(\d+)\:(\d+)\]--'
556556
r'\[(\d+)\-(\d+)\-(\d+)[^\]\d]*(\d+)\:(\d+)\]\s+=>\s+(\d+)\:(\d+)'
557557
)

orgparse/tests/test_data.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,64 @@ def test_iter_node():
9090

9191
by_iter = [n.heading for n in node]
9292
assert by_iter == ['H1', 'H2', 'H3']
93+
94+
95+
def test_commented_headings_do_not_appear_as_children():
96+
root = loads("""\
97+
* H1
98+
#** H2
99+
** H3
100+
#* H4
101+
#** H5
102+
* H6
103+
""")
104+
top_level = root.children
105+
assert len(top_level) == 2
106+
107+
h1 = top_level[0]
108+
assert h1.heading == "H1"
109+
assert h1.get_body() == "#** H2"
110+
111+
[h3] = h1.children
112+
assert h3.heading == "H3"
113+
assert h3.get_body() == "#* H4\n#** H5"
114+
115+
h6 = top_level[1]
116+
assert h6.heading == "H6"
117+
assert len(h6.children) == 0
118+
119+
120+
def test_commented_clock_entries_are_ignored_by_node_clock():
121+
root = loads("""\
122+
* Heading
123+
# * Floss
124+
# SCHEDULED: <2019-06-22 Sat 08:30 .+1w>
125+
# :LOGBOOK:
126+
# CLOCK: [2019-06-04 Tue 16:00]--[2019-06-04 Tue 17:00] => 1:00
127+
# :END:
128+
""")
129+
[node] = root.children[0]
130+
assert node.heading == "Heading"
131+
assert node.clock == []
132+
133+
134+
def test_commented_scheduled_marker_is_ignored_by_node_scheduled():
135+
root = loads("""\
136+
* Heading
137+
# SCHEDULED: <2019-06-22 Sat 08:30 .+1w>
138+
""")
139+
[node] = root.children[0]
140+
assert node.heading == "Heading"
141+
assert node.scheduled.start is None
142+
143+
144+
def test_commented_property_is_ignored_by_node_get_property():
145+
root = loads("""\
146+
* Heading
147+
# :PROPERTIES:
148+
# :PROPER-TEA: backup
149+
# :END:
150+
""")
151+
[node] = root.children[0]
152+
assert node.heading == "Heading"
153+
assert node.get_property("PROPER-TEA") is None

0 commit comments

Comments
 (0)