highlighting-kate 0.5.14 → 0.5.15
raw patch · 5 files changed
+178/−176 lines, 5 filesnew-component:exe:highlighting-katePVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +7/−11
- changelog +7/−1
- extra/Highlight.hs +0/−160
- extra/highlighting-kate.hs +160/−0
- highlighting-kate.cabal +4/−4
README.md view
@@ -133,10 +133,6 @@ which generates some of the needed source files from xml syntax definitions. -If you get a linking error with GHC 7 on Mac OS X, "scattered reloc r_address-too large for inferred architecture i386," the workaround is to use the flag-`--disable-library-for-ghci` when you `cabal install`.- To generate the documentation: cabal haddock@@ -145,21 +141,21 @@ cabal test -For an example of the use of the library, see Highlight.hs.+For an example of the use of the library, see highlighting-kate.hs. To compile this program along with the library, specify the 'executable' flag in the configure step above: cabal install -fexecutable -To run Highlight, specify the language name using -s:+To run `highlighting-kate`, specify the language name using -s: - Highlight -s haskell Highlight.hs > example.html+ highlighting-kate -s haskell highlighting-kate.hs > example.html -If you don't specify a language name, Highlight will try to guess it-from the file extension. Highlight can also be used as a pipe, reading-input from STDIN. For other options,+If you don't specify a language name, `highlighting-kate` will try to guess it+from the file extension.`highlighting-kate` can also be used as a pipe,+reading input from STDIN. For other options, - Highlight --help+ highlighting-kate --help Styling is done using span tags. The Highlight program will include default styles in the generated HTML, unless a link to a CSS file is
changelog view
@@ -1,3 +1,9 @@+highlighting-kate 0.5.15 (25 Apr 2015)++ * Rename `Highlight` utility and `Highlight.hs` to `highlighting-kate` and+ `highlighting-kate.hs` to avoid naming conflicts with other syntax+ highlighting utilities.+ highlighting-kate 0.5.14 (28 Mar 2015) * Put code blocks in a div. This reverts the change in 0.5.13,@@ -17,7 +23,7 @@ blocks must have a fixed minimal width, making them hard to read on narrower screens. - Wrapping the table in a pre block allows formating of code+ Wrapping the table in a pre block allows formatting of code blocks to have a horizontal scroll bar if the content doesn't fit the screen width, by adding the following style:
− extra/Highlight.hs
@@ -1,160 +0,0 @@-{-# LANGUAGE CPP, OverloadedStrings #-}-module Main where-import Text.Highlighting.Kate-import System.IO (hPutStrLn, stderr)-import System.Environment-import System.Console.GetOpt-import System.Exit-import System.FilePath (takeFileName)-import Data.Maybe (listToMaybe)-import Data.Char (toLower)-#if MIN_VERSION_blaze_html(0,5,0)-import Text.Blaze.Html-import Text.Blaze.Html.Renderer.String-#else-import Text.Blaze-import Text.Blaze.Renderer.String-#endif-import qualified Text.Blaze.Html5 as H-import qualified Text.Blaze.Html5.Attributes as A--data Flag = Sty String- | Format String- | Help- | Fragment- | List- | NumberLines- | Syntax String- | TitleAttributes- | Version- deriving (Eq, Show)--options :: [OptDescr Flag]-options =- [ Option ['S'] ["style"] (ReqArg Sty "STYLE") "specify style"- , Option ['F'] ["format"] (ReqArg Format "FORMAT") "output format (html|latex)"- , Option ['f'] ["fragment"] (NoArg Fragment) "fragment, without document header"- , Option ['h'] ["help"] (NoArg Help) "show usage message"- , Option ['l'] ["list"] (NoArg List) "list available language syntaxes"- , Option ['n'] ["number-lines"] (NoArg NumberLines) "number lines"- , Option ['s'] ["syntax"] (ReqArg Syntax "SYNTAX") "specify language syntax to use"- , Option ['t'] ["title-attributes"] (NoArg TitleAttributes) "include structure in title attributes"- , Option ['v'] ["version"] (NoArg Version) "print version"- ]--syntaxOf :: [Flag] -> Maybe String-syntaxOf [] = Nothing-syntaxOf (Syntax s : _) = Just s-syntaxOf (_:xs) = syntaxOf xs--styleOf :: [Flag] -> Maybe Style-styleOf [] = Nothing-styleOf (Sty s : _) = case map toLower s of- "pygments" -> Just pygments- "espresso" -> Just espresso- "kate" -> Just kate- "tango" -> Just tango- "haddock" -> Just haddock- "monochrome" -> Just monochrome- _ -> error $ "Unknown style: " ++ s-styleOf (_ : xs) = styleOf xs--formatOf :: [Flag] -> String-formatOf [] = "html" -- default-formatOf (Format s : _) = case map toLower s of- "html" -> "html"- "latex" -> "latex"- _ -> error $ "Unknown format: " ++ s-formatOf (_ : xs) = formatOf xs--filterNewlines :: String -> String-filterNewlines ('\r':'\n':xs) = '\n' : filterNewlines xs-filterNewlines ('\r':xs) = '\n' : filterNewlines xs-filterNewlines (x:xs) = x : filterNewlines xs-filterNewlines [] = []--main = do- (opts, fnames, errs) <- getArgs >>= return . getOpt Permute options- prg <- getProgName- let usageHeader = prg ++ " [options] [files...]"- if not (null errs)- then ioError (userError $ concat errs ++ usageInfo usageHeader options)- else return ()- if List `elem` opts- then putStrLn (unwords languages) >> exitWith ExitSuccess- else return ()- if Help `elem` opts- then hPutStrLn stderr (usageInfo usageHeader options) >> - exitWith (ExitFailure 1)- else return ()- if Version `elem` opts- then putStrLn (prg ++ " " ++ highlightingKateVersion ++ " - (c) 2008 John MacFarlane") >> - exitWith ExitSuccess- else return ()- code <- if null fnames- then getContents >>= return . filterNewlines- else mapM readFile fnames >>= return . filterNewlines . concat- let lang' = case syntaxOf opts of- Just e -> Just e- Nothing -> case fnames of- [] -> Nothing- (x:_) -> listToMaybe $ languagesByFilename $ takeFileName x- lang <- if lang' == Nothing- then hPutStrLn stderr "No syntax specified." >>- hPutStrLn stderr (usageInfo usageHeader options) >>- exitWith (ExitFailure 5)- else do let (Just l) = lang'- return (map toLower l)- if not (lang `elem` (map (map toLower) languages))- then hPutStrLn stderr ("Unknown syntax: " ++ lang) >> exitWith (ExitFailure 4)- else return ()- let highlightOpts = defaultFormatOpts{ titleAttributes = TitleAttributes `elem` opts- , numberLines = NumberLines `elem` opts- , lineAnchors = NumberLines `elem` opts- }- let fragment = Fragment `elem` opts- let fname = case fnames of- [] -> ""- (x:_) -> x- case formatOf opts of- "html" -> hlHtml fragment fname highlightOpts (maybe pygments id $ styleOf opts)- lang code- "latex" -> hlLaTeX fragment fname highlightOpts (maybe pygments id $ styleOf opts) lang code- x -> error $ "Uknown format " ++ x--hlHtml :: Bool -- ^ Fragment- -> FilePath -- ^ Filename- -> FormatOptions- -> Style- -> String -- ^ language- -> String -- ^ code- -> IO ()-hlHtml frag fname opts sty lang code =- if frag- then putStrLn $ renderHtml fragment- else putStrLn $ renderHtml $ H.head (pageTitle >> metadata >> css) >> H.body (toHtml fragment)- where fragment = formatHtmlBlock opts $ highlightAs lang code- css = H.style ! A.type_ "text/css" $ toHtml $ styleToCss sty- pageTitle = H.title $ toHtml fname- metadata = H.meta ! A.httpEquiv "Content-Type" ! A.content "text/html; charset=UTF-8" >>- H.meta ! A.name "generator" ! A.content "highlight-kate"--hlLaTeX :: Bool -- ^ Fragment- -> FilePath -- ^ Filename- -> FormatOptions- -> Style- -> String -- ^ language- -> String -- ^ code- -> IO ()-hlLaTeX frag fname opts sty lang code =- if frag- then putStrLn fragment- else putStrLn $ "\\documentclass{article}\n\\usepackage[margin=1in]{geometry}\n" ++- macros ++ pageTitle ++- "\n\\begin{document}\n\\maketitle\n" ++ fragment ++ "\n\\end{document}"- where fragment = formatLaTeXBlock opts $ highlightAs lang code- macros = styleToLaTeX sty- pageTitle = "\\title{" ++ fname ++ "}\n"---
+ extra/highlighting-kate.hs view
@@ -0,0 +1,160 @@+{-# LANGUAGE CPP, OverloadedStrings #-}+module Main where+import Text.Highlighting.Kate+import System.IO (hPutStrLn, stderr)+import System.Environment+import System.Console.GetOpt+import System.Exit+import System.FilePath (takeFileName)+import Data.Maybe (listToMaybe)+import Data.Char (toLower)+#if MIN_VERSION_blaze_html(0,5,0)+import Text.Blaze.Html+import Text.Blaze.Html.Renderer.String+#else+import Text.Blaze+import Text.Blaze.Renderer.String+#endif+import qualified Text.Blaze.Html5 as H+import qualified Text.Blaze.Html5.Attributes as A++data Flag = Sty String+ | Format String+ | Help+ | Fragment+ | List+ | NumberLines+ | Syntax String+ | TitleAttributes+ | Version+ deriving (Eq, Show)++options :: [OptDescr Flag]+options =+ [ Option ['S'] ["style"] (ReqArg Sty "STYLE") "specify style"+ , Option ['F'] ["format"] (ReqArg Format "FORMAT") "output format (html|latex)"+ , Option ['f'] ["fragment"] (NoArg Fragment) "fragment, without document header"+ , Option ['h'] ["help"] (NoArg Help) "show usage message"+ , Option ['l'] ["list"] (NoArg List) "list available language syntaxes"+ , Option ['n'] ["number-lines"] (NoArg NumberLines) "number lines"+ , Option ['s'] ["syntax"] (ReqArg Syntax "SYNTAX") "specify language syntax to use"+ , Option ['t'] ["title-attributes"] (NoArg TitleAttributes) "include structure in title attributes"+ , Option ['v'] ["version"] (NoArg Version) "print version"+ ]++syntaxOf :: [Flag] -> Maybe String+syntaxOf [] = Nothing+syntaxOf (Syntax s : _) = Just s+syntaxOf (_:xs) = syntaxOf xs++styleOf :: [Flag] -> Maybe Style+styleOf [] = Nothing+styleOf (Sty s : _) = case map toLower s of+ "pygments" -> Just pygments+ "espresso" -> Just espresso+ "kate" -> Just kate+ "tango" -> Just tango+ "haddock" -> Just haddock+ "monochrome" -> Just monochrome+ _ -> error $ "Unknown style: " ++ s+styleOf (_ : xs) = styleOf xs++formatOf :: [Flag] -> String+formatOf [] = "html" -- default+formatOf (Format s : _) = case map toLower s of+ "html" -> "html"+ "latex" -> "latex"+ _ -> error $ "Unknown format: " ++ s+formatOf (_ : xs) = formatOf xs++filterNewlines :: String -> String+filterNewlines ('\r':'\n':xs) = '\n' : filterNewlines xs+filterNewlines ('\r':xs) = '\n' : filterNewlines xs+filterNewlines (x:xs) = x : filterNewlines xs+filterNewlines [] = []++main = do+ (opts, fnames, errs) <- getArgs >>= return . getOpt Permute options+ prg <- getProgName+ let usageHeader = prg ++ " [options] [files...]"+ if not (null errs)+ then ioError (userError $ concat errs ++ usageInfo usageHeader options)+ else return ()+ if List `elem` opts+ then putStrLn (unwords languages) >> exitWith ExitSuccess+ else return ()+ if Help `elem` opts+ then hPutStrLn stderr (usageInfo usageHeader options) >> + exitWith (ExitFailure 1)+ else return ()+ if Version `elem` opts+ then putStrLn (prg ++ " " ++ highlightingKateVersion ++ " - (c) 2008 John MacFarlane") >> + exitWith ExitSuccess+ else return ()+ code <- if null fnames+ then getContents >>= return . filterNewlines+ else mapM readFile fnames >>= return . filterNewlines . concat+ let lang' = case syntaxOf opts of+ Just e -> Just e+ Nothing -> case fnames of+ [] -> Nothing+ (x:_) -> listToMaybe $ languagesByFilename $ takeFileName x+ lang <- if lang' == Nothing+ then hPutStrLn stderr "No syntax specified." >>+ hPutStrLn stderr (usageInfo usageHeader options) >>+ exitWith (ExitFailure 5)+ else do let (Just l) = lang'+ return (map toLower l)+ if not (lang `elem` (map (map toLower) languages))+ then hPutStrLn stderr ("Unknown syntax: " ++ lang) >> exitWith (ExitFailure 4)+ else return ()+ let highlightOpts = defaultFormatOpts{ titleAttributes = TitleAttributes `elem` opts+ , numberLines = NumberLines `elem` opts+ , lineAnchors = NumberLines `elem` opts+ }+ let fragment = Fragment `elem` opts+ let fname = case fnames of+ [] -> ""+ (x:_) -> x+ case formatOf opts of+ "html" -> hlHtml fragment fname highlightOpts (maybe pygments id $ styleOf opts)+ lang code+ "latex" -> hlLaTeX fragment fname highlightOpts (maybe pygments id $ styleOf opts) lang code+ x -> error $ "Uknown format " ++ x++hlHtml :: Bool -- ^ Fragment+ -> FilePath -- ^ Filename+ -> FormatOptions+ -> Style+ -> String -- ^ language+ -> String -- ^ code+ -> IO ()+hlHtml frag fname opts sty lang code =+ if frag+ then putStrLn $ renderHtml fragment+ else putStrLn $ renderHtml $ H.head (pageTitle >> metadata >> css) >> H.body (toHtml fragment)+ where fragment = formatHtmlBlock opts $ highlightAs lang code+ css = H.style ! A.type_ "text/css" $ toHtml $ styleToCss sty+ pageTitle = H.title $ toHtml fname+ metadata = H.meta ! A.httpEquiv "Content-Type" ! A.content "text/html; charset=UTF-8" >>+ H.meta ! A.name "generator" ! A.content "highlight-kate"++hlLaTeX :: Bool -- ^ Fragment+ -> FilePath -- ^ Filename+ -> FormatOptions+ -> Style+ -> String -- ^ language+ -> String -- ^ code+ -> IO ()+hlLaTeX frag fname opts sty lang code =+ if frag+ then putStrLn fragment+ else putStrLn $ "\\documentclass{article}\n\\usepackage[margin=1in]{geometry}\n" +++ macros ++ pageTitle +++ "\n\\begin{document}\n\\maketitle\n" ++ fragment ++ "\n\\end{document}"+ where fragment = formatLaTeXBlock opts $ highlightAs lang code+ macros = styleToLaTeX sty+ pageTitle = "\\title{" ++ fname ++ "}\n"+++
highlighting-kate.cabal view
@@ -1,5 +1,5 @@ Name: highlighting-kate-Version: 0.5.14+Version: 0.5.15 Cabal-Version: >= 1.10 Build-Type: Simple Category: Text@@ -85,7 +85,7 @@ Description: Choose the new, smaller, split-up base package. Default: True Flag executable- Description: Build the Highlight executable.+ Description: Build the highlighting-kate executable. Default: False Flag pcre-light Description: Use the pcre-light library instead of regex-pcre-builtin@@ -240,8 +240,8 @@ -- memory on platforms without a native code generator: Cc-Options: -O0 -Executable Highlight- Main-Is: Highlight.hs+Executable highlighting-kate+ Main-Is: highlighting-kate.hs Build-Depends: base, containers, blaze-html >= 0.4.2 && < 0.9, filepath, highlighting-kate Hs-Source-Dirs: extra