diff --git a/default_environment/templates/html/footnote_reference.dust b/default_environment/templates/html/footnote_reference.dust
index ae1f616..a218064 100644
--- a/default_environment/templates/html/footnote_reference.dust
+++ b/default_environment/templates/html/footnote_reference.dust
@@ -1 +1 @@
-!!!!!!!! footnote_reference
+{.label}
diff --git a/org_test_documents/footnote_definitions.org b/org_test_documents/footnote_definitions.org
new file mode 100644
index 0000000..8a15e71
--- /dev/null
+++ b/org_test_documents/footnote_definitions.org
@@ -0,0 +1,25 @@
+# Test proves that:
+#
+# - Anonymous references with identical content get unique IDs.
+# - Unreferenced footnote definitions are dropped.
+# - Footnote definitions that come before their first reference are dropped.
+
+foo[fn:2:something]
+
+bar[fn::something]
+
+baz[fn::something]
+
+cat[fn::something]
+
+dog[fn:3]
+
+[fn:3] ipsum
+
+[fn:4] lorem
+
+[fn:3] dolar
+
+[fn:5] not referenced
+
+stuff[fn:4] and things
diff --git a/src/intermediate/footnote_reference.rs b/src/intermediate/footnote_reference.rs
index cb393c2..b660a9c 100644
--- a/src/intermediate/footnote_reference.rs
+++ b/src/intermediate/footnote_reference.rs
@@ -3,13 +3,16 @@ use crate::error::CustomError;
use super::registry::Registry;
#[derive(Debug)]
-pub(crate) struct IFootnoteReference {}
+pub(crate) struct IFootnoteReference {
+ footnote_id: usize,
+}
impl IFootnoteReference {
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
original: &organic::types::FootnoteReference<'parse>,
) -> Result {
- Ok(IFootnoteReference {})
+ let footnote_id = registry.get_footnote_reference_id(original.label, &original.definition);
+ Ok(IFootnoteReference { footnote_id })
}
}
diff --git a/src/intermediate/registry.rs b/src/intermediate/registry.rs
index d53e2ba..b7988d2 100644
--- a/src/intermediate/registry.rs
+++ b/src/intermediate/registry.rs
@@ -1,10 +1,13 @@
use std::collections::HashMap;
+use organic::types::Object;
+
type IdCounter = u16;
-pub(crate) struct Registry<'parse> {
+pub(crate) struct Registry<'intermediate, 'parse> {
id_counter: IdCounter,
targets: HashMap<&'parse str, String>,
+ footnote_ids: Vec<(Option<&'parse str>, &Vec