Mercurial > core / rust/lib/obj/src/object/doc/org.rs
changeset 698: |
96958d3eb5b0 |
parent: |
c7165d93a9eb
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
3 //! Org-mode object types 5 //! The Org-mode format is particularly difficult to parse, but can be 6 //! done. The best resources for learning how to create a parser for 7 //! Org is available in the Org-Element API docs. 10 //! The `Org` type is the main type used for accessing Org Docs. This 11 //! object includes builder functions for the `OrgParser` type, which 12 //! handles parsing of the Org-mode format. 14 //! This module does not intend to fully support the Org-mode format, 15 //! and is not a replacement for existing org files. 18 //! - [parse org-mode in elisp](http://ergoemacs.org/emacs/elisp_parse_org_mode.html) 19 //! - [Using the Mapping API](https://orgmode.org/manual/Using-the-Mapping-API.html) 20 //! - [Using the Property API](https://orgmode.org/manual/Using-the-Property-API.html) 21 //! - [Org-element API](https://orgmode.org/worg/dev/org-element-api.html) 22 //! - [Orgnode.py](http://members.optusnet.com.au/~charles57/GTD/Orgnode.py) 23 use crate::{object::meta::Property, Objective, Result}; 26 use logger::log::info; 31 path::{Path, PathBuf}, 34 use serde::{Deserialize, Serialize}; 37 #[derive(Serialize, Deserialize, Debug)] 39 pub properties: Option<Vec<Property>>, 40 pub contents: HashMap<Id, String>, 44 /// Create a new Org object 45 pub fn new() -> Self { 48 contents: HashMap::new(), 51 /// Create a new Org object from an Org-mode file 52 pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> { 53 let content = String::from_utf8(fs::read(PathBuf::from(path.as_ref()))?) 54 .expect("failed to read utf8 string"); 55 let mut org = Org::new(); 56 org.contents.insert(Id::rand(), content); 57 info!("parsed org-file: {}", path.as_ref().display()); 62 /// Append structured data to this Org document 63 pub fn append(self, input: String) -> Result<Self> { 65 doc.contents.insert(Id::rand(), input); 70 /// Return document content 71 pub fn contents(self) -> HashMap<Id, String> { 76 impl Objective for Org {}