### Install orgize Package Source: https://github.com/poiscript/orgize/blob/v0.10/wasm/README.md Instructions for installing the orgize NPM package using either npm or yarn. These commands download and add the package to your project's dependencies. ```sh npm install orgize yarn add orgize ``` -------------------------------- ### Render org content to HTML Source: https://github.com/poiscript/orgize/blob/v0.10/README.md Shows conversion of parsed org content directly to HTML output. The example demonstrates automatic generation of semantic HTML elements from org structure. ```rust use orgize::Org; assert_eq!( Org::parse("* title\n*section*").to_html(), "

title

section

" ); ``` -------------------------------- ### Initialize and Use Orgize in Node.js Source: https://github.com/poiscript/orgize/blob/v0.10/wasm/README.md Illustrates how to use the Orgize WebAssembly module in a Node.js environment. This example shows asynchronous initialization using `initSync` with Wasm bytes read from a file, parsing Org syntax, rendering to HTML, and releasing memory. ```javascript import { Org, initSync } from "orgize"; import { readFile } from "node:fs/promises"; // you can also use import.meta.resolve, but it's currently behind // an experimental flag --experimental-import-meta-resolve import { createRequire } from "node:module"; const require = createRequire(import.meta.url); readFile(require.resolve("orgize/wasm")).then((bytes) => { initSync(bytes); const org = new Org("* Hello, /world/!"); const html = org.html(); console.log(html); org.free(); }); ``` -------------------------------- ### Querying Org-mode Headlines (Rust) Source: https://context7.com/poiscript/orgize/llms.txt Provides examples of querying headline properties such as level, TODO status, priority, and tags from a parsed org-mode document. It demonstrates using `Headline` AST node methods to extract this information. ```rust use orgize::{Org, ast::{Headline, TodoType}}; let org = Org::parse(r#"\n* TODO [#A] First task :work:urgent:\n** DONE [#B] Completed subtask :home:\n*** Third level :tag:"#); // Get first headline let hdl = org.first_node::().unwrap(); // Check headline properties assert_eq!(hdl.level(), 1); assert_eq!(hdl.todo_keyword().unwrap().to_string(), "TODO"); assert_eq!(hdl.todo_type().unwrap(), TodoType::Todo); assert!(hdl.is_todo()); assert_eq!(hdl.priority().unwrap().to_string(), "A"); // Extract tags let tags: Vec = hdl.tags().map(|t| t.to_string()).collect(); assert_eq!(tags, vec!["work", "urgent"]); // Get title assert_eq!(hdl.title_raw(), "First task "); ``` -------------------------------- ### Check Org Headline States (Comment, Archive, Todo/Done) Source: https://context7.com/poiscript/orgize/llms.txt Provides examples of checking various states of org-mode headlines using Rust. It covers detecting if a headline is commented (`* COMMENT`), archived (`:ARCHIVE:`), or has a TODO/DONE status. This is useful for programmatic analysis of org files. ```rust use orgize::{Org, ast::Headline}; // Check for COMMENT keyword let hdl = Org::parse("* COMMENT hello").first_node::().unwrap(); assert!(hdl.is_commented()); let hdl = Org::parse("* hello").first_node::().unwrap(); assert!(!hdl.is_commented()); // Check for ARCHIVE tag let hdl = Org::parse("* hello :ARCHIVE:").first_node::().unwrap(); assert!(hdl.is_archived()); let hdl = Org::parse("* hello :ARCHIVED:").first_node::().unwrap(); assert!(!hdl.is_archived()); // Check TODO/DONE state let hdl = Org::parse("* TODO task").first_node::().unwrap(); assert!(hdl.is_todo()); assert!(!hdl.is_done()); let hdl = Org::parse("* DONE task").first_node::().unwrap(); assert!(!hdl.is_todo()); assert!(hdl.is_done()); ``` -------------------------------- ### Initialize and Use Orgize in Browser Source: https://github.com/poiscript/orgize/blob/v0.10/wasm/README.md Demonstrates how to initialize and use the Orgize WebAssembly module in a browser environment. It shows importing the Org class, initializing the module, creating an Org object, rendering it to HTML, and freeing allocated memory. ```javascript import init, { Org } from "orgize"; init().then(() => { const org = new Org("* Hello, /world/!"); const html = org.html(); console.log(html); org.free(); }); ``` -------------------------------- ### Parse with custom configuration Source: https://github.com/poiscript/orgize/blob/v0.10/README.md Shows how to parse an org-mode string with custom TODO keywords using ParseConfig. This allows customization of parsing behavior beyond defaults. ```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"); ``` -------------------------------- ### Parse Org-mode Content to Syntax Tree (Rust) Source: https://context7.com/poiscript/orgize/llms.txt Demonstrates basic parsing of org-mode content into a detailed syntax tree using the Org::parse function. This preserves all structural and formatting information, including whitespace, and is useful for analysis. Dependencies include the 'orgize' crate. ```rust use orgize::{Org, rowan::ast::AstNode}; // Parse org-mode content let org = Org::parse("* DONE Title :tag:"); // Access the syntax tree 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 ":" "# ); ``` -------------------------------- ### Traverse syntax tree nodes Source: https://github.com/poiscript/orgize/blob/v0.10/README.md Illustrates traversal of the parsed syntax tree to count headlines. Uses a custom event handler to increment a counter when entering headline nodes. ```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); ``` -------------------------------- ### Parse org-mode string using Org::parse Source: https://github.com/poiscript/orgize/blob/v0.10/README.md Demonstrates how to parse an org-mode string into a syntax tree using the Org::parse function. This basic usage shows parsing a headline with a tag. ```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 ":" "#); ``` -------------------------------- ### Traversing Org-mode Syntax Tree (Rust) Source: https://context7.com/poiscript/orgize/llms.txt Demonstrates traversing the org-mode syntax tree using a custom handler function. The `traverse` method accepts an `Event` handler that can process `Enter` and `Exit` events for different containers, like `Headline`, to perform actions like counting nodes. ```rust use orgize::{ export::{from_fn, Container, Event}, Org, }; let mut hdl_count = 0; // Create handler that counts headlines let mut handler = from_fn(|event| { if matches!(event, Event::Enter(Container::Headline(_))) { hdl_count += 1; } }); // Traverse document Org::parse("* 1\n** 2\n*** 3\n**** 4").traverse(&mut handler); assert_eq!(hdl_count, 4); ``` -------------------------------- ### Access Org Headline Planning Information (Scheduled, Deadline, Closed) Source: https://context7.com/poiscript/orgize/llms.txt Demonstrates how to extract planning timestamps like SCHEDULED, DEADLINE, and CLOSED from org-mode headlines using Rust. This allows for date-based processing and analysis of tasks. It returns `Option` for each type. ```rust use orgize::{Org, ast::Headline}; let org = Org::parse(r###" * TODO Task SCHEDULED: <2024-01-15 Mon> DEADLINE: <2024-01-20 Sat> "###); let hdl = org.first_node::().unwrap(); // Access planning timestamps if let Some(scheduled) = hdl.scheduled() { // Process scheduled timestamp } if let Some(deadline) = hdl.deadline() { // Process deadline timestamp } // For completed tasks let org = Org::parse(r###" * DONE Completed Task CLOSED: [2024-01-18 Thu] "###); let hdl = org.first_node::().unwrap(); if let Some(closed) = hdl.closed() { // Process closed timestamp } ``` -------------------------------- ### Custom Org-mode Parse Configuration (Rust) Source: https://context7.com/poiscript/orgize/llms.txt Shows how to customize org-mode parsing using `ParseConfig` to define custom TODO keywords (e.g., 'TASK', 'COMPLETED') and other options like subscript/superscript handling. The parsed output can be accessed via AST nodes like `Headline`. ```rust use orgize::{Org, ParseConfig, ast::Headline}; // Create custom configuration let config = ParseConfig { todo_keywords: (vec!["TASK".to_string()], vec!["COMPLETED".to_string()]), use_sub_superscript: orgize::config::UseSubSuperscript::Brace, ..Default::default() }; // Parse with custom config let org = config.parse("* TASK Title 1\n** COMPLETED Title 2"); // Access parsed elements let hdl = org.first_node::().unwrap(); assert_eq!(hdl.todo_keyword().unwrap().to_string(), "TASK"); assert_eq!(hdl.level(), 1); assert_eq!(hdl.title_raw(), "Title 1"); ``` -------------------------------- ### Custom Org to HTML Export with Slugified Anchors Source: https://context7.com/poiscript/orgize/llms.txt Demonstrates a custom HTML export process in Rust that adds IDs and anchor links to headings. This allows for direct linking to specific sections within the generated HTML. It requires custom handler logic to modify the default export behavior. ```rust use orgize::{ export::HtmlExport, export::{from_fn_with_ctx, Container, Event}, Org, }; use std::cmp::min; // Custom slugify function (simplified) fn slugify(s: &str) -> String { s.to_lowercase().replace(' ', "-") } let org = Org::parse("* Hello World\n** Another Section"); let mut html_export = HtmlExport::default(); // Create custom handler let mut handler = from_fn_with_ctx(|event, ctx| { if let Event::Enter(Container::Headline(headline)) = event { let level = min(headline.level(), 6); let title = headline.title().map(|e| e.to_string()).collect::(); let slug = slugify(&title); // Custom heading with anchor html_export.push_str(format!( "" )); for elem in headline.title() { html_export.element(elem, ctx); } html_export.push_str(format!("")); } else { // Forward other events to default handler html_export.event(event, ctx); } }); org.traverse(&mut handler); let result = html_export.finish(); // Produces:

Hello World

... ``` -------------------------------- ### Finding Org-mode Nodes by Position (Rust) Source: https://context7.com/poiscript/orgize/llms.txt Illustrates how to locate specific Abstract Syntax Tree (AST) nodes, like `Headline`, within an org-mode document based on their text offset. This is useful for navigation and precise editing, returning `None` for invalid offsets. ```rust use orgize::{Org, ast::Headline}; let org = Org::parse("\n\n* foo\n* bar"); // No headline at offset 0 assert!(org.node_at_offset::(0).is_none()); // Find headline at offset 2 (start of first headline) let hdl = org.node_at_offset::(2).unwrap(); assert_eq!(hdl.title_raw(), "foo"); // Find headline at offset 9 (second headline) let hdl = org.node_at_offset::(9).unwrap(); assert_eq!(hdl.title_raw(), "bar"); // Out of bounds returns None assert!(org.node_at_offset::(999).is_none()); ``` -------------------------------- ### Export Org to HTML with Default Handler Source: https://context7.com/poiscript/orgize/llms.txt Converts org-mode content to HTML using the default export handler. This is suitable for basic HTML generation without custom formatting. It takes org-mode text as input and outputs a string containing the HTML representation. ```rust use orgize::Org; // Simple HTML export let html = Org::parse("* title\n*section*").to_html(); assert_eq!( html, "

title

section

" ); // More complex example let org_content = r###" * Introduction This is a paragraph with *bold* and /italic/ text. ** Subheading - First item - Second item "###; let html = Org::parse(org_content).to_html(); // Produces structured HTML with proper heading hierarchy and list formatting ``` -------------------------------- ### Parse Org-mode document and extract TODO items using Rust Orgize Source: https://context7.com/poiscript/orgize/llms.txt This snippet configures Orgize's parser with custom TODO keywords, parses an org-mode string, traverses the syntax tree to collect headlines, filters active TODO entries, and finally exports the document to HTML. It requires the orgize crate and its dependencies. The output includes a vector of active task titles and an HTML representation of the original org content. ```Rust use orgize::{Org, ast::Headline, ParseConfig}; // Step 1: Configure parser let config = ParseConfig { todo_keywords: ( vec!["TODO".to_string(), "IN_PROGRESS".to_string()], vec!["DONE".to_string(), "CANCELLED".to_string()] ), ..Default::default() }; // Step 2: Parse document let org_content = r#" * TODO Project Alpha :work: ** IN_PROGRESS Feature A** DONE Feature B ** CANCELLED Feature C * DONE Project Beta :personal: "#; let org = config.parse(org_content); // Step 3: Analyze structure let headlines: Vec = { let mut headlines = vec![]; let doc = org.document(); fn collect(node: orgize::SyntaxNode, headlines: &mut Vec) { use rowan::ast::AstNode; if let Some(hdl) = Headline::cast(node.clone()) { headlines.push(hdl); } for child in node.children() { collect(child, headlines); } } collect(doc.syntax, &mut headlines); headlines }; // Step 4: Filter and process let active_tasks: Vec<_> = headlines.iter() .filter(|h| h.is_todo()) .map(|h| h.title_raw()) .collect(); // Step 5: Export to HTML let html = org.to_html(); // Generates complete HTML document ``` -------------------------------- ### Render Math Expressions with JavaScript Source: https://github.com/poiscript/orgize/blob/v0.10/wasm/index.html This code snippet shows how to render mathematical expressions dynamically. It includes handling for subscripts, superscripts, and line breaks. The editor session listens for changes to update the rendering. ```JavaScript editor.session.on("change", () => render()); render(); }); ``` -------------------------------- ### Working with Org Clock Entries Source: https://context7.com/poiscript/orgize/llms.txt Shows how to extract clock entries from LOGBOOK drawers within org-mode headlines using Rust. This functionality is useful for time tracking and analysis. The code parses a headline with clock entries and collects them into a vector. ```rust use orgize::{Org, ast::Headline}; let org = Org::parse(r###"* TODO Task :LOGBOOK: CLOCK: [2024-10-12 Sat 09:00]--[2024-10-12 Sat 10:30] CLOCK: [2024-10-12 Sat 14:00]--[2024-10-12 Sat 15:15] :END: "###); let hdl = org.first_node::().unwrap(); let clocks: Vec<_> = hdl.clocks().collect(); assert_eq!(clocks.len(), 2); // Process clock entries for time tracking ``` -------------------------------- ### Modify syntax tree content Source: https://github.com/poiscript/orgize/blob/v0.10/README.md Demonstrates modification of the syntax tree by replacing node ranges with new content. Shows changing headline text and removing preceding content. ```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!"); ``` -------------------------------- ### Export Org to Markdown Source: https://context7.com/poiscript/orgize/llms.txt Converts org-mode documents into Markdown format using the `MarkdownExport` handler. This is useful for interoperability with other Markdown-based systems. The input is org-mode text, and the output is a Markdown string. ```rust use orgize::{export::MarkdownExport, Org}; let content = r###" * Main Heading ** Subheading This is a paragraph with *bold* and /italic/. - Item 1 - Item 2 "###; let mut export = MarkdownExport::default(); Org::parse(content).traverse(&mut export); let markdown = export.finish(); // Produces Markdown with proper heading levels, formatting, and lists ``` -------------------------------- ### Parsing Org Inline Title Elements Source: https://context7.com/poiscript/orgize/llms.txt Illustrates how to parse and access inline elements (like bold, italic, tags) within org-mode headline titles using Rust. This allows for fine-grained control over how parts of a headline are processed or displayed. It demonstrates iterating over title elements and checking their syntax kind. ```rust use orgize::{Org, ast::Headline, SyntaxKind}; let hdl = Org::parse("*** abc *bold* /italic/ :tag:") .first_node::() .unwrap(); let title: Vec<_> = hdl.title().collect(); // title[0] is "abc " assert_eq!(title[1].kind(), SyntaxKind::BOLD); assert_eq!(title[1].to_string(), "*bold*"); assert_eq!(title[3].kind(), SyntaxKind::ITALIC); assert_eq!(title[3].to_string(), "/italic/"); ``` -------------------------------- ### Modifying Org-mode Syntax Tree (Rust) Source: https://context7.com/poiscript/orgize/llms.txt Explains how to modify the org-mode syntax tree in place using `replace_range`. This method automatically re-parses affected parts of the tree, allowing for dynamic updates to content like headline levels and text, and subsequent re-querying of the modified structure. ```rust use orgize::{Org, ast::Headline, TextRange, TextSize}; let mut org = Org::parse("hello\n* world"); // Get initial headline let hdl = org.first_node::().unwrap(); assert_eq!(hdl.level(), 1); // Replace headline stars org.replace_range(hdl.text_range(), "** WORLD!"); // Query again after modification let hdl = org.first_node::().unwrap(); assert_eq!(hdl.level(), 2); assert_eq!(hdl.title_raw(), "WORLD!"); // Remove content before headline 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.