From 284c6d3abd4cfa1e0eb91961dadffdb04fdc416a Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 9 Jun 2023 15:18:28 +0100 Subject: Use `.` instead of `>>` in fuction composition --- src/Zettel/Render.hs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/Zettel/Render.hs') diff --git a/src/Zettel/Render.hs b/src/Zettel/Render.hs index 0e7f436..264b7d1 100644 --- a/src/Zettel/Render.hs +++ b/src/Zettel/Render.hs @@ -26,7 +26,7 @@ import Text.Pandoc.Options (ReaderOptions (..), WriterOptions (..), getDefaultEx import Text.Pandoc.Scripting (noEngine) import Text.Pandoc.Templates (WithDefaultPartials (..), compileTemplate) import Text.Pandoc.Walk (query) -import Text.Pandoc.Writers (writeMarkdown) +import Text.Pandoc.Writers (writeMarkdown, writeJSON) import Zettel.Types zettelIdToLink :: ZettelId -> Inline @@ -63,7 +63,9 @@ renderZettel csl bib _ zettel = do let writeOpts = ( def { writerTemplate = Just templ, - writerExtensions = multimarkdownExtensions, + writerExtensions = disableExtension Ext_raw_attribute multimarkdownExtensions + -- enableExtension Ext_intraword_underscores githubMarkdownExtensions + , writerReferenceLinks = True } ) @@ -94,27 +96,35 @@ renderZettel csl bib _ zettel = do >>= writeMarkdown writeOpts else writeMarkdown writeOpts zettel.zettelBody -renderZettelFile :: FilePath -> Maybe FilePath -> FilePath -> ZettelId -> Zettel -> IO () -renderZettelFile csl bib dir ident zettel = do - log $ "Writing " <> T.pack path +renderZettelFile :: Bool -> FilePath -> Maybe FilePath -> FilePath -> ZettelId -> Zettel -> IO () +renderZettelFile json csl bib dir ident zettel = do + log $ "Rendering " <> T.pack path t <- renderZettel csl bib ident zettel writeFileText path t + when json $ do + log $ "Rendering " <> T.pack pathJSON + runIOorExplode (writeJSON def zettel.zettelBody) >>= writeFileText pathJSON where path = dir "zettel" toString (unZettelId ident) <.> "md" + pathJSON = dir "zettel" toString (unZettelId ident) <.> "json" -renderBibFile :: FilePath -> Maybe FilePath -> FilePath -> BibId -> Zettel -> IO () -renderBibFile csl bib dir (BibId ident) zettel = do +renderBibFile :: Bool -> FilePath -> Maybe FilePath -> FilePath -> BibId -> Zettel -> IO () +renderBibFile json csl bib dir (BibId ident) zettel = do log $ "Writing " <> T.pack path t <- renderZettel csl bib (ZettelId ident) zettel writeFileText path t + when json $ do + log $ "Rendering " <> T.pack pathJSON + runIOorExplode (writeJSON def zettel.zettelBody) >>= writeFileText pathJSON where path = dir "bib" toString ident <.> "md" + pathJSON = dir "bib" toString ident <.> "json" -renderZettelGraphFile :: FilePath -> Maybe FilePath -> FilePath -> ZettelGraph -> IO () -renderZettelGraphFile csl bib fp zg = +renderZettelGraphFile :: Bool -> FilePath -> Maybe FilePath -> FilePath -> ZettelGraph -> IO () +renderZettelGraphFile json csl bib fp zg = forM_ (Map.assocs (unZettelGraph zg)) - (uncurry (renderZettelFile csl bib fp)) + (uncurry (renderZettelFile json csl bib fp)) >> forM_ (Map.assocs (zettelGraphBib zg)) - (uncurry (renderBibFile csl bib fp)) + (uncurry (renderBibFile json csl bib fp)) -- cgit