-- | Convert an AlBhed Index database to a prettyprinter `Doc` type
toDoc :: AlBhed.Index.Index -> Doc ()
toDoc = vsep . map indexItemToDoc
where
indexItemToDoc :: IndexItem -> Doc ()
indexItemToDoc (IndexItem (primer, locations)) =
primerToDoc primer <> line
<> align (indent 2 . vsep $ locationToDoc <$> NonEmptyList.toList locations)
primerToDoc :: Primer -> Doc ()
primerToDoc primer =
"Primer" <+> pretty (toRoman $ primer ^. volume) <+> squotes (pretty $ primer ^. alBhed)
<+> "->" <+> squotes (pretty $ primer ^. english)
locationToDoc :: Location -> Doc ()
locationToDoc loc = (pretty . PrintableText.unPrintableText $ loc ^. area)
<+> maybe emptyDoc (("-" <+>) . pretty . PrintableText.unPrintableText) (loc ^. section)