diff options
author | Yann Herklotz <git@yannherklotz.com> | 2023-05-28 03:52:10 +0100 |
---|---|---|
committer | Yann Herklotz <git@yannherklotz.com> | 2023-05-28 03:52:10 +0100 |
commit | 02d36d9c5c55d49bdfedf29fb9aff9202f19cf53 (patch) | |
tree | 2f8cc931b77aaefaf71eec3cc15f0015496a2dd2 /src/Zettel/Bibliography.hs | |
parent | 5681d073ee1ded65bcd944c6abc2c7082cff2b31 (diff) | |
download | zk-visual-02d36d9c5c55d49bdfedf29fb9aff9202f19cf53.tar.gz zk-visual-02d36d9c5c55d49bdfedf29fb9aff9202f19cf53.zip |
Add support for bibliography notes export
Diffstat (limited to 'src/Zettel/Bibliography.hs')
-rw-r--r-- | src/Zettel/Bibliography.hs | 25 |
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} |