Skip to content

Commit

Permalink
use html-conduit for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ocramz committed Jan 26, 2021
1 parent 5d6c629 commit 2608e94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/Text/Html.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# language LambdaCase #-}
{-# options_ghc -Wno-unused-imports -Wno-unused-top-binds #-}
-- {-# options_ghc -Wno-unused-imports -Wno-unused-top-binds #-}
module Text.Html (loadAndProcess, loadDoc) where

import Control.Applicative (Alternative (..))
Expand All @@ -23,13 +23,16 @@ import Text.Megaparsec.Error (ParseErrorBundle (..), errorBundlePretty)
import System.Directory (makeAbsolute)
-- filepath
import System.FilePath.Posix (takeExtension, (</>))
-- html-conduit
import Text.HTML.DOM (parseLT)

-- text
import qualified Data.Text as T (Text, all, pack, unpack)
import qualified Data.Text.IO as T (putStrLn)
import qualified Data.Text.Lazy as TL (Text, toStrict, fromStrict)
import qualified Data.Text.Lazy.IO as TL (readFile, putStrLn)

-- xml-conduit
import Text.XML (ParseSettings, Document(..), Element(..), Node(..), parseText, def, renderText, psDecodeEntities, decodeHtmlEntities, rsPretty, rsXMLDeclaration)
import Data.XML.Types (Name(..))

Expand Down Expand Up @@ -82,17 +85,19 @@ loadElementH cfg inPaths fp = do
expand cfg inPaths decSetts el

loadDoc :: FilePath -> IO Document
loadDoc fp = do
tl0 <- TL.readFile fp
let
decSetts = def { psDecodeEntities = decodeHtmlEntities }
case parseText decSetts tl0 of
Right hdoc -> pure hdoc
Left e -> error $ unwords ["Error while attempting to parse", fp, ":", show e]

data Error =
EFileNotFound FilePath
| ECannotParseFilePath SomeException FilePath
loadDoc fp = parseLT <$> TL.readFile fp
-- tl0 <- TL.readFile fp
-- pure $ parseLT tl0
-- let
-- decSetts = def { psDecodeEntities = decodeHtmlEntities }
-- case parseText decSetts tl0 of
-- case parseLT tl0 of
-- Right hdoc -> pure hdoc
-- Left e -> error $ unwords ["Error while attempting to parse", fp, ":", show e]

-- data Error =
-- EFileNotFound FilePath
-- | ECannotParseFilePath SomeException FilePath


data Match =
Expand Down
3 changes: 2 additions & 1 deletion twelve.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: twelve
version: 0.2.0.0
version: 0.3.0.0
synopsis: Like 11ty, but this goes up to 12
description: twelve is a simple build tool for composing static websites from templates. Please see README for full details
homepage: https://github.com/ocramz/twelve
Expand Down Expand Up @@ -34,6 +34,7 @@ library
, file-embed
, filepath
, githash
, html-conduit
, http-types
, megaparsec
, mtl
Expand Down

0 comments on commit 2608e94

Please sign in to comment.