pandoc-vimhl 0.1.2.4 → 0.1.3.0
raw patch · 4 files changed
+33/−12 lines, 4 filesdep +text
Dependencies added: text
Files
- Changelog.md +4/−0
- LICENSE +1/−1
- pandoc-vimhl.cabal +3/−2
- vimhl.hs +25/−9
Changelog.md view
@@ -1,3 +1,7 @@+### 0.1.3.0++- Updated after Pandoc *2.8* and the *String-to-Text* migration.+ ### 0.1.2.4 - Removed *shebang* line as it may lead to compilation failures.
LICENSE view
@@ -1,7 +1,7 @@ The following license covers this documentation, and the source code, except where otherwise indicated. -Copyright 2016-2018, Alexey Radkov. All rights reserved.+Copyright 2016-2019, Alexey Radkov. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
pandoc-vimhl.cabal view
@@ -1,5 +1,5 @@ name: pandoc-vimhl-version: 0.1.2.4+version: 0.1.3.0 synopsis: Pandoc filter for native Vim code highlighting description: Pandoc filter for native Vim code highlighting in HTML and PDF documents. Requires Vim and plugin@@ -10,7 +10,7 @@ extra-source-files: Changelog.md author: Alexey Radkov <alexey.radkov@gmail.com> maintainer: Alexey Radkov <alexey.radkov@gmail.com>-copyright: 2016-2018 Alexey Radkov+copyright: 2016-2019 Alexey Radkov category: Text build-type: Simple cabal-version: 1.20@@ -30,6 +30,7 @@ , temporary >= 1.1 , regex-compat , cond >= 0.2+ , text default-extensions: CPP if flag(debug)
vimhl.hs view
@@ -1,8 +1,6 @@-{-# LANGUAGE CPP #-}- import Text.Pandoc.JSON import Text.Regex (mkRegex, splitRegex, matchRegexAll)-import System.IO+import System.IO (IOMode (WriteMode), openFile, hFlush) import System.IO.Temp import System.IO.Error import System.Directory@@ -11,23 +9,38 @@ import System.Exit import Data.Char (toLower) import Data.Maybe (fromMaybe)-import Control.Arrow (first, (&&&))+import Control.Arrow ((&&&), (***)) import Control.Monad #if !MIN_VERSION_base(4,8,0) import Control.Applicative #endif import Control.Exception (bracket) import Control.Conditional hiding (unless)+#if MIN_VERSION_pandoc_types(1,20,0)+import Prelude hiding (readFile)+import Data.Text.IO (readFile, hPutStr)+import Data.Text (Text, unpack)+#else+import System.IO (hPutStr)+#endif +#if MIN_VERSION_pandoc_types(1,20,0)+tOSTRING :: Text -> String+tOSTRING = unpack+#else+tOSTRING :: String -> String+tOSTRING = id+#endif+ vimHl :: Maybe Format -> Block -> IO Block vimHl (Just fm@(Format fmt)) (CodeBlock (_, cls@(ft:_), namevals) contents)- | lookup "hl" namevals' == Just "vim" && fmt `elem` ["html", "latex"] = do+ | lookup "hl" namevals' == Just "vim" && fmt' `elem` ["html", "latex"] = do let vimhlcmd =- unwords [cmd fmt, nmb]+ unwords [cmd fmt', nmb] where cmd "html" = "MakeHtmlCodeHighlight" cmd "latex" = "MakeTexCodeHighlight" cmd x = error $ "Unexpected format '" ++ x ++ "'"- nmb | "numberLines" `elem` cls =+ nmb | "numberLines" `elem` cls' = fromMaybe "-1" $ lookup "startfrom" namevals' | otherwise = "" colorscheme =@@ -58,7 +71,7 @@ let vimcmd = unwords ["vim -Nen", cmds, vimrccmd, colorscheme- ,"-c 'set ft=" ++ ft, "|"+ ,"-c 'set ft=" ++ ft', "|" ,vimhlcmd ++ "' -c 'w!", dst ++ "' -c 'qa!'" ,src ]@@ -83,7 +96,10 @@ #endif readFile dst return $ RawBlock fm block- where namevals' = map (first $ map toLower) namevals+ where fmt' = tOSTRING fmt+ cls' = map tOSTRING cls+ ft' = tOSTRING ft+ namevals' = map (map toLower . tOSTRING *** tOSTRING) namevals vimHl _ cb = return cb main :: IO ()