Remove category from global settings.
Some checks failed
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded
rust-foreign-document-test Build rust-foreign-document-test has failed

This setting does not impact parsing so we can iterate over the final document to find the keywords.
This commit is contained in:
Tom Alexander 2023-09-30 14:35:22 -04:00
parent d38b0a84f6
commit 186201a4b5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 17 additions and 13 deletions

View File

@ -12,8 +12,6 @@ pub struct GlobalSettings<'g, 's> {
pub radio_targets: Vec<&'g Vec<Object<'s>>>,
pub file_access: &'g dyn FileAccessInterface,
pub in_progress_todo_keywords: BTreeSet<String>,
pub category: Option<String>,
pub complete_todo_keywords: BTreeSet<String>,
/// Set to true to allow for plain lists using single letters as the bullet in the same way that numbers are used.
///
@ -41,7 +39,6 @@ impl<'g, 's> GlobalSettings<'g, 's> {
working_directory: None,
},
in_progress_todo_keywords: BTreeSet::new(),
category: None,
complete_todo_keywords: BTreeSet::new(),
list_allow_alphabetical: false,
tab_width: DEFAULT_TAB_WIDTH,

View File

@ -149,7 +149,7 @@ fn document_org_source<'b, 'g, 'r, 's>(
let new_context = context.with_global_settings(&new_settings);
let context = &new_context;
let (remaining, document) =
let (remaining, mut document) =
_document(context, input).map(|(rem, out)| (Into::<&str>::into(rem), out))?;
{
// If there are radio targets in this document then we need to parse the entire document again with the knowledge of the radio targets.
@ -173,6 +173,21 @@ fn document_org_source<'b, 'g, 'r, 's>(
return Ok((remaining.into(), document));
}
}
// Find final in-buffer settings that do not impact parsing
document.category = Into::<AstNode>::into(&document)
.into_iter()
.filter_map(|ast_node| {
if let AstNode::Keyword(ast_node) = ast_node {
if ast_node.key.eq_ignore_ascii_case("category") {
return Some(ast_node);
}
}
None
})
.last()
.map(|kw| kw.value.to_owned());
Ok((remaining.into(), document))
}
@ -191,7 +206,7 @@ fn _document<'b, 'g, 'r, 's>(
remaining,
Document {
source: source.into(),
category: context.get_global_settings().category.clone(),
category: None,
path: None,
zeroth_section,
children,

View File

@ -111,14 +111,6 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>(
}
}
// Category
for kw in keywords
.iter()
.filter(|kw| kw.key.eq_ignore_ascii_case("category"))
{
new_settings.category = Some(kw.value.to_owned());
}
Ok(new_settings)
}