百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

orgize

> 开发工具
开源

一个用于解析 org-mode 文件的 Rust 库。

341 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个用于解析 org-mode 文件的 Rust 库。

Orgize

A Rust library for parsing org-mode files.

Live Demo:

Parse

To parse a org-mode string, simply invoking the Org::parse function:

rust
use orgize::{Org, rowan::ast::AstNode};

let org = Org::parse("* DONE Title :tag:");
assert_eq!(
    format!("{:#?}", org.document().syntax()),
    r#"[email protected]
  [email protected]
    [email protected] "*"
    [email protected] " "
    [email protected] "DONE"
    [email protected] " "
    [email protected]
      [email protected] "Title "
    [email protected]
      [email protected] ":"
      [email protected] "tag"
      [email protected] ":"
"#);

use ParseConfig::parse to specific a custom parse config

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");

Traverse

Use org.traverse(&mut traversal) to walk through the syntax tree.

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);

Modify

Use org.replace_range(TextRange::new(start, end), "new_text") to modify the syntax tree:

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!");

Render to html

Call the Org::to_html function to export org element tree to html:

rust
use orgize::Org;

assert_eq!(
    Org::parse("* title\n*section*").to_html(),
    "
title

section
"
);

Checkout examples/html-slugify.rs on how to customizing html export process.

Features

  • chrono: adds the ability to convert Timestamp into chrono::NaiveDateTime, disabled by default.

  • indexmap: adds the ability to convert PropertyDrawer properties into IndexMap, disabled by default.

API compatibility

element.syntax() exposes access to the internal syntax tree, along with some rowan low-level APIs. This can be useful for intricate tasks.

However, the structure of the internal syntax tree can change between different versions of the library. Because of this, the result of element.syntax() doesn't follow semantic versioning, which means updates might break your code if it relies on this method.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustclilsporg-modeparser

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具