summaryrefslogtreecommitdiffstats
path: root/src/Zettel/Bibliography.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Zettel/Bibliography.hs')
-rw-r--r--src/Zettel/Bibliography.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Zettel/Bibliography.hs b/src/Zettel/Bibliography.hs
new file mode 100644
index 0000000..6186917
--- /dev/null
+++ b/src/Zettel/Bibliography.hs
@@ -0,0 +1,25 @@
+{-# LANGUAGE OverloadedRecordDot #-}
+
+module Zettel.Bibliography where
+
+import Text.Pandoc.Definition (Citation (..), Inline (..), Target (..))
+import Text.Pandoc.Walk (walk)
+import Zettel.Types
+
+replaceCitation :: Citation -> ([Inline], Target)
+replaceCitation c =
+ ([Str $ "@" <> zid], ("/bib/" <> zid, ""))
+ where
+ zid = citationId c
+
+replaceCite :: Inline -> [Inline]
+replaceCite (Cite c _) =
+ [Str "("] <> map (uncurry (Link mempty) . replaceCitation) c <> [Str ")"]
+replaceCite c = [c]
+
+replaceCites :: [Inline] -> [Inline]
+replaceCites = concatMap replaceCite
+
+handleBibliography :: ZettelGraph -> ZettelGraph
+handleBibliography zg =
+ if null zg.zettelGraphBib then zg else zg {unZettelGraph = walk replaceCites zg.unZettelGraph}