packages feed

prettyprinter-lucid (empty) → 0.1.0.0

raw patch · 4 files changed

+100/−0 lines, 4 filesdep +basedep +luciddep +prettyprinter

Dependencies added: base, lucid, prettyprinter, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright George Thomas (c) 2020++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Author name here nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# Pretty HTML++This is just a tiny library enabling [lucid](https://hackage.haskell.org/package/lucid) to be used as a backend for [prettyprinter](https://hackage.haskell.org/package/prettyprinter). This makes it easy to programmatically generate HTML documents with complex nested styling.
+ prettyprinter-lucid.cabal view
@@ -0,0 +1,51 @@+cabal-version:       3.0+name:                prettyprinter-lucid+synopsis:            A prettyprinter backend for lucid+description:         Provides utility functions for rendering pretty HTML.+category:            Web+homepage:            https://github.com/georgefst/prettyprinter-lucid+license:             BSD-3-Clause+license-file:        LICENSE+author:              George Thomas+maintainer:          georgefsthomas@gmail.com+version:             0.1.0.0+extra-doc-files:     README.md++source-repository head+    type: git+    location: git://github.com/georgefst/prettyprinter-lucid.git++library+    exposed-modules:+        Prettyprinter.Lucid+    build-depends:+        base ^>= {4.12, 4.13, 4.14},+        lucid ^>= 2.9.12,+        prettyprinter ^>= 1.7.0,+        text ^>= 1.2.3,+    hs-source-dirs:+        src+    ghc-options:+        -Wall+        -Wincomplete-uni-patterns+        -Wincomplete-record-updates+        -fdefer-typed-holes+    default-language: Haskell2010+    default-extensions:+        DeriveFoldable+        DeriveFunctor+        DeriveGeneric+        DeriveTraversable+        DerivingStrategies+        EmptyCase+        FlexibleContexts+        FlexibleInstances+        GeneralisedNewtypeDeriving+        LambdaCase+        MultiParamTypeClasses+        OverloadedStrings+        PartialTypeSignatures+        RankNTypes+        ScopedTypeVariables+        StandaloneDeriving+        TupleSections
+ src/Prettyprinter/Lucid.hs view
@@ -0,0 +1,16 @@+module Prettyprinter.Lucid where++import qualified Data.Text as T+import Lucid+import Prettyprinter.Render.Util.SimpleDocTree++renderHtml :: SimpleDocTree (Html () -> Html ()) -> Html ()+renderHtml =+    let go = \case+            STEmpty -> pure ()+            STChar c -> toHtml $ T.singleton c+            STText _ t -> toHtml t+            STLine i -> br_ [] >> toHtml (T.replicate i $ T.singleton ' ')+            STAnn ann content -> ann $ go content+            STConcat contents -> foldMap go contents+     in pre_ . go