PoiScript / orgize

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

Inconsistent handling of edge case headlines lacking space #19

Closed calmofthestorm closed 4 years ago

calmofthestorm commented 4 years ago

I wanted to mention a few edge cases I found involving headlines that don't have a space after the stars. Per the spec, none of these are headlines.

The first two are treated as headlines by org-element, but not org-agenda tags, org mode font lock, or orgize.

The second two are treated as headlines by org-element and orgize, but not org mode font lock.

It's fine if you want to just close this -- I'm not even entirely sure what the correct behavior should be. I just wanted to mention it since I found it when testing something. I could also send a PR for adding a errata/quirks documentation if you like.

fn main() {
    // Org mode: Treats it as not a headline (both font lock and agenda tag view)
    // Orgize 0.8.3: Not a headline
    // (with-temp-buffer (insert "*a\n")(org-element-parse-buffer (point-max))) --> title "a", level 1
    let org = orgize::Org::parse("*a :foo:\n");
    assert_eq!(0, org.headlines().count());

    // Org mode: Treats it as not a headline (both font lock and agenda tag view)
    // Orgize 0.8.3: Not a headline
    // (with-temp-buffer (insert "*a")(org-element-parse-buffer (point-max))) --> title "a", level 1
    let org = orgize::Org::parse("*a :foo:");
    assert_eq!(0, org.headlines().count());

    // Org mode: Treats it as not a headline (font lock)
    // Orgize 0.8.3: Headline with level 3 and title ""
    // (with-temp-buffer (insert "***")(org-element-parse-buffer (point-max))) --> title "", level 3
    let org = orgize::Org::parse("***");
    assert_eq!(1, org.headlines().count());
    assert_eq!(3, org.headlines().next().unwrap().level());
    assert_eq!("", org.headlines().next().unwrap().title(&org).raw);

    // Org mode: Treats it as not a headline (font lock)
    // Orgize 0.8.3: Headline with level 1 and title ""
    // (with-temp-buffer (insert "*\n")(org-element-parse-buffer (point-max))) --> title "", level 1
    let org = orgize::Org::parse("*\n");
    assert_eq!(1, org.headlines().count());
    assert_eq!(1, org.headlines().next().unwrap().level());
    assert_eq!("", org.headlines().next().unwrap().title(&org).raw);
}
PoiScript commented 4 years ago

I'm quite surprised that org-elements api will treat *a as a valid headline. In this case, I think we can just leave it as it is...

I could also send a PR for adding a errata/quirks documentation if you like.

PR is welcome! You can create a docs/ directly at root for documents.

calmofthestorm commented 4 years ago

A few more cases like this I should document when I write the PR.

 (with-temp-buffer (insert "*")(org-element-parse-buffer (point-max))) 
 (with-temp-buffer (insert "*\r")(org-element-parse-buffer (point-max))) 
 (with-temp-buffer (insert "*\t")(org-element-parse-buffer (point-max))) 

    let org = orgize::Org::parse("* \tTODO");
    // org-element gets nil for this.
    assert_eq!(org.headlines().next().unwrap().title(&org).keyword, None);

    let org = orgize::Org::parse("* \t TODO");
    // org-element gets nil for this.
    assert_eq!(org.headlines().next().unwrap().title(&org).keyword, None);