Giter VIP home page Giter VIP logo

blaze-markup's Introduction

What

This is the source code of my personal home page. It might be of interest to anyone who wants to set up a blog using Hakyll.

License

This website falls under regular copyright laws. This means the code is available as a reference. You shouldn't use it as a starting point for your own site, the examples on the Hakyll site are much cleaner.

blaze-markup's People

Contributors

23skidoo avatar andreasabel avatar andrewthad avatar aslatter avatar axman6 avatar bgamari avatar bodigrim avatar chris-martin avatar danburton avatar deepakjois avatar dougburke avatar franklinchen avatar jaspervdj avatar javache avatar jgm avatar jnwhiteh avatar joerixaop avatar marcmo avatar markwright avatar meiersi avatar pidelport avatar ryanglscott avatar snoyberg avatar sol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

blaze-markup's Issues

Non validating `script` combinator

In tasty-html, we need to include jquery source code inline. However we can't use the script combinator because jquery has many HTML tags in the code and fails to validate.

Is there a clean way to deal with this need?

Would you accept in blaze-html an alternative combinator to script which doesn't check for validation? Maybe unsafeScript?

Make a revision on hackage (for GHC 9.0)

Please go to https://hackage.haskell.org/package/blaze-markup/maintain and revise the upper bounds:

  • base < 4.16 (see #53)
  • tasty < 1.5 (see #52)

Optionally, also revise tested-with (see #54).

There is a handy tool for making revisions: https://github.com/hackage-trustees/hackage-cli.
E.g. after merging #54, you could try

hackage-cli push-cabal --incr-rev  blaze-markup.cabal

(This previews the changes. The revision is only actually made if you also supply --publish.)

ToMarkup instance

Could we please have the following instance?

instance (ToMarkup a) => ToMarkup (E.Value a) where
toMarkup x = toMarkup (E.unValue x)

This would simplify the use of Values in hamlet templates, since we would no longer need to write #{E.unvalue whatEver} but we could just use #{whatEver}.

Doesn't work with GHC 8.4.1

src/Text/Blaze/Internal.hs:222:25: error:
    • No instance for (Semigroup AttributeValue)
        arising from the 'deriving' clause of a data type declaration
      Possible fix:
        use a standalone 'deriving instance' declaration,
          so you can specify the instance context yourself
    • When deriving the instance for (Monoid AttributeValue)
    |
222 |     deriving (IsString, Monoid)
    |                         ^^^^^^

I suggest adding Hackage revisions changing the constraint on base to >= 4 && < 4.11 in already-released versions.

Failure with ApplicativeDo

Example provided by @snoyberg :

{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE OverloadedStrings #-}

import Data.Text (Text)
import Text.Blaze
import Text.Blaze.Renderer.String

foo :: Markup -> Markup
foo title = do
    "hello "
    title
    "!"

main :: IO ()
main = print $ renderMarkup $ foo "world"

This can trigger Exception: Text.Blaze.Internal.MarkupM: invalid use of monadic bind. Originally reported at yesodweb/shakespeare#204 .

Add toPreEscapedMarkup

It might be a good idea to have

class ToMarkup a where
    toMarkup :: a -> Markup
    toPreEscapedMarkup :: a -> Markup

and the same for attributes.

MonadReader instance

Would be nice to have a MonadReader instance of Markup to use it with Reader's ask/local to pass around some variables without littering code with extra arguments here and there.

Recursive instances for MarkupM not ignoring first argument of Append constructor

Use case

I have a LaTeX document which have to be parsed to JSON. This JSON then is going to be traversed by frontend developers and used to compose a web page via React. Therefore final document should contain HTML/MathML pieces with HTML subtrees in JSON data.
They tell me it's inconvenient to get composed textual HTML chunks with markup from server.

I use Pandoc to convert Tex chunks to HTML and it seems strange to parse resulting HTML again to json with tags converted to json keys. Luckily standard Pandoc writer for HTML returns MarkupM () instead of Text, so structure isn't lost.

Hence now I have to write ToJSON instance for MarkupM (). This instance cannot ignore first operand of Append data constructor, because most of the data is finally contained in there. This argument has quantified type forall b. ... MarkupM b.

Problem

Attempt to write it via Generics leads to this error:

• Can't make a derived instance of ‘Generic (MarkupM ())’:
        Append must be a vanilla data constructor
    • In the stand-alone deriving instance for ‘Generic (MarkupM ())’

It seems to be related to https://gitlab.haskell.org/ghc/ghc/-/issues/10514

I was able to write typecheckable instance with signature instance (forall b. ToJSON b) => ToJSON (MarkupM ()) manually, using QuantifiedConstraints extension, but it seems unusable -- attempt to call yields this:

    • No instance for (aeson-1.4.7.1:Data.Aeson.Types.ToJSON.ToJSON b)
        arising from a use of ‘encodePretty’
      Possible fix:
        add (aeson-1.4.7.1:Data.Aeson.Types.ToJSON.ToJSON
               b) to the context of
          a quantified context

It does not seem surprising though.

Question

Is it possible to write such an instance? Ideally, derive. And how to, if possible?

Or I would be thankful for a guide in a right direction regarding use case.

Revise to allow base-4.16 (GHC 9.2)

Compilation with GHC 9.2 succeeds if base is bumped.

cabal install -w ghc-9.2.0 blaze-markup --allow-newer=base

A revision on hackage could fix this. (Instructions see #55.)

StaticString benchmark

While reading the code I started wondering, if you have some data or at least first hand expriences of the speedup provided by the StaticString type? It seems you want to shift as much processing of all the literal tags and comments to compile time.

Some more insight would be appreciated!

Thx

blaze-markup-0.8.* fails to build with GHC 7.0.4

The error is

Configuring library for blaze-markup-0.8.2.2..
Preprocessing library for blaze-markup-0.8.2.2..
Building library for blaze-markup-0.8.2.2..
[1 of 6] Compiling Text.Blaze.Internal ( src/Text/Blaze/Internal.hs, dist/build/Text/Blaze/Internal.o )

src/Text/Blaze/Internal.hs:230:10:
    Illegal equational constraint a ~ ()
    (Use -XTypeFamilies to permit this)
    In the context: (a ~ ())
    While checking the context of an instance declaration
    In the instance declaration for `IsString (MarkupM a)'

I've fixed up the affected releases at

extract value a from MarkupM a

Although the MarkupM monad is usually used as Markup = MarkupM (), it sometimes is handy to use it in a monad transformer stack. For example, code that builds Html and keeps track of internal references might be of type StateT Reference MarkupM (). It seems to be impossible, however, to replace the MarkupM monad inside the stack with another monad, say IO when rendering the Html. The reason is that there is currently no (exposed) way of extracting the a from some MarkupM a value. Hence please either expose the function markupValue :: MarkupM a -> a or generalize the renderer functions to work not only on MarkupM () but on any MarkupM a.

FromList instances for Attribute

Lately, I've been writing more functions that take an Attribute collection as an argument. I'm trying to think of ways to make it easier to users (mostly myself) to call these functions. One strategy I've started adopting is accepting a Foldable collection of Attributes. Here's an example from a library of mine:

footer_ :: (Monad m, Foldable t) => t Attribute -> WidgetT site m a -> WidgetT site m a

I know that blaze has the ! operator, but I've always preferred concatenating all of my Attributes first and then applying them to the element. And that's exactly what this function does. It uses the Foldable instance just to call fold on the collection. The end user ends up writing:

footer [class_ "foo", id_ "bar"] "Stuff in the footer"

I was thinking though that it's annoying to have the Foldable constraint at all. It could be written to take a list of Attributes instead, but I still consider that an unneeded indirection. The function could alternatively be written as:

footer_ :: Monad m => Attribute -> WidgetT site m a -> WidgetT site m a

But then the user must call fold (or mconcat) manually:

footer (fold [class_ "foo", id_ "bar"]) "Stuff in the footer"

Which I don't want to have to do when writing code. All of this is the background for why I would like a FromList instance. The instance I'm describing could technically exist for any Monoid. It is written as:

class IsList Attribute where
  type Item Attribute = Attribute
  fromList = fold
  toList x = [x]

The neat thing about this is that it would enable me to define footer_ to accept an Attribute, and in the common use case (a list of attributes of known at compile time), the user doesn't have to call fold manually:

footer_ :: Monad m => Attribute -> WidgetT site m a -> WidgetT site m a
footer_ = ...

>>> footer_ [class_ "bar", id_ "baz"] "Content"

The bad thing is that this instance does not satisfy the law fromList . toList = id. However, given that users cannot inspect Attributes to discover their structure, I would argue that the law is satisfied "up to interpretation", similar to how certain monads only satisfy the monad laws under an interpretation function. Anyway, let me know what you think. Having this instance would be helpful for a lot of the stuff I'm working on.

script tag rejects valid javascript due to `external`

As you know, style and script tags apply the external function to their content, which here causes the content to be wiped if it contains the "</" characters.

First of all, it would be awesome if these docs mentioned that this happens, since I was very confused about why my input was getting eaten.

Second of all, as-is this appears to be a bug, not a feature, since it rejects perfectly valid javascript code, such as document.write("<p>hello</p>") because that code contains the substring </.

This seems to be a functioning workaround:

script :: String -> Html
script str = preEscapedToHtml ("<script>" ++ str ++ "</script>")

Make MarkupM and AttributeValue derive Eq

Prelude> import Text.Blaze.Html5
Prelude Text.Blaze.Html5> toHtml "foo" == toHtml "bar"

<interactive>:2:1: error:
     No instance for (Eq Html) arising from a use of ‘==’
     In the expression: toHtml "foo" == toHtml "bar"
      In an equation for it’: it = toHtml "foo" == toHtml "bar"
Prelude Text.Blaze.Html5> toValue "foo" == toValue "bar"

<interactive>:3:1: error:
     No instance for (Eq AttributeValue) arising from a use of ‘==’
     In the expression: toValue "foo" == toValue "bar"
      In an equation for it’: it = toValue "foo" == toValue "bar"

This would be useful for all kinds of scripts.

Custom element creation as part of the public API

Hey,

As WebComponents and other contexts where custom events are more common have surfaced, have you considered making customParent et alii from the Internal module part of Blaze's public API? Perhaps with a shorter function name as well. :)

blaze-markup-0.8.2.4: Build fails using GHC 8.10.1

$ cabal get blaze-markup
$ cd blaze-markup-0.8.2.4
$ cabal install
cabal: Could not resolve dependencies:
[__0] trying: blaze-markup-0.8.2.4 (user goal)
[__1] next goal: base (dependency of blaze-markup)
[__1] rejecting: base-4.14.0.0/installed-4.14.0.0 (conflict: blaze-markup =>
base>=4 && <4.14)
[__1] rejecting: base-4.12.0.0, base-4.11.1.0, base-4.11.0.0, base-4.10.1.0,
ghc -V
The Glorious Glasgow Haskell Compilation System, version 8.10.1

(Curiously blaze-markup-0.8.2.0 compiles with GHC 8.10.1.)

blaze-markup-0.6.3.0 test suite failure

Citing from http://hydra.cryp.to/build/538134/nixlog/7/raw:

Running 1 test suites...
Test suite blaze-markup-tests: RUNNING...
Text.Blaze.Tests:
  left identity Monoid law: [Failed]
*** Failed! Falsifiable (after 6 tests): 
"<img id=\"g\195\175d\" name=\"\" class=\"\195\144\" id=\"&#39;Y\"><img><div class=\"f\195\141\195\190\">U</div>"
(used seed -4141915000318621053)
  right identity Monoid law: [Failed]
*** Failed! Falsifiable (after 4 tests): 
"<br class=\"\"><table class=\"\194\177\"><div name=\"\194\156\" id=\"\195\156\" class=\"MwF\" name=\"\195\189\"><area></div></table>"
(used seed 3769094616709931206)
  associativity Monoid law: [Failed]
*** Failed! Falsifiable (after 4 tests): 
"<img name=\"\195\191\" class=\"\" id=\"P\194\164\195\178\" class=\"\">"
""
"<area id=\"\" id=\"\" name=\"R`\">"
(used seed 9159315065659811936)
  mconcat Monoid law: [Failed]
*** Failed! Falsifiable (after 4 tests): 
["<img class=\"v\" name=\"\194\146\">"]
(used seed 4417847674701686653)
  identity Applicative law: [Failed]
*** Failed! Falsifiable (after 5 tests): 
"<area name=\"\194\132\" class=\"#\" name=\"7c\">"
(used seed 1682729845193000793)
  post escaping characters: [OK, passed 100 tests]
  valid UTF-8: [OK, passed 100 tests]
  external </ sequence: [OK, passed 100 tests]
  well nested <>: [OK, passed 100 tests]
  unsafeByteString id: [OK, passed 100 tests]
  conditional attributes: [OK]
  contents 1: [OK]
  empty 1: [OK]
  empty 2: [OK]
  comment 1: [OK]

         Properties   Test Cases  Total       
 Passed  5            5           10          
 Failed  5            0           5           
 Total   10           5           15          
Test suite blaze-markup-tests: FAIL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.