packages feed

pandoc-crossref 0.1.3.0 → 0.1.4.0

raw patch · 4 files changed

+24/−11 lines, 4 files

Files

pandoc-crossref.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                pandoc-crossref-version:             0.1.3.0+version:             0.1.4.0 synopsis:            Pandoc filter for cross-references description:         pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them. license:             GPL-2@@ -23,7 +23,7 @@ source-repository this   type: git   location: https://github.com/lierdakil/pandoc-crossref-  tag: v0.1.3.0+  tag: v0.1.4.0  executable pandoc-crossref   main-is:             pandoc-crossref.hs
pandoc-crossref.hs view
@@ -17,7 +17,7 @@   dtv <- getSettings meta   let     doWalk =-      bottomUpM (codeBlockCaptions opts) bs+      bottomUpM (codeBlockCaptions opts) (walk divBlocks bs)       >>= walkM (replaceBlocks opts)       >>= bottomUpM (replaceRefs opts)       >>= bottomUpM (listOf opts)
src/References/Blocks.hs view
@@ -1,4 +1,4 @@-module References.Blocks (replaceBlocks) where+module References.Blocks (divBlocks, replaceBlocks) where  import Text.Pandoc.Definition import Text.Pandoc.Builder (text, toList)@@ -30,8 +30,8 @@         in r{curChap=cc'}       when ("sec:" `isPrefixOf` label') $ replaceAttrSec label' text' secRefs'     return $ Header n (label', cls, attrs) text'-replaceBlocks opts (Para (Image alt img:c))-  | Just label <- getRefLabel "fig" c+replaceBlocks opts (Div (label,_,_) [Plain [Image alt img]])+  | "fig:" `isPrefixOf` label   = do     idxStr <- replaceAttr opts label alt imgRefs'     let alt' = case outFormat opts of@@ -39,8 +39,8 @@             RawInline (Format "tex") ("\\label{"++label++"}") : alt           _  -> applyTemplate idxStr alt $ figureTemplate opts     return $ Para [Image alt' (fst img,"fig:")]-replaceBlocks opts (Para (Math DisplayMath eq:c))-  | Just label <- getRefLabel "eq" c+replaceBlocks opts (Div (label,_,_) [Plain [Math DisplayMath eq]])+  | "eq:" `isPrefixOf` label   = case outFormat opts of       f | isFormat "latex" f ->         let eqn = "\\begin{equation}"++eq++"\\label{"++label++"}\\end{equation}"@@ -49,9 +49,9 @@         idxStr <- replaceAttr opts label [] eqnRefs'         let eq' = eq++"\\qquad("++stringify idxStr++")"         return $ Para [Math DisplayMath eq']-replaceBlocks opts (Table title align widths header cells)+replaceBlocks opts (Div (label,_,_) [Table title align widths header cells])   | not $ null title-  , Just label <- getRefLabel "tbl" [last title]+  , "tbl:" `isPrefixOf` label   = do     idxStr <- replaceAttr opts label (init title) tblRefs'     let title' =@@ -110,6 +110,19 @@           , CodeBlock ([], classes, attrs) code           ] replaceBlocks _ x = return x++divBlocks :: Block -> Block+divBlocks (Para (Image alt img:c))+  | Just label <- getRefLabel "fig" c+  = Div (label,[],[]) [Plain [Image alt (fst img, "fig:")]]+divBlocks (Para (math@(Math DisplayMath _eq):c))+  | Just label <- getRefLabel "eq" c+  = Div (label,[],[]) [Plain [math]]+divBlocks (table@(Table title _align _widths _header _cells))+  | not $ null title+  , Just label <- getRefLabel "tbl" [last title]+  = Div (label,[],[]) [table]+divBlocks x = x  getRefLabel :: String -> [Inline] -> Maybe String getRefLabel _ [] = Nothing
test-pandoc-crossref.hs view
@@ -162,7 +162,7 @@  testBlocks :: Blocks -> (Blocks, References) -> Expectation testBlocks arg res = runState (walkM (f defaultOptions) arg) def `shouldBe` res-  where f = References.Blocks.replaceBlocks+  where f = (. References.Blocks.divBlocks) . References.Blocks.replaceBlocks  testRefs :: Blocks -> References -> Blocks -> Expectation testRefs bs st res = runState (bottomUpM (References.Refs.replaceRefs defaultOptions) (toList bs)) st `shouldBe` (toList res,st)