@@ -88,49 +88,41 @@ function Section.from_node(section_node, file, parent)
8888
8989 for child in section_node :iter_children () do
9090 if child :type () == ' plan' then
91- local plan_children = ts_utils .get_named_children (child )
92- local len = # plan_children
93- local i = 1
94- while i <= len do
95- local plan_item = plan_children [i ]
96- if not plan_item then
97- break
98- end
99- local next_item = plan_children [i + 1 ]
100-
101- local type = ' NONE'
102- local node = plan_item
103- local item_type = plan_item :type ():upper ()
104-
105- if item_type == ' NAME' and next_item and next_item :type ():upper () == ' TIMESTAMP' then
106- local t = file :get_node_text (plan_item ):upper ()
107- if t == ' DEADLINE:' or t == ' SCHEDULED:' or t == ' CLOSED:' then
108- node = next_item
109- type = t :sub (1 , t :len () - 1 )
110- i = i + 1
91+ for entry in child :iter_children () do
92+ if entry :type () == ' entry' then
93+ local first_node = entry :named_child (0 )
94+ local first_node_text = file :get_node_text (first_node )
95+ if entry :named_child_count () == 1 and first_node :type () == ' timestamp' then
96+ utils .concat (
97+ data .dates ,
98+ Date .from_org_date (first_node_text , {
99+ range = Range .from_node (first_node ),
100+ })
101+ )
102+ end
103+ if entry :named_child_count () == 2 and first_node :type () == ' entry_name' then
104+ local valid_plan_types = { ' SCHEDULED' , ' DEADLINE' , ' CLOSED' }
105+ local type = ' NONE'
106+ if vim .tbl_contains (valid_plan_types , first_node_text :upper ()) then
107+ type = first_node_text
108+ end
109+ local timestamp = file :get_node_text (entry :named_child (1 ))
110+ utils .concat (
111+ data .dates ,
112+ Date .from_org_date (timestamp , {
113+ range = Range .from_node (entry :named_child (1 )),
114+ type = type ,
115+ })
116+ )
111117 end
112118 end
113-
114- local date = file :get_node_text (node )
115- utils .concat (
116- data .dates ,
117- Date .from_org_date (date , {
118- type = type ,
119- range = Range .from_node (node ),
120- })
121- )
122- i = i + 1
123119 end
124120 end
125121 if child :type () == ' body' then
126- local dates = file :get_ts_matches (' (timestamp) @timestamp' , child )
127- for _ , date in ipairs (dates ) do
128- utils .concat (
129- data .dates ,
130- Date .from_org_date (date .timestamp .text , {
131- range = Range .from_node (date .timestamp .node ),
132- })
133- )
122+ local start_line = child :range ()
123+ local lines = file :get_node_text_list (child )
124+ for i , line in ipairs (lines ) do
125+ utils .concat (data .dates , Date .parse_all_from_line (line , start_line + i ))
134126 end
135127 local drawers = file :get_ts_matches (' (drawer) @drawer' , child )
136128 for _ , drawer_item in ipairs (drawers ) do
@@ -166,13 +158,16 @@ function Section.from_node(section_node, file, parent)
166158 data .title = file :get_node_text (headline_node )
167159 data .todo_keyword_node = headline_node :child (0 )
168160 end
169- if headline_node :type () == ' tag' then
170- local tag = file :get_node_text (headline_node )
171- if not vim .tbl_contains (data .tags , tag ) then
172- table.insert (data .tags , tag )
173- end
174- if not vim .tbl_contains (data .own_tags , tag ) then
175- table.insert (data .own_tags , tag )
161+ if headline_node :type () == ' tag_list' then
162+ local tags = ts_utils .get_named_children (headline_node )
163+ for _ , tag_node in ipairs (tags ) do
164+ local tag = file :get_node_text (tag_node )
165+ if not vim .tbl_contains (data .tags , tag ) then
166+ table.insert (data .tags , tag )
167+ end
168+ if not vim .tbl_contains (data .own_tags , tag ) then
169+ table.insert (data .own_tags , tag )
170+ end
176171 end
177172 end
178173 end
0 commit comments