Working Markdown processing and rendering

This commit is contained in:
2024-02-22 19:58:34 -06:00
parent 9255c8e4ac
commit 81e01e242c
8 changed files with 84 additions and 44 deletions

View File

@@ -1,7 +1,20 @@
module Core.Rendering where
import Lucid
import Data.ByteString.Lazy (ByteString)
import Commonmark
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString as B
import Data.Text
import Data.Text.Encoding (decodeUtf8)
import qualified Lucid as LU
import System.IO ()
lucidToTwain :: Html () -> ByteString
lucidToTwain = renderBS
lucidToTwain :: LU.Html () -> ByteString
lucidToTwain = LU.renderBS
mdToLucid :: Text -> LU.Html ()
mdToLucid cmtextinput = case (commonmark "" cmtextinput) of
Left _ -> LU.toHtmlRaw ("Failed to parse Markdown document" :: Text)
Right (h :: Html ()) -> LU.toHtmlRaw (renderHtml h)
mdFileToLucid :: FilePath -> IO (LU.Html ())
mdFileToLucid path = fmap (mdToLucid . decodeUtf8) (B.readFile path)