{-# LANGUAGE OverloadedStrings #-}
module Language.Drasil.HTML.MathJax (
  mathJax3Url, mathJaxScript,
  inlineEqn, blockEqn
) where

import Data.Text (Text)
import qualified Data.Text as T

import Drasil.Data.Formats.JSON (renderJSON, jsonRenderOpts, JSONStyle(..), JSON(..))

import Drasil.Printers.Common (wrap)

mathJax3Url :: Text
mathJax3Url :: Text
mathJax3Url = Text
"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js"

-- | Variable to include MathJax in our HTML files so we can render equations in LaTeX.
mathJaxScript :: Text
mathJaxScript :: Text
mathJaxScript = Text
"MathJax = " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
configJSON Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
";"
  where
    configJSON :: Text
configJSON = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Doc (ZonkAny 0) -> String
forall a. Show a => a -> String
show (Doc (ZonkAny 0) -> String) -> Doc (ZonkAny 0) -> String
forall a b. (a -> b) -> a -> b
$ JSONRenderOptions -> JSON -> Doc (ZonkAny 0)
forall ann. JSONRenderOptions -> JSON -> Doc ann
renderJSON
      (JSONStyle -> JSONRenderOptions
jsonRenderOpts (Natural -> JSONStyle
Pretty Natural
2))
      ( [(Text, JSON)] -> JSON
JObject [
        (Text
"loader",
        [(Text, JSON)] -> JSON
JObject [(Text
"load", [JSON] -> JSON
JArray [JSON
"[tex]/textmacros", JSON
"output/chtml"])]),
        (Text
"tex", [(Text, JSON)] -> JSON
JObject [(Text
"packages", [(Text, JSON)] -> JSON
JObject [(Text
"[+]", [JSON] -> JSON
JArray [JSON
"textmacros"])])]),
        (Text
"svg", [(Text, JSON)] -> JSON
JObject [(Text
"fontCache", JSON
"global")])]
      )

inlineEqn :: Text -> Text
inlineEqn :: Text -> Text
inlineEqn = Text -> Text -> Text -> Text
forall a. CanTextWrap a => Text -> Text -> a -> a
wrap Text
"\\(" Text
"\\)"

blockEqn :: Text -> Text
blockEqn :: Text -> Text
blockEqn = Text -> Text -> Text -> Text
forall a. CanTextWrap a => Text -> Text -> a -> a
wrap Text
"\\[" Text
"\\]"