packages feed

skylighting 0.1.0.1 → 0.1.1

raw patch · 7 files changed

+107/−51 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Skylighting.Styles: breezeDark :: Style

Files

bin/main.hs view
@@ -114,6 +114,7 @@                             "tango"      -> return tango                             "haddock"    -> return haddock                             "monochrome" -> return monochrome+                            "breeze-dark" -> return breezeDark                             _            -> err $ "Unknown style: " ++ s styleOf (_ : xs) = styleOf xs 
changelog.md view
@@ -8,3 +8,9 @@  * Fixed bug in LaTeX renderer (backslash in wrong position). +## 0.1.1    -- 2017-01-19++* Added breezeDark style, from breeze-dark.theme.+* Fixed performance bug in regex application (#1).  This gives a+  significant speedup, especially for inputs with long lines.+
skylighting.cabal view
@@ -1,5 +1,5 @@ name:                skylighting-version:             0.1.0.1+version:             0.1.1 synopsis:            syntax highlighting library description:         Skylighting is a syntax highlighting library with                      support for over one hundred languages.  It derives
src/Skylighting/Regex.hs view
@@ -50,8 +50,7 @@ compileRegex caseSensitive regexpStr =   let opts = compAnchored + compUTF8 +                if caseSensitive then 0 else compCaseless-  in  case unsafePerformIO $ compile opts (execNotEmpty)-             (BS.cons '.' regexpStr) of+  in  case unsafePerformIO $ compile opts (execNotEmpty) regexpStr of             Left (off,msg) -> E.throw $ RegexException $                         "Error compiling regex /" ++ toString regexpStr ++                         "/ at offset " ++ show off ++ "\n" ++ msg
src/Skylighting/Styles.hs view
@@ -1,7 +1,8 @@ module Skylighting.Styles (     parseTheme-  , pygments   , kate+  , breezeDark+  , pygments   , espresso   , tango   , haddock@@ -19,46 +20,6 @@ color :: Int -> Maybe Color color = toColor --- | Style based on pygments's default colors.-pygments :: Style-pygments = Style{-    backgroundColor = Nothing-  , defaultColor = Nothing-  , lineNumberColor = color 0xaaaaaa-  , lineNumberBackgroundColor = Nothing-  , tokenStyles =-    [ (KeywordTok, defStyle{ tokenColor = color 0x007020, tokenBold = True })-    , (DataTypeTok, defStyle{ tokenColor = color 0x902000 })-    , (DecValTok, defStyle{ tokenColor = color 0x40a070 })-    , (BaseNTok, defStyle{ tokenColor = color 0x40a070 })-    , (FloatTok, defStyle{ tokenColor = color 0x40a070 })-    , (CharTok, defStyle{ tokenColor = color 0x4070a0 })-    , (StringTok, defStyle{ tokenColor = color 0x4070a0 })-    , (CommentTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True })-    , (OtherTok, defStyle{ tokenColor = color 0x007020 })-    , (AlertTok, defStyle{ tokenColor = color 0xff0000, tokenBold = True })-    , (FunctionTok, defStyle{ tokenColor = color 0x06287e })-    , (ErrorTok, defStyle{ tokenColor = color 0xff0000, tokenBold = True })-    , (WarningTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })-    , (ConstantTok, defStyle{ tokenColor = color 0x880000 })-    , (SpecialCharTok, defStyle{ tokenColor = color 0x4070a0 })-    , (VerbatimStringTok, defStyle{ tokenColor = color 0x4070a0 })-    , (SpecialStringTok, defStyle{ tokenColor = color 0xBB6688 })-    , (ImportTok, defStyle)-    , (VariableTok, defStyle{ tokenColor = color 0x19177C })-    , (ControlFlowTok, defStyle{ tokenColor = color 0x007020, tokenBold = True })-    , (OperatorTok, defStyle{ tokenColor = color 0x666666 })-    , (BuiltInTok, defStyle)-    , (ExtensionTok, defStyle)-    , (PreprocessorTok, defStyle{ tokenColor = color 0xBC7A00 })-    , (AttributeTok, defStyle{ tokenColor = color 0x7D9029 })-    , (DocumentationTok, defStyle{ tokenColor = color 0xBA2121, tokenItalic = True })-    , (AnnotationTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })-    , (CommentVarTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })-    , (InformationTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })-    ]-  }- -- | Style based on kate's default colors. kate :: Style kate = Style{@@ -100,6 +61,89 @@     , lineNumberColor = Just (RGB 160 160 160)     , lineNumberBackgroundColor = Just (RGB 255 255 255)     }++-- | Style from the breeze-dark KDE syntax highlighting theme.+breezeDark :: Style+breezeDark = Style+    { tokenStyles =+        [ ( KeywordTok, defStyle { tokenColor = Just (RGB 207 207 194) })+        , ( DataTypeTok, defStyle { tokenColor = Just (RGB 41 128 185) })+        , ( DecValTok, defStyle { tokenColor = Just (RGB 246 116 0) })+        , ( BaseNTok, defStyle { tokenColor = Just (RGB 246 116 0) })+        , ( FloatTok, defStyle { tokenColor = Just (RGB 246 116 0) })+        , ( ConstantTok, defStyle { tokenColor = Just (RGB 39 174 174) })+        , ( CharTok, defStyle { tokenColor = Just (RGB 61 174 233) })+        , ( SpecialCharTok, defStyle { tokenColor = Just (RGB 61 174 233) })+        , ( StringTok, defStyle { tokenColor = Just (RGB 244 79 79) })+        , ( VerbatimStringTok, defStyle { tokenColor = Just (RGB 218 68 83) })+        , ( SpecialStringTok, defStyle { tokenColor = Just (RGB 218 68 83) })+        , ( ImportTok, defStyle { tokenColor = Just (RGB 39 174 96) })+        , ( CommentTok, defStyle { tokenColor = Just (RGB 122 124 125) })+        , ( DocumentationTok, defStyle { tokenColor = Just (RGB 164 51 64) })+        , ( AnnotationTok, defStyle { tokenColor = Just (RGB 63 128 88) })+        , ( CommentVarTok, defStyle { tokenColor = Just (RGB 127 140 141) })+        , ( OtherTok, defStyle { tokenColor = Just (RGB 39 174 96) })+        , ( FunctionTok, defStyle { tokenColor = Just (RGB 142 68 173) })+        , ( VariableTok, defStyle { tokenColor = Just (RGB 39 174 174) })+        , ( ControlFlowTok, defStyle { tokenColor = Just (RGB 253 188 75) })+        , ( OperatorTok, defStyle { tokenColor = Just (RGB 207 207 194) })+        , ( BuiltInTok, defStyle { tokenColor = Just (RGB 127 140 141) })+        , ( ExtensionTok, defStyle { tokenColor = Just (RGB 0 153 255) })+        , ( PreprocessorTok, defStyle { tokenColor = Just (RGB 39 174 96) })+        , ( AttributeTok, defStyle { tokenColor = Just (RGB 41 128 185) })+        , ( RegionMarkerTok, defStyle { tokenColor = Just (RGB 41 128 185) })+        , ( InformationTok, defStyle { tokenColor = Just (RGB 196 91 0) })+        , ( WarningTok, defStyle { tokenColor = Just (RGB 218 68 83) })+        , ( AlertTok, defStyle { tokenColor = Just (RGB 149 218 76) })+        , ( ErrorTok, defStyle { tokenColor = Just (RGB 218 68 83) })+        , ( NormalTok, defStyle { tokenColor = Just (RGB 207 207 194) })+        ]+    , defaultColor = Just (RGB 207 207 194)+    , backgroundColor = Just (RGB 35 38 41)+    , lineNumberColor = Just (RGB 122 124 125)+    , lineNumberBackgroundColor = Just (RGB 35 38 41)+    }++-- | Style based on pygments's default colors.+pygments :: Style+pygments = Style{+    backgroundColor = Nothing+  , defaultColor = Nothing+  , lineNumberColor = color 0xaaaaaa+  , lineNumberBackgroundColor = Nothing+  , tokenStyles =+    [ (KeywordTok, defStyle{ tokenColor = color 0x007020, tokenBold = True })+    , (DataTypeTok, defStyle{ tokenColor = color 0x902000 })+    , (DecValTok, defStyle{ tokenColor = color 0x40a070 })+    , (BaseNTok, defStyle{ tokenColor = color 0x40a070 })+    , (FloatTok, defStyle{ tokenColor = color 0x40a070 })+    , (CharTok, defStyle{ tokenColor = color 0x4070a0 })+    , (StringTok, defStyle{ tokenColor = color 0x4070a0 })+    , (CommentTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True })+    , (OtherTok, defStyle{ tokenColor = color 0x007020 })+    , (AlertTok, defStyle{ tokenColor = color 0xff0000, tokenBold = True })+    , (FunctionTok, defStyle{ tokenColor = color 0x06287e })+    , (ErrorTok, defStyle{ tokenColor = color 0xff0000, tokenBold = True })+    , (WarningTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })+    , (ConstantTok, defStyle{ tokenColor = color 0x880000 })+    , (SpecialCharTok, defStyle{ tokenColor = color 0x4070a0 })+    , (VerbatimStringTok, defStyle{ tokenColor = color 0x4070a0 })+    , (SpecialStringTok, defStyle{ tokenColor = color 0xBB6688 })+    , (ImportTok, defStyle)+    , (VariableTok, defStyle{ tokenColor = color 0x19177C })+    , (ControlFlowTok, defStyle{ tokenColor = color 0x007020, tokenBold = True })+    , (OperatorTok, defStyle{ tokenColor = color 0x666666 })+    , (BuiltInTok, defStyle)+    , (ExtensionTok, defStyle)+    , (PreprocessorTok, defStyle{ tokenColor = color 0xBC7A00 })+    , (AttributeTok, defStyle{ tokenColor = color 0x7D9029 })+    , (DocumentationTok, defStyle{ tokenColor = color 0xBA2121, tokenItalic = True })+    , (AnnotationTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })+    , (CommentVarTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })+    , (InformationTok, defStyle{ tokenColor = color 0x60a0b0, tokenItalic = True, tokenBold = True })+    ]+  }+  -- | Style based on pygments's tango colors. tango :: Style
src/Skylighting/Tokenizer.hs view
@@ -403,14 +403,19 @@                  $ reCompiled re   inp <- gets input   prev <- gets prevChar-  -- we keep one preceding character, so initial \b can match:-  let target = encodeUtf8 $-               if prev == '\n'-                  then Text.cons ' ' inp-                  else Text.cons prev inp+  -- If regex starts with \b, determine if we're at a word+  -- boundary and mzero if not (TODO - is this the correct+  -- definition of a word boundary?)+  when (BS.take 2 reStr == "\\b") $+       case Text.uncons inp of+            Nothing -> return ()+            Just (c, _)+              | isAlphaNum prev -> guard (not (isAlphaNum c))+              | otherwise ->       guard (isAlphaNum c)+  let target = encodeUtf8 inp   case matchRegex regex target of        Just (match:capts) -> do-         match' <- decodeBS $ BS.drop 1 match -- drop the prevchar+         match' <- decodeBS match          capts' <- mapM decodeBS capts          modify $ \st -> st{ captures = capts' }          takeChars (Text.length match')
test/expected/abc.python.native view
@@ -39,7 +39,8 @@   , ( NormalTok , ":i] " )   , ( OperatorTok , "+" )   , ( NormalTok , " b[i" )-  , ( DecValTok , "+1" )+  , ( OperatorTok , "+" )+  , ( DecValTok , "1" )   , ( NormalTok , ":])" )   ] , [ ( NormalTok , "            " )