packages feed

pandoc-crossref 0.1.2.0 → 0.1.2.1

raw patch · 3 files changed

+33/−10 lines, 3 files

Files

pandoc-crossref.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                pandoc-crossref-version:             0.1.2.0+version:             0.1.2.1 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.2.0+  tag: v0.1.2.1  executable pandoc-crossref   main-is:             pandoc-crossref.hs
src/References/Refs.hs view
@@ -21,15 +21,16 @@     mapM replaceRefs' (groupBy eqPrefix cits)   where     eqPrefix a b = uncurry (==) $-      (uncapitalizeFirst . getLabelPrefix . citationId) <***> (a,b)+      (fmap uncapitalizeFirst . getLabelPrefix . citationId) <***> (a,b)     (<***>) = join (***)     replaceRefs' cits'       | Just prefix <- allCitsPrefix cits'       = replaceRefs'' prefix opts cits'       | otherwise = return [Cite cits' il']         where-          il' = [Str "["]-            ++intercalate [Str ";"] (map citationToInlines cits')+          il' =  normalizeInlines $+              [Str "["]+            ++intercalate [Str ";", Space] (map citationToInlines cits')             ++[Str "]"]           citationToInlines c = normalizeSpaces $             citationPrefix c ++ [Space, Str $ "@"++citationId c] ++ citationSuffix c@@ -84,7 +85,7 @@           listLabels prefix "\\ref{" ", " "}" cits     p | useCleveref opts = []       | otherwise = getRefPrefix opts prefix cap (length cits - 1)-    cap = isFirstUpper $ getLabelPrefix . citationId . head $ cits+    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . head $ cits     cref | cap = "\\Cref"          | otherwise = "\\cref" @@ -95,15 +96,18 @@ getLabelWithoutPrefix :: String -> String getLabelWithoutPrefix = drop 1 . dropWhile (/=':') -getLabelPrefix :: String -> String-getLabelPrefix = (++ ":") . takeWhile (/=':')+getLabelPrefix :: String -> Maybe String+getLabelPrefix lab+  | uncapitalizeFirst p `elem` prefixes = Just p+  | otherwise = Nothing+  where p = (++ ":") . takeWhile (/=':') $ lab  replaceRefsOther :: String -> Options -> [Citation] -> WS [Inline] replaceRefsOther prefix opts cits = do   indices <- mapM (getRefIndex prefix) cits   let     indices' = groupBy ((==) `on` (fmap fst . fst)) (sort indices)-    cap = isFirstUpper $ getLabelPrefix . citationId . head $ cits+    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . head $ cits   return $ normalizeInlines $ getRefPrefix opts prefix cap (length cits - 1) ++ concatMap (makeIndices opts) indices'  getRefIndex :: String -> Citation -> WS (Maybe (Int, Int), [Inline])
test-pandoc-crossref.hs view
@@ -17,6 +17,8 @@ import qualified Util.CodeBlockCaptions import qualified Data.Map as M import Data.Monoid+import Data.List+import Control.Arrow  main :: IO () main = hspec $ do@@ -102,8 +104,25 @@         in Util.Template.applyTemplate [Str "1"] [Str "title"] template `shouldBe`            toList (str "Figure" <> str "1" <> str "title") +    describe "Citation groups shouldn't be separated (#22 regression test)" $ do+      it "Should not separate citation groups" $ do+        let cits = para $ citeGen "" [1..3]+        testRefs cits def cits++      it "Should not separate citation groups with unknown prefix" $ do+        let cits = para $ citeGen "unk:" [1..3]+        testRefs cits def cits++      it "Should not separate citation groups with different unknown prefixes" $ do+        let cits = para $ cite (mconcat $ map (cit . uncurry (++) . second show) l) $ text $+              "[" ++ intercalate "; " (map (("@"++) . uncurry (++) . second show) l) ++ "]"+            l = zip ["unk1:", "unk2:"] [1,2::Int]+        testRefs cits def cits++ citeGen :: String -> [Int] -> Inlines-citeGen p l = cite (mconcat $ map (cit . (p++) . show) l) mempty+citeGen p l = cite (mconcat $ map (cit . (p++) . show) l) $ text $+  "[" ++ intercalate "; " (map (("@"++) . (p++) . show) l) ++ "]"  refGen :: String -> [Int] -> [Int] -> M.Map String RefRec refGen p l1 l2 = M.fromList $ mconcat $ zipWith refRec'' (((uncapitalizeFirst p++) . show) `map` l1) l2