PoiScript / orgize

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

support for top-level properties drawer #78

Closed rrix closed 3 weeks ago

rrix commented 1 month ago

as of org 9.5, properties drawers are allowed before the first-level heading

Org mode is moving more towards making things before the first headline behave just as if it was at outline level 0. Inheritance for properties will work also for this level. In other words: defining things in a property drawer before the first headline will make them "inheritable" for all headlines.

org-roam uses this in the org-roam-capture template and parses the level 0 heading as if it were a regular org-roam node/org-mode heading. It would be nice if there was a Document::properties() which returns an Option<PropertyDrawer>

PoiScript commented 1 month ago

supported in 9b8aec0:

    let org = Org::parse(
        r#":PROPERTIES:
:key: value
:END:
"#,
    );

    assert_eq!(
        org.document().properties().unwrap().get("key").unwrap(),
        "value"
    );
rrix commented 1 month ago

I can't seem to get this one to work.

:PROPERTIES:
:ID:       20220718T085035.042592
:END:
#+TITLE: Complete Computing
#+ARCOLOGY_KEY: cce/index
#+ARCOLOGY_ALLOW_CRAWL: t

dumps the following syntax on dbg!:

[src/extract.rs:18] doc.document() = Document {
    syntax: DOCUMENT@0..2791
      SECTION@0..2412
        DRAWER@0..53
          DRAWER_BEGIN@0..13
            COLON@0..1 ":"
            TEXT@1..11 "PROPERTIES"
            COLON@11..12 ":"
            NEW_LINE@12..13 "\n"
          DRAWER_CONTENT@13..47
            PARAGRAPH@13..47
              TEXT@13..47 ":ID:       20220718T0 ..."
          DRAWER_END@47..53
            COLON@47..48 ":"
            TEXT@48..51 "END"
            COLON@51..52 ":"
            NEW_LINE@52..53 "\n"
        KEYWORD@53..81
          HASH_PLUS@53..55 "#+"
          TEXT@55..60 "TITLE"
          COLON@60..61 ":"
          TEXT@61..80 " Complete Computing"
          NEW_LINE@80..81 "\n"
        KEYWORD@81..107
          HASH_PLUS@81..83 "#+"
          TEXT@83..95 "ARCOLOGY_KEY"
          COLON@95..96 ":"
          TEXT@96..106 " cce/index"
          NEW_LINE@106..107 "\n"
        KEYWORD@107..134
          HASH_PLUS@107..109 "#+"
          TEXT@109..129 "ARCOLOGY_ALLOW_CRAWL"
          COLON@129..130 ":"
          TEXT@130..132 " t"
          NEW_LINE@132..133 "\n"
          BLANK_LINE@133..134 "\n"

and org.document().properties() is_none, can you hit me with a cluebat :)

PoiScript commented 3 weeks ago

sorry for the late reply. it seems to be a potential bug where the parser incorrectly interprets a keyword as a property node. it issue was fixed in commit 5bc15d80ffdf11b87cc5344f6c8ad24673551e2c and included in the latest release:

    use orgize::{ast::Document, Org};

    let org = Org::parse(
        r#":PROPERTIES:
:ID:       20220718T085035.042592
:END:
#+TITLE: Complete Computing"#,
    );

    let properties = org.document().properties().unwrap();

    assert_eq!(properties.iter().count(), 1);
    assert_eq!(properties.get("ID").unwrap(), "20220718T085035.042592");
rrix commented 3 weeks ago

cheers @PoiScript , i really appreciate your work on this parser!