packages feed

pandoc-stylefrommeta 0.2.1.1 → 0.2.2.0

raw patch · 4 files changed

+65/−17 lines, 4 files

Files

Changelog.md view
@@ -1,3 +1,7 @@+### 0.2.2.0++- Updated after Pandoc *2.8* and the *String-to-Text* migration.+ ### 0.2.1.0  - Ensure that *para_style* is always found (different versions of Pandoc may
README.md view
@@ -1,6 +1,8 @@ styleFromMeta ============= +[![Hackage](https://img.shields.io/hackage/v/pandoc-stylefrommeta)](https://hackage.haskell.org/package/pandoc-stylefrommeta)+ Pandoc filter to apply styles found in the metadata of the document to various objects. 
pandoc-stylefrommeta.cabal view
@@ -1,5 +1,5 @@ name:                    pandoc-stylefrommeta-version:                 0.2.1.1+version:                 0.2.2.0 synopsis:                Pandoc filter to customize links, images and paragraphs description:             Pandoc filter to customize links, images and paragraphs         (with restrictions). Styles are read from the metadata of the document:
styleFromMeta.hs view
@@ -1,11 +1,17 @@ {-# LANGUAGE ViewPatterns, PatternGuards, PatternSynonyms #-} +#if MIN_VERSION_pandoc_types(1,20,0)+{-# LANGUAGE OverloadedStrings #-}+#endif+ import           Text.Pandoc.JSON import           Text.Pandoc.Walk (walk) import           Text.Pandoc.Options (def) import           Text.Pandoc.Shared (stringify) import qualified Data.Map as M+#if !MIN_VERSION_pandoc_types(1,20,0) import           Data.String.Utils (replace)+#endif  #if MIN_VERSION_pandoc(2,0,0) import           Text.Pandoc.Writers (Writer (..), getWriter)@@ -17,18 +23,53 @@ import           Text.Pandoc (Writer (..), getWriter) #endif +#if MIN_VERSION_pandoc(2,8,0)+import           Text.Pandoc.Class (PandocPure)+import           Text.Pandoc.Error (PandocError)+#endif++#if MIN_VERSION_pandoc_types(1,20,0)+type STRING = T.Text+rEPLACE :: STRING -> STRING -> STRING -> STRING+rEPLACE = T.replace+tOSTRING :: T.Text -> String+tOSTRING = T.unpack+fROMSTRING :: String -> T.Text+fROMSTRING = T.pack+tOTEXT :: T.Text -> T.Text+tOTEXT = id+#else+type STRING = String+rEPLACE :: STRING -> STRING -> STRING -> STRING+rEPLACE = replace+tOSTRING :: String -> String+tOSTRING = id+fROMSTRING :: String -> String+fROMSTRING = id+tOTEXT :: T.Text -> String+tOTEXT = T.unpack+#endif++#if MIN_VERSION_pandoc(2,8,0)+rUNGETWRITER :: PandocPure a -> Either PandocError a+rUNGETWRITER = runPure+#else+rUNGETWRITER :: a -> a+rUNGETWRITER = id+#endif+ #if MIN_TOOL_VERSION_ghc(7,10,1)-pattern Style :: String -> Inline+pattern Style :: STRING -> Inline #endif pattern Style x <- Math InlineMath x  #if MIN_TOOL_VERSION_ghc(7,10,1)-pattern Subst :: String -> Inline+pattern Subst :: STRING -> Inline #endif pattern Subst x = Math InlineMath x  #if MIN_TOOL_VERSION_ghc(7,10,1)-pattern SubstVerbatim :: String -> Inline+pattern SubstVerbatim :: STRING -> Inline #endif pattern SubstVerbatim x <- Math DisplayMath x @@ -37,7 +78,7 @@ #endif pattern Alt x <- (dropWhile (== Space) -> x) -type MMap = M.Map String MetaValue+type MMap = M.Map STRING MetaValue type PureInlineParams = ([Inline], Target)          -- style:(alt, target) type InlineParams = (Inline, [Inline], Target)      -- (style:alt, target) type InlineCons = [Inline] -> Target -> Inline      -- Image or Link@@ -110,9 +151,9 @@     substParamsInRawBlock fm params s substParams _  _               i                       = i -substParamsInRawBlock :: Format -> PureInlineParams -> String -> String+substParamsInRawBlock :: Format -> PureInlineParams -> STRING -> STRING substParamsInRawBlock fm (alt, (src, title)) s =-    foldr (\(p, is) -> replace p $ renderInlines fm is) s+    foldr (\(p, is) -> rEPLACE p $ renderInlines fm is) s           [("$ALT$",     alt                                           )           ,("$SRC$",     [Str src]                                     )           ,("$TITLE$",   [Str title]                                   )@@ -121,31 +162,32 @@           ,("$$TITLE$$", [RawInline fm title]                          )           ] -renderBlocks :: Format -> [Block] -> String+renderBlocks :: Format -> [Block] -> STRING renderBlocks fm p =     let fmt = toWriterFormat fm         writer = getWriter fmt         doc = Pandoc (Meta M.empty) p-    in case writer of-        Left _ -> error $ "Unknown format " ++ fmt+    in case rUNGETWRITER writer of+        Left _ -> error $ "Unknown format " ++ tOSTRING fmt #if MIN_VERSION_pandoc(2,0,0)         Right (TextWriter w, _) ->             case runPure $ w def doc of-                Left e -> displayException e-                Right r -> T.unpack r+                Left e -> fROMSTRING $ displayException e+                Right r -> tOTEXT r         Right (ByteStringWriter w, _) ->             case runPure $ w def doc of-                Left e -> displayException e-                Right r -> C8L.unpack r+                Left e -> fROMSTRING $ displayException e+                Right r -> fROMSTRING $ C8L.unpack r #else         Right (PureStringWriter w) -> w def doc-        _ -> error $ "Unsupported format " ++ fmt ++ ", try Pandoc 2.0!"+        _ -> error $ "Unsupported format " ++ tOSTRING fmt +++            ", use Pandoc 2.0 or newer!" #endif -renderInlines :: Format -> [Inline] -> String+renderInlines :: Format -> [Inline] -> STRING renderInlines fm p = renderBlocks fm [Plain p] -toWriterFormat :: Format -> String+toWriterFormat :: Format -> STRING toWriterFormat (Format "tex") = "latex" toWriterFormat (Format fmt)   = fmt