summaryrefslogtreecommitdiffstats
path: root/src/Zettel/Math.hs
blob: 49d6420dfd8b57583e3edffe777e9e7dfa395fcc (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
26
27
28
29
-- |
-- Module      : Zettel.Math
-- Description : Wrap math with hugo raw-html markers
-- Copyright   : (c) 2023, Yann Herklotz
-- License     : GPL-3.0-only
-- Maintainer  : git [at] yannherklotz [dot] com
-- Stability   : experimental
-- Portability : POSIX
module Zettel.Math where

import Text.Pandoc.Definition (Inline (..), Block (..))
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]

wrapMathLatex :: Block -> Block
wrapMathLatex r@(RawBlock t b)
      | t == "latex" = RawBlock "markdown" $ "{{< math >}}\n" <> b <> "{{< /math >}}"
      | otherwise = r
wrapMathLatex r = r

wrapZettelGraph :: ZettelGraph -> ZettelGraph
wrapZettelGraph = walk wrapMathLatex . walk wrapMath