Add support for target links.
All checks were successful
format Build format has succeeded
build-natter Build build-natter has succeeded
rust-clippy Build rust-clippy has succeeded
rust-test Build rust-test has succeeded

This commit is contained in:
Tom Alexander
2023-12-23 22:12:05 -05:00
parent d2ea6b6a0f
commit 59a91331cc
3 changed files with 58 additions and 34 deletions

View File

@@ -14,7 +14,7 @@ type IdCounter = u16;
#[derive(Debug)]
pub(crate) struct Registry<'orig, 'parse> {
id_counter: IdCounter,
targets: HashMap<&'parse str, String>,
targets: HashMap<String, String>,
footnote_ids: Vec<(Option<&'parse str>, Vec<IAstNode>)>,
footnote_reference_counts: HashMap<&'parse str, usize>,
on_deck_footnote_ids: HashMap<&'parse str, &'orig Vec<Element<'parse>>>,
@@ -31,8 +31,8 @@ impl<'orig, 'parse> Registry<'orig, 'parse> {
}
}
pub(crate) fn get_target<'reg>(&'reg mut self, body: &'parse str) -> &'reg String {
self.targets.entry(body).or_insert_with(|| {
pub(crate) fn get_target<S: Into<String>>(&mut self, body: S) -> &String {
self.targets.entry(body.into()).or_insert_with(|| {
self.id_counter += 1;
format!("target_{}", self.id_counter)
})