{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall #-}
module Wave.Md2doc (
module Wave.Md2doc,
) where
import UniformBase
import Foundational.SettingsPage
import Foundational.MetaPage
import Foundational.Filetypes4sites ( Docrep(Docrep), meta1)
import Foundational.CmdLineFlags
( PubFlags(draftFlag, privateFlag) )
import Uniform.Pandoc
(pandocProcessCites, markdownFileType, readMarkdown2 )
import Uniform.Latex
import Lib.FileHandling
import Lib.OneMDfile
import Foundational.MetaPage (MetaPage(dyDoNotReplace))
import Lib.FileHandling (readErlaubt)
readMarkdownFile2docrep :: NoticeLevel -> Settings -> Path Abs File -> ErrIO Docrep
readMarkdownFile2docrep :: NoticeLevel -> Settings -> Path Abs File -> ErrIO Docrep
readMarkdownFile2docrep NoticeLevel
debug Settings
sett3 Path Abs File
fnin = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords
[Text
"readMarkdownFile2docrep fnin", forall a. PrettyStrings a => a -> Text
showPretty Path Abs File
fnin]
MarkdownText
mdfile <- forall a b.
TypedFiles7a a b =>
Path Abs File -> TypedFile5 a b -> ErrIO b
read8 Path Abs File
fnin TypedFile5 Text MarkdownText
markdownFileType
Pandoc
pd <- MarkdownText -> ErrIO Pandoc
readMarkdown2 MarkdownText
mdfile
let meta6 :: MetaPage
meta6 = Settings -> Path Abs File -> Pandoc -> MetaPage
pandoc2MetaPage Settings
sett3 Path Abs File
fnin Pandoc
pd
let doc1 :: Docrep
doc1 = MetaPage -> Pandoc -> Docrep
Docrep MetaPage
meta6 Pandoc
pd
let langCode :: Text
langCode = Text -> Text
latexLangConversion forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetaPage -> Text
dyLang forall b c a. (b -> c) -> (a -> b) -> a -> c
. Docrep -> MetaPage
meta1 forall a b. (a -> b) -> a -> b
$ Docrep
doc1
let debugReplace :: Bool
debugReplace = NoticeLevel -> Bool
inform NoticeLevel
debug
Docrep
doc2 <- if Text
langCode forall a. Eq a => a -> a -> Bool
== Text
"ngerman"
then do
[Text]
erl1 <- Path Abs File -> ErrIO [Text]
readErlaubt (SiteLayout -> Path Abs File
replaceErlaubtFile forall b c a. (b -> c) -> (a -> b) -> a -> c
. Settings -> SiteLayout
siteLayout forall a b. (a -> b) -> a -> b
$ Settings
sett3)
let addErl :: [Text]
addErl = MetaPage -> [Text]
dyDoNotReplace forall b c a. (b -> c) -> (a -> b) -> a -> c
. Docrep -> MetaPage
meta1 forall a b. (a -> b) -> a -> b
$ Docrep
doc1
erl2 :: [Text]
erl2 = [Text]
addErl forall a. [a] -> [a] -> [a]
++ [Text]
erl1
Bool
changed <- Bool -> [Text] -> Path Abs File -> ErrIO Bool
applyReplace Bool
debugReplace [Text]
erl2 Path Abs File
fnin
if (Bool
changed Bool -> Bool -> Bool
&& (Bool -> Bool
not Bool
debugReplace))
then NoticeLevel -> Settings -> Path Abs File -> ErrIO Docrep
readMarkdownFile2docrep NoticeLevel
debug Settings
sett3 Path Abs File
fnin
else forall (m :: * -> *) a. Monad m => a -> m a
return Docrep
doc1
else forall (m :: * -> *) a. Monad m => a -> m a
return Docrep
doc1
forall (m :: * -> *) a. Monad m => a -> m a
return Docrep
doc2
applyReplace :: Bool -> [Text] -> Path Abs File -> ErrIO Bool
applyReplace :: Bool -> [Text] -> Path Abs File -> ErrIO Bool
applyReplace Bool
debugReplace [Text]
erl2 Path Abs File
fnin = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugReplace forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords
[Text
"applyReplace fnin", forall a. PrettyStrings a => a -> Text
showPretty Path Abs File
fnin
, Text
"\t erlaubt:", forall {a}. Show a => a -> Text
showT [Text]
erl2]
Bool
res <- Bool -> [Text] -> Path Abs File -> ErrIO Bool
procMd1 Bool
debugReplace [Text]
erl2 Path Abs File
fnin
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugReplace forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"applyReplace done. Changed:", forall {a}. Show a => a -> Text
showT Bool
res ]
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
res
addRefs :: NoticeLevel -> Docrep -> ErrIO Docrep
addRefs :: NoticeLevel -> Docrep -> ErrIO Docrep
addRefs NoticeLevel
debug dr1 :: Docrep
dr1@(Docrep MetaPage
y1 Pandoc
p1) = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"addRefs", forall {a}. Show a => a -> Text
showT Docrep
dr1, Text
"\n"]
case (MetaPage -> Maybe Text
dyBibliography MetaPage
y1) of
Maybe Text
Nothing -> (forall (m :: * -> *) a. Monad m => a -> m a
return Docrep
dr1)
Just Text
_ -> do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords
[Text
"addRefs2-1", forall {a}. Show a => a -> Text
showT forall a b. (a -> b) -> a -> b
$ MetaPage -> FilePath
dyFn MetaPage
y1
, Text
"\n\t biblio1" , forall {a}. Show a => a -> Text
showT forall a b. (a -> b) -> a -> b
$ MetaPage -> Maybe Text
dyBibliography MetaPage
y1
, Text
"\n\t style1" , forall {a}. Show a => a -> Text
showT forall a b. (a -> b) -> a -> b
$ MetaPage -> Maybe Text
dyStyle MetaPage
y1
]
Pandoc
p2 <- Pandoc -> ErrIO Pandoc
pandocProcessCites Pandoc
p1
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"addRefs2-4", Text
"p2\n", forall {a}. Show a => a -> Text
showT Pandoc
p2]
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaPage -> Pandoc -> Docrep
Docrep MetaPage
y1 Pandoc
p2)
filterNeeds :: NoticeLevel -> PubFlags -> Settings -> Path Rel File -> ErrIO(Maybe (Path Rel File))
filterNeeds :: NoticeLevel
-> PubFlags
-> Settings
-> Path Rel File
-> ErrIO (Maybe (Path Rel File))
filterNeeds NoticeLevel
debug PubFlags
pubf Settings
sett4 Path Rel File
fn = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"filterNeeds", Text
"\nPubFlags", forall {a}. Show a => a -> Text
showT PubFlags
pubf ]
let doughP :: Path Abs Dir
doughP = SiteLayout -> Path Abs Dir
doughDir forall b c a. (b -> c) -> (a -> b) -> a -> c
. Settings -> SiteLayout
siteLayout forall a b. (a -> b) -> a -> b
$ Settings
sett4
Docrep
d1 <- NoticeLevel -> Settings -> Path Abs File -> ErrIO Docrep
readMarkdownFile2docrep NoticeLevel
debug Settings
sett4 (Path Abs Dir
doughP forall fp file.
Filenames3 fp file =>
fp -> file -> FileResultT fp file
</> Path Rel File
fn)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"filterNeeds2", Text
"\nMeta", forall {a}. Show a => a -> Text
showT (Docrep -> MetaPage
meta1 Docrep
d1) ]
let t :: Bool
t = PubFlags -> MetaPage -> Bool
includeBakeTest3docrep PubFlags
pubf (Docrep -> MetaPage
meta1 Docrep
d1)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
t then forall a. a -> Maybe a
Just Path Rel File
fn else forall a. Maybe a
Nothing
includeBakeTest3docrep :: PubFlags -> MetaPage -> Bool
includeBakeTest3docrep :: PubFlags -> MetaPage -> Bool
includeBakeTest3docrep PubFlags
pubf MetaPage
doc1 =
(PubFlags -> Bool
draftFlag PubFlags
pubf Bool -> Bool -> Bool
|| Text
vers1 forall a. Eq a => a -> a -> Bool
== Text
"publish")
Bool -> Bool -> Bool
&& (PubFlags -> Bool
privateFlag PubFlags
pubf Bool -> Bool -> Bool
|| Text
vis1 forall a. Eq a => a -> a -> Bool
== Text
"public")
where
vers1 :: Text
vers1 = MetaPage -> Text
dyVersion MetaPage
doc1
vis1 :: Text
vis1 = MetaPage -> Text
dyVisibility MetaPage
doc1