Index: trunk/cli/conversion.ml
===================================================================
--- trunk/cli/conversion.ml	(revision 38)
+++ trunk/cli/conversion.ml	(revision 39)
@@ -1,3 +1,7 @@
 open Logarion
+
+module Ref_set = Set.Make(String)
+module Id_map = Map.Make(String)
+
 type t = {
 	id: string;
@@ -6,4 +10,5 @@
 	topic_roots: string list;
 	topics: (String_set.t * String_set.t) Topic_set.Map.t;
+	references: Ref_set.t Id_map.t;
 	texts: Text.t list
 }
@@ -20,4 +25,5 @@
 	topic_roots = [];
 	topics = Topic_set.Map.empty;
+	references = Id_map.empty;
 	texts = []
 }
Index: trunk/cli/convert.ml
===================================================================
--- trunk/cli/convert.ml	(revision 38)
+++ trunk/cli/convert.ml	(revision 39)
@@ -27,13 +27,23 @@
 	t
 
+let acc_ref id t a =
+	Conversion.Id_map.update t (function
+	| Some s -> Some (Conversion.Ref_set.add id s)
+	| None -> Some (Conversion.Ref_set.singleton id)
+	) a
+
+let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
+
 let directory converters noindex repo =
-	let fn (ts,ls,acc) ((elt,_) as r) =
-		(Topic_set.to_map ts (Text.set "topics" elt)), elt::ls,
+	let fn (ts,refs,ls,acc) ((elt,_) as r) =
+		Topic_set.to_map ts (Text.set "topics" elt),
+		fold_refs elt refs,
+		elt::ls,
 		if convert converters repo r then acc+1 else acc in
-	let topics, texts, count =
-		File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty,[],0)) in
+	let topics, references, texts, count =
+		File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty, Conversion.Id_map.empty, [], 0)) in
 	let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv)
 		with Not_found -> Topic_set.roots topics in
-	let repo = Conversion.{ repo with topic_roots; topics; texts } in
+	let repo = Conversion.{ repo with topic_roots; topics; references; texts } in
 	if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
 	Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
@@ -63,5 +73,11 @@
 			| Error s -> prerr_endline s
 			| Ok text ->
-				let repo = { (Conversion.empty ()) with dir = ""; kv = load_kv "" } in
+				let dir = "." in
+				let references = File_store.(fold ~dir ~order:newest
+					(fun refs (elt, _) -> fold_refs elt refs) Conversion.Id_map.empty) in
+					Conversion.Id_map.iter
+						(fun k v -> Conversion.Ref_set.iter (fun e -> Printf.eprintf "%s %s\n" k e) v)
+						references;
+				let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references } in
 				ignore @@ convert (converters types repo.kv) repo (text, [path])
 		)
Index: trunk/cli/html.ml
===================================================================
--- trunk/cli/html.ml	(revision 38)
+++ trunk/cli/html.ml	(revision 39)
@@ -26,5 +26,5 @@
 		with Not_found -> if Sys.file_exists (Filename.concat conv.Conversion.dir "feed.atom")
 			then "feed.atom" else "" in
-	let header = match htm.templates.header with 
+	let header = match htm.templates.header with
 		| Some x -> replace x
 		| None -> Printf.(sprintf "<header><a href='.'>%s</a>%s</header>" site_title
@@ -47,4 +47,5 @@
 module HtmlConverter = struct
 	include Converter.Html
+	let uid_uri u a = Printf.sprintf "%s<a href='%s%s'>%s</a>" a u ext u
 	let angled_uri u a =
 		if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false
@@ -70,5 +71,5 @@
 			String_set.fold to_linked x "" in
 		let ref_links x =
-			let link l = HtmlConverter.angled_uri (String.(sub l 1 (length l-2))) "" in
+			let link l = HtmlConverter.uid_uri l "" in
 			String_set.fold (fun r a -> sep_append a (link r)) x ""
 		in
@@ -80,5 +81,8 @@
 		^ opt_kv "Topics:" (topic_links (set "topics" text))
 		^ opt_kv "Id:" text.id
-		^ opt_kv "References:" (ref_links (set "references" text))
+		^ opt_kv "Refers:" (ref_links (set "references" text))
+		^ opt_kv "Referred by:" (try
+				ref_links (Conversion.Id_map.find text.id conversion.Conversion.references)
+				with Not_found -> "")
 		^ {|</dl></header><pre style="white-space:pre-wrap">|} in
 	wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
