PoiScript / orgize

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

Support alternative notations for subscript/superscript #81

Closed rogueai closed 3 weeks ago

rogueai commented 4 weeks ago

Hi, first of all thanks for your library, it's definitely one of the most comprehensive parsers for org, and the ast traverser makes it extremely easy to write custom exporters!

I have a question about subscripts and superscripts: in my org config I've set the subscripts to only accept the {} notation with:

(setq org-use-sub-superscripts '{})

that means only a_{b} will be exported as subscript and not a_b, and the same applies for superscripts.

Is there a way to configure orgize to do the same, or is it something that would need to be implemented on your side?

Thanks!

PoiScript commented 3 weeks ago

hello, I just published v0.10.0-alpha.10 to crates.io. This version adds control over sub/superscript parsing via the use_sub_superscript field in ParseConfig:

use orgize::{config::UseSubSuperscript, Org, ParseConfig};

let org = ParseConfig {
    use_sub_superscript: UseSubSuperscript::Brace,
    ..Default::default()
}
.parse("a_b, a_{b}");

assert_eq!(
    org.to_html(),
    "<main><section><p>a_b, a<sub>b</sub></p></section></main>"
);

let org = ParseConfig {
    use_sub_superscript: UseSubSuperscript::Nil,
    ..Default::default()
}
.parse("a_b, a_{b}");

assert_eq!(
    org.to_html(),
    "<main><section><p>a_b, a_{b}</p></section></main>"
);