pandoc-crossref 0.3.2.1 → 0.3.3.0
raw patch · 10 files changed
+106/−61 lines, 10 filesdep +gitrevdep ~pandoc
Dependencies added: gitrev
Dependency ranges changed: pandoc
Files
- CHANGELOG.md +7/−0
- lib/Text/Pandoc/CrossRef/References/Blocks.hs +2/−4
- lib/Text/Pandoc/CrossRef/References/List.hs +6/−3
- lib/Text/Pandoc/CrossRef/Util/Util.hs +8/−0
- pandoc-crossref.cabal +57/−47
- src/pandoc-crossref.hs +3/−0
- test/demo-chapters.inc +1/−1
- test/demo.inc +1/−1
- test/test-integrative.hs +17/−3
- test/test-pandoc-crossref.hs +4/−2
CHANGELOG.md view
@@ -1,3 +1,10 @@+## 0.3.3.0++- Hide flaky tests behind a flag+- Update for Pandoc-2.3+- Add git commit info to version output+- Handle SoftBreak consistenlty (especailly after math)+ ## 0.3.2.1 - Make compatible with pandoc-types 1.17.5
lib/Text/Pandoc/CrossRef/References/Blocks.hs view
@@ -298,10 +298,8 @@ | not $ null title , Just label <- getRefLabel "tbl" [last title] = Div (label,[],[]) [Table (dropWhileEnd isSpace $ init title) align widths header cells]- where isSpace = (||) <$> (==Space) <*> (==SoftBreak) divBlocks x = x - splitMath :: [Block] -> [Block] splitMath (Para ils:xs) | length ils > 1 = map Para (split [] [] ils) ++ xs@@ -311,12 +309,12 @@ split ([x] : reverse (dropSpaces acc) : res) [] (dropSpaces ys) split res acc (y:ys) = split res (y:acc) ys- dropSpaces = dropWhile (\x -> x == Space || x == SoftBreak)+ dropSpaces = dropWhile isSpace splitMath xs = xs spanInlines :: Options -> [Inline] -> [Inline] spanInlines opts (math@(Math DisplayMath _eq):ils)- | c:ils' <- dropWhile (==Space) ils+ | c:ils' <- dropWhile isSpace ils , Just label <- getRefLabel "eq" [c] = Span (label,[],[]) [math]:ils' | autoEqnLabels opts
lib/Text/Pandoc/CrossRef/References/List.hs view
@@ -32,11 +32,14 @@ listOf :: Options -> [Block] -> WS [Block] listOf Options{outFormat=f} x | isLatexFormat f = return x-listOf opts (RawBlock (Format "latex") "\\listoffigures":xs)+listOf opts (RawBlock fmt "\\listoffigures":xs)+ | isLaTeXRawBlockFmt fmt = get imgRefs >>= makeList opts lofTitle xs-listOf opts (RawBlock (Format "latex") "\\listoftables":xs)+listOf opts (RawBlock fmt "\\listoftables":xs)+ | isLaTeXRawBlockFmt fmt = get tblRefs >>= makeList opts lotTitle xs-listOf opts (RawBlock (Format "latex") "\\listoflistings":xs)+listOf opts (RawBlock fmt "\\listoflistings":xs)+ | isLaTeXRawBlockFmt fmt = get lstRefs >>= makeList opts lolTitle xs listOf _ x = return x
lib/Text/Pandoc/CrossRef/Util/Util.hs view
@@ -122,3 +122,11 @@ , ("{#"++tag++":") `isPrefixOf` attr = init `fmap` stripPrefix "{#" attr getRefLabel _ _ = Nothing++isSpace :: Inline -> Bool+isSpace = (||) <$> (==Space) <*> (==SoftBreak)++isLaTeXRawBlockFmt :: Format -> Bool+isLaTeXRawBlockFmt (Format "latex") = True+isLaTeXRawBlockFmt (Format "tex") = True+isLaTeXRawBlockFmt _ = False
pandoc-crossref.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 84b607174500028529fbd471156fdf6ba5b440c5a9f3862137b96e7f05a147f2+-- hash: 1d7645597fa7a4589e37c71e3fee17d3eac5b57087d212f56fb16218fd9c3803 name: pandoc-crossref-version: 0.3.2.1+version: 0.3.3.0 synopsis: Pandoc filter for cross-references description: pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them. category: Text@@ -65,27 +65,12 @@ type: git location: https://github.com/lierdakil/pandoc-crossref +flag enable_flaky_tests+ description: Some tests rely on specific behaviour of pandoc, which may change between minor versions. These are still useful indicators for the developer, but not necessarily indicating there's a problem with the package itself. Enable if you know what you are doing.+ manual: True+ default: False+ library- hs-source-dirs:- lib- ghc-options: -Wall- build-depends:- base >=4.11 && <5- , containers >=0.1 && <0.6- , data-accessor >=0.2.2.6 && <0.3.0.0- , data-accessor-template >=0.2.1.12 && <0.3.0.0- , data-accessor-transformers >=0.2.1.6 && <0.3.0.0- , data-default >=0.4 && <0.8- , directory >=1 && <1.4- , filepath >=1.1 && <1.5- , mtl >=1.1 && <2.3- , pandoc >=2.2 && <2.3- , pandoc-types ==1.17.*- , roman-numerals ==0.5.*- , syb >=0.4 && <0.8- , template-haskell >=2.7.0.0 && <3.0.0.0- , text >=1.2.2 && <1.3- , utility-ht >=0.0.11 && <0.1.0 exposed-modules: Text.Pandoc.CrossRef other-modules:@@ -105,13 +90,9 @@ Text.Pandoc.CrossRef.Util.Template Text.Pandoc.CrossRef.Util.Util Paths_pandoc_crossref- default-language: Haskell2010--executable pandoc-crossref- main-is: pandoc-crossref.hs hs-source-dirs:- src- ghc-options: -Wall -threaded+ lib+ ghc-options: -Wall build-depends: base >=4.11 && <5 , containers >=0.1 && <0.6@@ -119,32 +100,26 @@ , data-accessor-template >=0.2.1.12 && <0.3.0.0 , data-accessor-transformers >=0.2.1.6 && <0.3.0.0 , data-default >=0.4 && <0.8- , deepseq >=1.4 && <1.5 , directory >=1 && <1.4 , filepath >=1.1 && <1.5 , mtl >=1.1 && <2.3- , open-browser >=0.2 && <0.3- , optparse-applicative >=0.13 && <0.15- , pandoc >=2.2 && <2.3- , pandoc-crossref+ , pandoc >=2.3 && <2.4 , pandoc-types ==1.17.* , roman-numerals ==0.5.* , syb >=0.4 && <0.8 , template-haskell >=2.7.0.0 && <3.0.0.0- , temporary >=1.2 && <1.4 , text >=1.2.2 && <1.3 , utility-ht >=0.0.11 && <0.1.0+ default-language: Haskell2010++executable pandoc-crossref+ main-is: pandoc-crossref.hs other-modules: ManData Paths_pandoc_crossref- default-language: Haskell2010--test-suite test-integrative- type: exitcode-stdio-1.0- main-is: test-integrative.hs hs-source-dirs:- test- ghc-options: -Wall -fno-warn-unused-do-bind -threaded+ src+ ghc-options: -Wall -threaded build-depends: base >=4.11 && <5 , containers >=0.1 && <0.6@@ -152,26 +127,29 @@ , data-accessor-template >=0.2.1.12 && <0.3.0.0 , data-accessor-transformers >=0.2.1.6 && <0.3.0.0 , data-default >=0.4 && <0.8+ , deepseq >=1.4 && <1.5 , directory >=1 && <1.4 , filepath >=1.1 && <1.5- , hspec >=2.4.4 && <3+ , gitrev >=1.3.1 && <1.4 , mtl >=1.1 && <2.3- , pandoc >=2.2 && <2.3+ , open-browser >=0.2 && <0.3+ , optparse-applicative >=0.13 && <0.15+ , pandoc >=2.3 && <2.4 , pandoc-crossref , pandoc-types ==1.17.* , roman-numerals ==0.5.* , syb >=0.4 && <0.8 , template-haskell >=2.7.0.0 && <3.0.0.0+ , temporary >=1.2 && <1.4 , text >=1.2.2 && <1.3 , utility-ht >=0.0.11 && <0.1.0 default-language: Haskell2010 -test-suite test-pandoc-crossref+test-suite test-integrative type: exitcode-stdio-1.0- main-is: test-pandoc-crossref.hs+ main-is: test-integrative.hs hs-source-dirs: test- lib ghc-options: -Wall -fno-warn-unused-do-bind -threaded build-depends: base >=4.11 && <5@@ -184,13 +162,21 @@ , filepath >=1.1 && <1.5 , hspec >=2.4.4 && <3 , mtl >=1.1 && <2.3- , pandoc >=2.2 && <2.3+ , pandoc >=2.3 && <2.4+ , pandoc-crossref , pandoc-types ==1.17.* , roman-numerals ==0.5.* , syb >=0.4 && <0.8 , template-haskell >=2.7.0.0 && <3.0.0.0 , text >=1.2.2 && <1.3 , utility-ht >=0.0.11 && <0.1.0+ if flag(enable_flaky_tests)+ cpp-options: -DFLAKY+ default-language: Haskell2010++test-suite test-pandoc-crossref+ type: exitcode-stdio-1.0+ main-is: test-pandoc-crossref.hs other-modules: Native Text.Pandoc.CrossRef@@ -210,4 +196,28 @@ Text.Pandoc.CrossRef.Util.Template Text.Pandoc.CrossRef.Util.Util Paths_pandoc_crossref+ hs-source-dirs:+ test+ lib+ ghc-options: -Wall -fno-warn-unused-do-bind -threaded+ build-depends:+ base >=4.11 && <5+ , containers >=0.1 && <0.6+ , data-accessor >=0.2.2.6 && <0.3.0.0+ , data-accessor-template >=0.2.1.12 && <0.3.0.0+ , data-accessor-transformers >=0.2.1.6 && <0.3.0.0+ , data-default >=0.4 && <0.8+ , directory >=1 && <1.4+ , filepath >=1.1 && <1.5+ , hspec >=2.4.4 && <3+ , mtl >=1.1 && <2.3+ , pandoc >=2.3 && <2.4+ , pandoc-types ==1.17.*+ , roman-numerals ==0.5.*+ , syb >=0.4 && <0.8+ , template-haskell >=2.7.0.0 && <3.0.0.0+ , text >=1.2.2 && <1.3+ , utility-ht >=0.0.11 && <0.1.0+ if flag(enable_flaky_tests)+ cpp-options: -DFLAKY default-language: Haskell2010
src/pandoc-crossref.hs view
@@ -31,6 +31,7 @@ import System.IO import ManData import Control.Concurrent+import Development.GitRev man, manHtml :: String man = $(embedManualText)@@ -50,6 +51,8 @@ go :: Maybe Flag -> Maybe String -> IO () go (Just Version) _ = putStrLn $ "pandoc-crossref v" <> VERSION_pandoc_crossref+ <> " git commit " <> $gitHash+ <> " (" <> $gitBranch <> ")" <> " built with Pandoc v" <> VERSION_pandoc <> "," <> " pandoc-types v" <> VERSION_pandoc_types <> " and GHC " <> TOOL_VERSION_ghc
test/demo-chapters.inc view
@@ -44,7 +44,7 @@ ,Div ("lst:captionAttr",["listing","haskell"],[]) [Para [Str "Listing",Space,Str "4.1:",Space,Str "Listing",Space,Str "caption"] ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]- ,RawBlock (Format "latex") "\\pagebreak"+ ,RawBlock (Format "tex") "\\pagebreak" ,Header 2 ("sec:table-capts",[],[]) [Str "Table-style",Space,Str "captions"] ,Para [Str "Enabled",Space,Str "with",Space,Code ("",[],[]) "codeBlockCaptions",Space,Str "metadata",Space,Str "option.",Space,Str "If",Space,Str "code",Space,Str "block",Space,Str "is",Space,Str "immediately",SoftBreak,Str "adjacent",Space,Str "to",Space,Str "paragraph,",Space,Str "starting",Space,Str "with",Space,Code ("",[],[]) "Listing:",Space,Str "or",Space,Code ("",[],[]) ":",Str ",",Space,Str "said",Space,Str "paragraph",Space,Str "will",Space,Str "be",SoftBreak,Str "treated",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption."] ,Div ("lst:tableCaption",["listing","haskell"],[])
test/demo.inc view
@@ -44,7 +44,7 @@ ,Div ("lst:captionAttr",["listing","haskell"],[]) [Para [Str "Listing",Space,Str "1:",Space,Str "Listing",Space,Str "caption"] ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]- ,RawBlock (Format "latex") "\\pagebreak"+ ,RawBlock (Format "tex") "\\pagebreak" ,Header 2 ("sec:table-capts",[],[]) [Str "Table-style",Space,Str "captions"] ,Para [Str "Enabled",Space,Str "with",Space,Code ("",[],[]) "codeBlockCaptions",Space,Str "metadata",Space,Str "option.",Space,Str "If",Space,Str "code",Space,Str "block",Space,Str "is",Space,Str "immediately",SoftBreak,Str "adjacent",Space,Str "to",Space,Str "paragraph,",Space,Str "starting",Space,Str "with",Space,Code ("",[],[]) "Listing:",Space,Str "or",Space,Code ("",[],[]) ":",Str ",",Space,Str "said",Space,Str "paragraph",Space,Str "will",Space,Str "be",SoftBreak,Str "treated",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption."] ,Div ("lst:tableCaption",["listing","haskell"],[])
test/test-integrative.hs view
@@ -37,25 +37,39 @@ describe dir $ do input <- runIO $ readFile ("test" </> "m2m" </> dir </> "input.md") expect_md <- runIO $ readFile ("test" </> "m2m" </> dir </> "expect.md")- expect_tex <- runIO $ readFile ("test" </> "m2m" </> dir </> "expect.tex") let ro = def { readerExtensions = pandocExtensions } wo = def { writerExtensions = pandocExtensions, writerHighlightStyle=Just pygments } p@(Pandoc meta _) <- runIO $ either (error . show) id <$> P.runIO (readMarkdown ro $ T.pack input) let actual_md = either (fail . show) T.unpack $ runPure $ writeMarkdown wo $ runCrossRef meta (Just $ Format "markdown") defaultCrossRefAction p- actual_tex = either (fail . show) T.unpack $ runPure $ writeLaTeX wo $ runCrossRef meta (Just $ Format "latex") defaultCrossRefAction p it "Markdown" $ do zipWithM_ shouldBe (lines' actual_md) (lines' expect_md) length' (lines' actual_md) `shouldBe` length' (lines' expect_md)+#ifdef FLAKY+ expect_tex <- runIO $ readFile ("test" </> "m2m" </> dir </> "expect.tex")+ let actual_tex = either (fail . show) T.unpack $ runPure $ writeLaTeX wo $ runCrossRef meta (Just $ Format "latex") defaultCrossRefAction p it "LaTeX" $ do zipWithM_ shouldBe (lines' actual_tex) (lines' expect_tex) length' (lines' actual_tex) `shouldBe` length' (lines' expect_tex)+#endif where lines' = zip [(1 :: Int)..] . lines length' = length . filter (not . null . snd) main :: IO () main = do- mds <- getDirectoryContents ("test" </> "m2m")+ mds <-+#ifndef FLAKY+ filter (`notElem` flaky) <$>+#endif+ getDirectoryContents ("test" </> "m2m") hspec $ describe "Integrative tests" $ mapM_ m2m mds++#ifndef FLAKY+flaky :: [String]+flaky = [ "equations-tables"+ , "equations-tables-auto"+ , "subfigures-grid"+ ]+#endif
test/test-pandoc-crossref.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleContexts, CPP #-} import Test.Hspec import Text.Pandoc hiding (getDataFileName) import Text.Pandoc.Builder@@ -307,10 +307,12 @@ <> para (citeGen "eq:some_equation" [1]) `test` "\\begin{equation}x^2\\label{eq:some_equation1}\\end{equation}\n\neq.~\\ref{eq:some_equation1}" +#ifdef FLAKY it "Tbl labels" $ table' "A table" "some_table1" <> para (citeGen "tbl:some_table" [1])- `test` "\\hypertarget{tbl:some_table1}{}\n\\begin{longtable}[]{@{}@{}}\n\\caption{\\label{tbl:some_table1}A table}\\tabularnewline\n\\toprule\n\\tabularnewline\n\\midrule\n\\endfirsthead\n\\toprule\n\\tabularnewline\n\\midrule\n\\endhead\n\\tabularnewline\n\\bottomrule\n\\end{longtable}\n\ntbl.~\\ref{tbl:some_table1}"+ `test` "\\hypertarget{tbl:some_table1}{}\n\\begin{longtable}[]{@{}@{}}\n\\caption{\\label{tbl:some_table1}A table}\\tabularnewline\n\\toprule\n\\endhead\n\\tabularnewline\n\\bottomrule\n\\end{longtable}\n\ntbl.~\\ref{tbl:some_table1}"+#endif it "Code block labels" $ do codeBlock' "A code block" "some_codeblock1"