PoiScript / orgize

A Rust library for parsing org-mode files.
https://poiscript.github.io/orgize/
MIT License
278 stars 34 forks source link

:PROPERTIES: takes precedence over headlines #24

Closed calmofthestorm closed 7 months ago

calmofthestorm commented 4 years ago

This one is interesting, and from what I remember of parser generators, may be tricky to resolve. Currently, it seems that Orgize will fail to parse headlines "inside" a :PROPERTIES: drawer. This occurs only when the headline inside the drawer is at a greater level, and only in properties drawers. Additionally, the properties drawer must immediately follow the headline and planning (this is required by the Org spec to be a valid properties drawer, but you may have a different drawer named :PROPERTIES: elsewhere in the node).

Note that this is arguably a broken org file -- all org files are valid strings, but, e.g., org-lint would catch this case. But I do think that properly parsing headlines should work even in the presence of broken drawers.

fn main() {
    // Passes -- drawer other than PROPERTIES.
    let org = orgize::Org::parse("* Hello\n:MYDRAWER:\n** World\n:END:");
    assert_eq!(org.headlines().count(), 2);

    // Passes -- both headlines at same depth.
    let org = orgize::Org::parse("* Hello\n:PROPERTIES:\n* World\n:END:");
    assert_eq!(org.headlines().count(), 2);

    // Passes -- in order to be the special "properties" drawer, the drawer must
    // immediately follow the headline and planning..
    let org = orgize::Org::parse("* Hello\nSpacer\n:PROPERTIES:\n** World\n:END:");
    assert_eq!(org.headlines().count(), 2);

    // Fails
    let org = orgize::Org::parse("* Hello\n:PROPERTIES:\n** World\n:END:");
    assert_eq!(org.headlines().count(), 2);
}
PoiScript commented 7 months ago

Thanks you for reporting this! This issue has been fixed in v0.10:

image