summaryrefslogtreecommitdiffstats
path: root/src/Zettel/Math.hs
blob: 226f515fe0acbd278bf0b16678916891e4a2a376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{-# LANGUAGE OverloadedRecordDot #-}

module Zettel.Math where

import Text.Pandoc.Definition (Inline (..), Pandoc (..))
import Text.Pandoc.Walk (walk)
import Zettel.Types

wrapMath :: [Inline] -> [Inline]
wrapMath = concatMap f
  where
    f :: Inline -> [Inline]
    f m@(Math _ _) = [RawInline "markdown" "{{< math >}}", m, RawInline "markdown" "{{< /math >}}"]
    f a = [a]

wrapMathPandoc :: Pandoc -> Pandoc
wrapMathPandoc = walk wrapMath

wrapZettel :: Zettel -> Zettel
wrapZettel z = z {zettelBody = wrapMathPandoc z.zettelBody}

wrapZettelGraph :: ZettelGraph -> ZettelGraph
wrapZettelGraph = ZettelGraph . fmap wrapZettel . unZettelGraph