Skip to content

Commit dfa1a8a

Browse files
committed
feat: permit customisation of tag characters
Org-mode frontends such as [Orgzly](https://www.orgzly.com/) are more lenient in their tag parsing, this allows us to parse org-mode files generated by such frontends.
1 parent 5f26c94 commit dfa1a8a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ pub struct ParseConfig {
4545
///
4646
/// Equivalent to [`org-element-affiliated-keywords`](https://git.sr.ht/~bzg/org-mode/tree/6f960f3c6a4dfe137fbd33fef9f7dadfd229600c/item/lisp/org-element.el#L331)
4747
pub affiliated_keywords: Vec<String>,
48+
49+
/// Control tag parsing
50+
///
51+
/// Defaults to org-mode's permitted characters: alphanumeric and `_@#%`.
52+
pub is_tag_char: fn(char) -> bool,
4853
}
4954

5055
impl ParseConfig {
@@ -82,6 +87,7 @@ impl Default for ParseConfig {
8287
"SRCNAME".into(),
8388
"TBLNAME".into(),
8489
],
90+
is_tag_char: |c| c.is_alphanumeric() || c == '_' || c == '@' || c == '#' || c == '%',
8591
}
8692
}
8793
}

src/syntax/headline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn headline_tags_node(input: Input) -> IResult<Input, GreenElement, ()> {
173173
} else if String::from_utf8_lossy(item)
174174
.chars()
175175
// https://github.com/yyr/org-mode/blob/d8494b5668ad4d4e68e83228ae8451eaa01d2220/lisp/org-element.el#L922C25-L922C32
176-
.all(|c| c.is_alphanumeric() || c == '_' || c == '@' || c == '#' || c == '%')
176+
.all(input.c.is_tag_char)
177177
{
178178
children.push(input.slice(ii + 1..i).text_token());
179179
children.push(token(COLON, ":"));

0 commit comments

Comments
 (0)