summaryrefslogtreecommitdiffstats
path: root/src/Zettel/Bibliography.hs
blob: 6186917d1e42e8a426db1c5b148b081c1a711cb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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}