PoiScript / orgize

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

Priority cookie causes first word of title to be swallowed when there is no space after it #20

Closed calmofthestorm closed 4 years ago

calmofthestorm commented 4 years ago

I was surprised to find that priority cookies don't need any whitespace after them, but orgize, org element, the spec, and org-mode all agree that the title may follow it immediately.

When the first word of the title immediately follows the priority cookie, Orgize correctly parses the priority, but will swallow the first word (i.e., all characters after the ] until the next whitespace) from the title.

This also occurs when the headline is commented (i.e., the COMMENT word is swallowed, and thus the headline is not detected as commented).

An interesting relationship to https://github.com/PoiScript/orgize/issues/17 is that "::" is also swallowed, giving an empty title vs "::" for org-element.

The last is a minor edge case probably not worth actually fixing unless it comes out of the other two (I can add it to the errata if it remains), but I think that the swallowed word is worth opening an issue for.

fn main() {
    let s = "* [#B]this_word_is_swallowed this_one_is_not";
    let org = orgize::Org::parse(&s);

    // Orgize swallows the word; org-element does not:
    // (headline (:raw-value this_word_is_swallowed this_one_is_not :priority 66 :title this_word_is_swallowed this_one_is_not))
    assert_eq!(
        "this_word_is_swallowed this_one_is_not",
        org.headlines().next().unwrap().title(&org).raw
    );

    let s = "* [#B]COMMENT hello world";
    let org = orgize::Org::parse(&s);

    assert!(org.headlines().next().unwrap().title(&org).is_commented());
    assert_eq!(
        "COMMENT hello world",
        org.headlines().next().unwrap().title(&org).raw
    );

    let s = "****** [#B]*  :a: ";
    let org = orgize::Org::parse(&s);
    assert_eq!(org.headlines().next().unwrap().title(&org).tags, vec!("a"));

    let s = "**  DONE [#B]::";
    let org = orgize::Org::parse(&s);
    // (headline (:raw-value :: :level 2 :priority 66 :todo-keyword DONE :title :: ))
    assert_eq!(org.headlines().next().unwrap().title(&org).raw, "::");
}
PoiScript commented 4 years ago

Fixed by a99702a.