<commit_before>-- includes.hs
import Text.Pandoc
import Text.Pandoc.Options
import System.Process
import Data.Set

tmpl = unlines [
  "$if(titleblock)$$titleblock$",
  "$endif$$for(header-includes)$$header-includes$",
  "$endfor$$for(include-before)$$include-before$",
  "$endfor$$if(toc)$$toc$",
  "$endif$$body$$for(include-after)$",
  "$include-after$$endfor$"
  ]

doInclude :: Block -> IO Block
doInclude cb@(CodeBlock (id, classes, namevals) contents) =
  case lookup "execute" namevals of
       Just f     -> return . Plain . (\d -> [d]) . (Str) =<< readProcess f [] contents
       Nothing    -> return cb
doInclude x = return x

main :: IO ()
main = getContents >>= bottomUpM doInclude . readMarkdown def{<commit_msg>More capable inline scripting module<commit_after>-- includes.hs
import Text.Pandoc
import Text.Pandoc.Options
import System.Process
import Data.Set

tmpl = unlines [
  "$if(titleblock)$$titleblock$",
  "$endif$$for(header-includes)$$header-includes$",
  "$endfor$$for(include-before)$$include-before$",
  "$endfor$$if(toc)$$toc$",
  "$endif$$body$$for(include-after)$",
  "$include-after$$endfor$"
  ]

doInclude :: [Block] -> IO [Block]
doInclude (cb@(CodeBlock (id, classes, namevals) contents):xs) =
  do rst <- doInclude xs
     case lookup "execute" namevals of
          Just f -> 
            do txt <- readProcess f [] contents
               case lookup "type" namevals of
                    Just "plainText" -> 
                      return (makePlain txt : rst)
                    Just "block" -> 
                      return (makeBlock txt : rst)
                    Nothing -> 
                      return ((blocks $ readMarkdown def txt) ++ rst)
               where makePlain = Plain . (\d -> [d]) . (Str)
                     makeBlock = CodeBlock attrs 
                     attrs = (id, classes, n)
                        where n = Prelude.filter notExecute namevals
                              notExecute (a,b) = a /= "execute"
                     blocks p@(Pandoc _ b) = b
          Nothing -> return (cb : rst)
doInclude (x:xs) =do rst <- doInclude xs
                     return (x:rst)
doInclude [] = return []

main :: IO ()
main = getContents >>= bottomUpM doInclude . readMarkdown def{
{'fraction_non_alphanumeric': 0.14196706720071206, 'fraction_numerical': 0.0, 'mean_word_length': 2.2865497076023393, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1310717', 'n_tokens_mistral': 695, 'n_tokens_neox': 671, 'n_words': 177}