Created
May 3, 2020 23:06
-
-
Save steshaw/922e56c93f2f3320c11171309b301342 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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