Skip to content

Instantly share code, notes, and snippets.

@smurphy8
Created December 4, 2014 22:09
Show Gist options
  • Select an option

  • Save smurphy8/1ac1543d2752f08ad3a9 to your computer and use it in GitHub Desktop.

Select an option

Save smurphy8/1ac1543d2752f08ad3a9 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
-- | GHC Command to run
-- | :cmd return ":l Main\n :main -o midstates_chart.svg -h 1800 -w 1800"
module Diagrams.Text.XML ( ) where
import Diagrams.Prelude
import Diagrams.TwoD.Text (fontWeight, FontWeight (..))
import Control.Lens (makePrisms, (^?))
import Text.Trifecta
import Text.Trifecta.Result (Result (..))
import Text.Trifecta.Delta
import Control.Applicative ((<|>))
-- import Data.List (intersperse)
import Diagrams.Backend.SVG.CmdLine
data Element = Element { element :: String
,attributes :: [Att]}
deriving (Show)
data Att = Att (String,String)
deriving (Shownn)
testText :: String
testText = "<element attr1='3' attr2='Cat'> Some Text </element>"
parseElement nameString = angles parseElement'
where
parseElement' = do symbol nameString
attrList <- many parseAttributes
return $ Element nameString attrList
parseAttributes = do spaces
firstletter <- letter
rest <- manyTill alphaNum (char '=')
literal <- stringLiteral <|> stringLiteral'
return $ Att (firstletter:rest, literal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment