feat(core): make checkbox lexing honor a configurable listsyms palette
Add a ListSyms type (vimwiki's g:vimwiki_listsyms) and thread it through the lexer so checkbox glyphs are recognized from the configured palette rather than the hardcoded ' .oOX'. Glyphs map to the existing five-bucket CheckboxState, so the HTML renderer and AST consumers are unchanged. VimwikiSyntax::parse_with_listsyms opts into a custom palette; the trait parse() keeps the default. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -309,6 +309,45 @@ fn checkbox_states() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checkbox_states_honor_custom_palette() {
|
||||
use nuwiki_core::listsyms::ListSyms;
|
||||
|
||||
let lex_with = |text: &str, syms: ListSyms| -> Vec<VimwikiTokenKind> {
|
||||
VimwikiLexer::new()
|
||||
.with_listsyms(syms)
|
||||
.lex(text)
|
||||
.into_iter()
|
||||
.map(|t| t.kind)
|
||||
.collect()
|
||||
};
|
||||
|
||||
// 3-glyph palette ` x✓`: empty / half / done, plus the fixed rejected `-`.
|
||||
let syms = ListSyms::new(" x✓");
|
||||
let cases: &[(&str, CheckboxState)] = &[
|
||||
("- [ ] a\n", CheckboxState::Empty),
|
||||
("- [x] a\n", CheckboxState::Half),
|
||||
("- [✓] a\n", CheckboxState::Done),
|
||||
("- [-] a\n", CheckboxState::Rejected),
|
||||
];
|
||||
for (line, expected) in cases {
|
||||
let lexed = lex_with(line, syms.clone());
|
||||
assert!(
|
||||
matches!(lexed[1], Checkbox(s) if s == *expected),
|
||||
"input {line:?} expected {expected:?}, got {:?}",
|
||||
lexed[1]
|
||||
);
|
||||
}
|
||||
|
||||
// Default-palette glyphs are not checkboxes under this palette: `[o]`
|
||||
// is plain inline text, so no Checkbox token is emitted.
|
||||
let lexed = lex_with("- [o] a\n", syms);
|
||||
assert!(
|
||||
!lexed.iter().any(|k| matches!(k, Checkbox(_))),
|
||||
"expected no checkbox token, got {lexed:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// ===== Blockquotes =====
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user