### Parse Org-mode String with Orgize Source: https://crates.io/crates/orgize/0.10.0-alpha.10/index Demonstrates how to parse a basic org-mode string into a document structure using the `Org::parse` function. It shows an example of asserting the formatted syntax tree of the parsed document, highlighting the structure of headlines and tags. ```rust use orgize::{Org, rowan::ast::AstNode}; let org = Org::parse("* DONE Title :tag:"); assert_eq!( format!("{:#?}", org.document().syntax()), r#"DOCUMENT@0..18 HEADLINE@0..18 HEADLINE_STARS@0..1 "*" WHITESPACE@1..2 " " HEADLINE_KEYWORD_DONE@2..6 "DONE" WHITESPACE@6..7 " " HEADLINE_TITLE@7..13 TEXT@7..13 "Title " HEADLINE_TAGS@13..18 COLON@13..14 ":" TEXT@14..17 "tag" COLON@17..18 ":" "# ); ``` -------------------------------- ### Render Org-mode to HTML Source: https://crates.io/crates/orgize/0.10.0-alpha.10/index Shows how to convert an org-mode element tree into an HTML string using the `Org::to_html` function. The example provides a simple org-mode input with a title and a section containing bold text, and asserts the expected HTML output. ```rust use orgize::Org; assert_eq!( Org::parse("* title\n*section*").to_html(), "

title

section

" ); ``` -------------------------------- ### Traverse Org-mode Syntax Tree Source: https://crates.io/crates/orgize/0.10.0-alpha.10/index Explains how to traverse the syntax tree of an org-mode document using the `traverse` method. This example counts the number of headlines encountered during the traversal by using a custom handler function that increments a counter when entering a headline container. ```rust use orgize::{ export::{from_fn, Container, Event}, Org, }; let mut hdl_count = 0; let mut handler = from_fn(|event| { if matches!(event, Event::Enter(Container::Headline(_))) { hdl_count += 1; } }); Org::parse("* 1\n** 2\n*** 3\n****4").traverse(&mut handler); assert_eq!(hdl_count, 3); ``` -------------------------------- ### Custom Org-mode Parsing with ParseConfig Source: https://crates.io/crates/orgize/0.10.0-alpha.10/index Illustrates how to customize the parsing behavior of org-mode files using `ParseConfig`. This example shows how to define custom 'todo' keywords, such as 'TASK', and then use these custom keywords during parsing. It verifies that the custom keyword is correctly identified in the parsed headline. ```rust use orgize::{Org, ParseConfig, ast::Headline}; let config = ParseConfig { // custom todo keywords todo_keywords: (vec!["TASK".to_string()], vec![]), ..Default::default() }; let org = config.parse("* TASK Title 1"); let hdl = org.first_node::().unwrap(); assert_eq!(hdl.todo_keyword().unwrap(), "TASK"); ``` -------------------------------- ### Modify Org-mode Syntax Tree with Replace Range Source: https://crates.io/crates/orgize/0.10.0-alpha.10/index Demonstrates how to modify the org-mode syntax tree in place using the `replace_range` method. This example shows replacing the text of a headline, changing its level, and then removing text before the headline. It asserts the resulting org-mode string after modifications. ```rust use orgize::{Org, ParseConfig, ast::Headline, TextRange}; let mut org = Org::parse("hello\n* world"); let hdl = org.first_node::().unwrap(); org.replace_range(hdl.text_range(), "** WORLD!"); let hdl = org.first_node::().unwrap(); assert_eq!(hdl.level(), 2); org.replace_range(TextRange::up_to(hdl.start()), ""); assert_eq!(org.to_org(), "** WORLD!"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.