skylighting 0.3.4.1 → 0.3.5
raw patch · 5 files changed
+81/−4 lines, 5 filesdep +base64-bytestringdep ~aesonPVP ok
version bump matches the API change (PVP)
Dependencies added: base64-bytestring
Dependency ranges changed: aeson
API changes (from Hackage documentation)
+ Skylighting.Regex: instance Data.Aeson.Types.FromJSON.FromJSON Skylighting.Regex.RE
+ Skylighting.Regex: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Regex.RE
+ Skylighting.Types: instance (Data.Aeson.Types.FromJSON.FromJSON a, GHC.Classes.Ord a) => Data.Aeson.Types.FromJSON.FromJSON (Skylighting.Types.WordSet a)
+ Skylighting.Types: instance Data.Aeson.Types.FromJSON.FromJSON Skylighting.Types.Context
+ Skylighting.Types: instance Data.Aeson.Types.FromJSON.FromJSON Skylighting.Types.ContextSwitch
+ Skylighting.Types: instance Data.Aeson.Types.FromJSON.FromJSON Skylighting.Types.KeywordAttr
+ Skylighting.Types: instance Data.Aeson.Types.FromJSON.FromJSON Skylighting.Types.Matcher
+ Skylighting.Types: instance Data.Aeson.Types.FromJSON.FromJSON Skylighting.Types.Rule
+ Skylighting.Types: instance Data.Aeson.Types.FromJSON.FromJSON Skylighting.Types.Syntax
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.Color
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.Context
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.ContextSwitch
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.KeywordAttr
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.Matcher
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.Rule
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.Style
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.Syntax
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.TokenStyle
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON Skylighting.Types.TokenType
+ Skylighting.Types: instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Skylighting.Types.WordSet a)
Files
- changelog.md +6/−0
- skylighting.cabal +3/−1
- src/Skylighting/Regex.hs +21/−0
- src/Skylighting/Styles.hs +2/−2
- src/Skylighting/Types.hs +49/−1
changelog.md view
@@ -1,5 +1,11 @@ # Revision history for skylighting +## 0.3.5 --- 2017-09-14++ * Added ToJSON/FromJSON instances for all basic types.+ * Added some background colors to 'kate' style, matching default.theme,+ and made FromJSON for Style sensitive to background-color.+ ## 0.3.4.1 -- 2017-09-09 * HTML formatting: do not use `div` elements for source
skylighting.cabal view
@@ -1,5 +1,5 @@ name: skylighting-version: 0.3.4.1+version: 0.3.5 synopsis: syntax highlighting library description: Skylighting is a syntax highlighting library with support for over one hundred languages. It derives@@ -239,6 +239,7 @@ utf8-string, hxt, safe,+ base64-bytestring, blaze-html >= 0.5, containers if flag(system-pcre)@@ -271,6 +272,7 @@ build-depends: base >= 4.7 && < 5.0, filepath, bytestring,+ base64-bytestring, text, safe, hxt,
src/Skylighting/Regex.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE OverloadedStrings #-} module Skylighting.Regex ( Regex@@ -20,6 +21,10 @@ import Text.Regex.PCRE.ByteString import Data.Data import Data.Binary (Binary)+import Data.Aeson+import qualified Data.Text as Text+import qualified Data.Text.Encoding as TE+import qualified Data.ByteString.Base64 as Base64 -- | An exception in compiling or executing a regex. newtype RegexException = RegexException String@@ -35,6 +40,14 @@ instance Binary RE +instance ToJSON RE where+ toJSON re = object [ "reString" .= encodeToText (reString re)+ , "reCaseSensitive" .= reCaseSensitive re ]+instance FromJSON RE where+ parseJSON = withObject "RE" $ \v ->+ RE <$> ((v .: "reString") >>= decodeFromText)+ <*> v .: "reCaseSensitive"+ -- | Compile a PCRE regex. If the first parameter is True, the regex is -- case-sensitive, otherwise caseless. The regex is compiled from -- a bytestring interpreted as UTF-8. If the regex cannot be compiled,@@ -83,3 +96,11 @@ Just (mat : capts) Right Nothing -> Nothing Left (_rc, msg) -> E.throw $ RegexException msg++-- functions to marshall bytestrings to text++encodeToText :: BS.ByteString -> Text.Text+encodeToText = TE.decodeUtf8 . Base64.encode++decodeFromText :: (Monad m) => Text.Text -> m BS.ByteString+decodeFromText = either fail return . Base64.decode . TE.encodeUtf8
src/Skylighting/Styles.hs view
@@ -49,10 +49,10 @@ , ( ExtensionTok, defStyle { tokenColor = Just (RGB 0 149 255), tokenBold = True }) , ( PreprocessorTok, defStyle { tokenColor = Just (RGB 0 110 40) }) , ( AttributeTok, defStyle { tokenColor = Just (RGB 0 87 174) })- , ( RegionMarkerTok, defStyle { tokenColor = Just (RGB 0 87 174) })+ , ( RegionMarkerTok, defStyle { tokenColor = Just (RGB 0 87 174), tokenBackground = Just (RGB 224 233 248)} ) , ( InformationTok, defStyle { tokenColor = Just (RGB 176 128 0) }) , ( WarningTok, defStyle { tokenColor = Just (RGB 191 3 3) })- , ( AlertTok, defStyle { tokenColor = Just (RGB 191 3 3), tokenBold = True })+ , ( AlertTok, defStyle { tokenColor = Just (RGB 191 3 3), tokenBackground = Just (RGB 247 230 230), tokenBold = True }) , ( ErrorTok, defStyle { tokenColor = Just (RGB 191 3 3), tokenUnderline = True }) , ( NormalTok, defStyle { tokenColor = Just (RGB 31 28 27) }) ]
src/Skylighting/Types.hs view
@@ -66,6 +66,10 @@ instance Binary KeywordAttr +instance ToJSON KeywordAttr where+ toEncoding = genericToEncoding defaultOptions+instance FromJSON KeywordAttr+ -- | A set of "words," possibly case insensitive. data WordSet a = CaseSensitiveWords (Set.Set a) | CaseInsensitiveWords (Set.Set a)@@ -73,6 +77,10 @@ instance Binary a => Binary (WordSet a) +instance ToJSON a => ToJSON (WordSet a) where+ toEncoding = genericToEncoding defaultOptions+instance (FromJSON a, Ord a) => FromJSON (WordSet a)+ -- | A set of words to match (either case-sensitive or case-insensitive). makeWordSet :: (FoldCase a, Ord a) => Bool -> [a] -> WordSet a makeWordSet True ws = CaseSensitiveWords (Set.fromList ws)@@ -105,6 +113,10 @@ | DetectIdentifier deriving (Show, Read, Eq, Ord, Data, Typeable, Generic) +instance ToJSON Matcher where+ toEncoding = genericToEncoding defaultOptions+instance FromJSON Matcher+ instance Binary Matcher -- | A context switch, either pops or pushes a context.@@ -114,6 +126,10 @@ instance Binary ContextSwitch +instance ToJSON ContextSwitch where+ toEncoding = genericToEncoding defaultOptions+instance FromJSON ContextSwitch+ -- | A rule corresponds to one of the elements of a Kate syntax -- highlighting "context." data Rule = Rule{@@ -131,6 +147,10 @@ instance Binary Rule +instance ToJSON Rule where+ toEncoding = genericToEncoding defaultOptions+instance FromJSON Rule+ -- | A syntax corresponds to a complete Kate syntax description. -- The 'sShortname' field is derived from the filename. data Syntax = Syntax{@@ -147,6 +167,10 @@ instance Binary Syntax +instance ToJSON Syntax where+ toEncoding = genericToEncoding defaultOptions+instance FromJSON Syntax+ -- | A map of syntaxes, keyed by full name. type SyntaxMap = Map.Map Text Syntax @@ -167,6 +191,10 @@ instance Binary Context +instance ToJSON Context where+ toEncoding = genericToEncoding defaultOptions+instance FromJSON Context+ -- | A pair consisting of a list of attributes and some text. type Token = (TokenType, Text) @@ -207,6 +235,9 @@ instance Binary TokenType +instance ToJSON TokenType where+ toEncoding t = toEncoding (Text.stripSuffix "Tok" $ Text.pack $ show t)+ -- | JSON @"Keyword"@ corresponds to 'KeywordTok', and so on. instance FromJSON TokenType where parseJSON (String t) =@@ -237,16 +268,23 @@ instance FromJSON TokenStyle where parseJSON (Object v) = do tcolor <- v .:? "text-color"+ bg <- v .:? "background-color" tbold <- v .:? "bold" .!= False titalic <- v .:? "italic" .!= False tunderline <- v .:? "underline" .!= False return TokenStyle{ tokenColor = tcolor- , tokenBackground = Nothing+ , tokenBackground = bg , tokenBold = tbold , tokenItalic = titalic , tokenUnderline = tunderline } parseJSON _ = mempty+instance ToJSON TokenStyle where+ toJSON ts = object [ "text-color" .= tokenColor ts+ , "background-color" .= tokenBackground ts+ , "bold" .= tokenBold ts+ , "italic" .= tokenItalic ts+ , "underline" .= tokenUnderline ts ] -- | Default style. defStyle :: TokenStyle@@ -296,6 +334,9 @@ parseJSON (String t) = maybe mempty return $ toColor (Text.unpack t) parseJSON _ = mempty +instance ToJSON Color where+ toJSON color = String (Text.pack (fromColor color :: String))+ -- | Different representations of a 'Color'. class FromColor a where fromColor :: Color -> a@@ -341,6 +382,13 @@ Map.mapKeys (\s -> maybe OtherTok id $ readMay (Text.unpack s ++ "Tok")) tokstyles } parseJSON _ = mempty++instance ToJSON Style where+ toJSON s = object [ "text-styles" .= toJSON (tokenStyles s)+ , "background-color" .= toJSON (backgroundColor s)+ , "text-color" .= toJSON (defaultColor s)+ , "line-numbers" .= toJSON (lineNumberColor s)+ ] -- | Options for formatting source code. data FormatOptions = FormatOptions{