Compare plain list item pre blank.

This commit is contained in:
Tom Alexander 2023-09-29 19:30:02 -04:00
parent 7727b5ef47
commit 064a4eeee7
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 26 additions and 2 deletions

View File

@ -53,6 +53,7 @@ use crate::types::PlainLink;
use crate::types::PlainList;
use crate::types::PlainListItem;
use crate::types::PlainListItemCounter;
use crate::types::PlainListItemPreBlank;
use crate::types::PlainListType;
use crate::types::PlainText;
use crate::types::Planning;
@ -887,7 +888,19 @@ fn compare_plain_list_item<'s>(
}
};
// TODO: Compare :pre-blank
// Compare pre-blank
// :pre-blank appears to count the line breaks between "::" and the contents in a descriptive list. Oddly enough it does not count the spaces so I'm not quite sure what the value is.
let pre_blank = get_property_unquoted_atom(emacs, ":pre-blank")?;
let pre_blank: Option<PlainListItemPreBlank> = pre_blank
.map(|val| val.parse())
.map_or(Ok(None), |r| r.map(Some))?;
if pre_blank.unwrap_or(0) != rust.pre_blank {
this_status = DiffStatus::Bad;
message = Some(format!(
"Pre-blank mismatch (emacs != rust) {:?} != {:?}",
pre_blank, rust.pre_blank
));
}
Ok(DiffResult {
status: this_status,

View File

@ -45,6 +45,7 @@ use crate::types::Object;
use crate::types::PlainList;
use crate::types::PlainListItem;
use crate::types::PlainListItemCounter;
use crate::types::PlainListItemPreBlank;
use crate::types::PlainListType;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
@ -220,6 +221,7 @@ fn plain_list_item<'b, 'g, 'r, 's>(
tag: maybe_tag
.map(|(_ws, item_tag)| item_tag)
.unwrap_or(Vec::new()),
pre_blank: 0,
children: Vec::new(),
},
),
@ -227,7 +229,11 @@ fn plain_list_item<'b, 'g, 'r, 's>(
}
Err(_) => {}
};
let (remaining, _ws) = item_tag_post_gap(&parser_context, remaining)?;
let (remaining, pre_blank) = item_tag_post_gap(&parser_context, remaining)?;
let pre_blank = Into::<&str>::into(pre_blank)
.bytes()
.filter(|b| *b == b'\n')
.count();
let (mut remaining, (mut children, _exit_contents)) = many_till(
include_input(parser_with_context!(element(true))(&parser_context)),
@ -266,6 +272,8 @@ fn plain_list_item<'b, 'g, 'r, 's>(
tag: maybe_tag
.map(|(_ws, item_tag)| item_tag)
.unwrap_or(Vec::new()),
pre_blank: PlainListItemPreBlank::try_from(pre_blank)
.expect("pre-blank cannot be larger than 2."),
children: children.into_iter().map(|(_start, item)| item).collect(),
},
),

View File

@ -29,10 +29,12 @@ pub struct PlainListItem<'s> {
pub counter: Option<PlainListItemCounter>,
pub checkbox: Option<(CheckboxType, &'s str)>,
pub tag: Vec<Object<'s>>,
pub pre_blank: PlainListItemPreBlank,
pub children: Vec<Element<'s>>,
}
pub type PlainListItemCounter = u16;
pub type PlainListItemPreBlank = u8;
#[derive(Debug)]
pub enum CheckboxType {

View File

@ -25,6 +25,7 @@ pub use greater_element::NodeProperty;
pub use greater_element::PlainList;
pub use greater_element::PlainListItem;
pub use greater_element::PlainListItemCounter;
pub use greater_element::PlainListItemPreBlank;
pub use greater_element::PlainListType;
pub use greater_element::PropertyDrawer;
pub use greater_element::Table;