From 6b797b52d65e0b174205bb12bc5075fed1825724 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 12 May 2023 22:28:07 +0100 Subject: Add math support in Hugo with shortcodes --- org-zk.cabal | 1 + src/Main.hs | 3 ++- src/Zettel.hs | 2 ++ src/Zettel/Math.hs | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/Zettel/Math.hs diff --git a/org-zk.cabal b/org-zk.cabal index fda804d..bca2ac2 100644 --- a/org-zk.cabal +++ b/org-zk.cabal @@ -52,6 +52,7 @@ executable org-zk other-modules: Zettel , Zettel.Common , Zettel.Links + , Zettel.Math , Zettel.Parse , Zettel.Render , Zettel.Transclusion diff --git a/src/Main.hs b/src/Main.hs index b66d2ab..1e1094a 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -212,5 +212,6 @@ main = do graph' <- parseZettelKasten fl let graph = transcludeMdAll graph' let linkedGraph = linkAll graph - renderZettelGraphFile "../zk-web/content/zettel" linkedGraph + let wrappedGraph = wrapZettelGraph linkedGraph + renderZettelGraphFile "../zk-web/content/zettel" wrappedGraph return () diff --git a/src/Zettel.hs b/src/Zettel.hs index 8c4720b..6846263 100644 --- a/src/Zettel.hs +++ b/src/Zettel.hs @@ -4,6 +4,7 @@ module Zettel module Zettel.Links, module Zettel.Parse, module Zettel.Transclusion, + module Zettel.Math, ) where @@ -12,3 +13,4 @@ import Zettel.Parse import Zettel.Render import Zettel.Transclusion import Zettel.Types +import Zettel.Math diff --git a/src/Zettel/Math.hs b/src/Zettel/Math.hs new file mode 100644 index 0000000..226f515 --- /dev/null +++ b/src/Zettel/Math.hs @@ -0,0 +1,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 -- cgit