Skip to content

Instantly share code, notes, and snippets.

@steshaw
Created May 3, 2020 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steshaw/922e56c93f2f3320c11171309b301342 to your computer and use it in GitHub Desktop.
Save steshaw/922e56c93f2f3320c11171309b301342 to your computer and use it in GitHub Desktop.
module HtmlToPlain where
import Prelude
import Text.Pandoc
import Text.Pandoc.Walk
import Data.Text
import qualified Data.Text.IO as T
htmlToPlain :: FilePath -> IO ()
htmlToPlain filePath = do
html <- T.readFile filePath;
htmlPandoc@(Pandoc _ htmlBlocks) <- runIOorExplode $ readHtml def html;
putStrLn "\nhtmlBlocks ---------------\n"
mapM_ print htmlBlocks;
md :: Text <- runIOorExplode $ writeMarkdown def htmlPandoc;
putStrLn "\nmd ---------------\n"
T.putStrLn md
mdPandoc@(Pandoc _ mdBlocks) <- runIOorExplode $ readMarkdown def md;
putStrLn "\nmdBlocks ---------------\n"
mapM_ print mdBlocks;
let cleanMdPandoc@(Pandoc _ cleanMdBlocks) = walk clean mdPandoc;
putStrLn "\ncleanMdBlocks ---------------\n"
mapM_ print cleanMdBlocks;
plain <- runIOorExplode $ writePlain def { writerTabStop = 2 } cleanMdPandoc;
putStrLn "\nplain ---------------\n"
T.putStrLn plain
where
clean :: Inline -> Inline
clean (Strong a) = Span def a
clean (Emph a) = Span def a
clean a = a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment