pandoc-crossref 0.2.1.2 → 0.2.1.3
raw patch · 6 files changed
+65/−16 lines, 6 files
Files
- README.md +2/−2
- lib/Text/Pandoc/CrossRef/References/Blocks.hs +5/−5
- lib/Text/Pandoc/CrossRef/References/Refs.hs +2/−6
- lib/Text/Pandoc/CrossRef/Util/Util.hs +10/−0
- pandoc-crossref.cabal +2/−2
- test/test-pandoc-crossref.hs +44/−1
README.md view
@@ -80,7 +80,7 @@ To sum up, subfigures are made with a div having a figure `id`. Contents of said div consist of several paragraphs. All but last paragraphs contain one subfigure each, with captions, images and (optionally) reference attributes. Last paragraph contains figure caption. -Output is customizable, with metadata fields. See [Customization](#Customization) for more information.+Output is customizable, with metadata fields. See [Customization](#customization) for more information. Default settings will produce the following equivalent Markdown from example above: @@ -223,7 +223,7 @@ Reference syntax heavily relies on citation syntax. Basic reference is created by writing `@`, then basically desired label with prefix. It is also possible to reference a group of objects, by putting them into brackets with `;` as separator. Similar objects will be grouped in order of them appearing in citation brackets, and sequential reference numbers will be shortened, e.g. `1,2,3` will be shortened to `1-3`. -You can capitalize first reference character to get capitalized prefix, e.g. `[@Fig:label1]` will produce `Fig. ...` by default. Capitalized prefixes are derived automatically by capitalizing first letter of every word in non-capitalized prefix, unless overriden with metadata settings. See [Customization](#Customization) for more information.+You can capitalize first reference character to get capitalized prefix, e.g. `[@Fig:label1]` will produce `Fig. ...` by default. Capitalized prefixes are derived automatically by capitalizing first letter of every word in non-capitalized prefix, unless overriden with metadata settings. See [Customization](#customization) for more information. ### Lists
lib/Text/Pandoc/CrossRef/References/Blocks.hs view
@@ -89,7 +89,7 @@ ++ cont ++ [ Para [RawInline (Format "tex") "\\caption" , Span stopAttr caption]- , RawBlock (Format "tex") $ "\\label{"++label++"}"+ , RawBlock (Format "tex") $ mkLaTeXLabel label , RawBlock (Format "tex") "\\end{figure}"] _ -> return $ Div (label, "subfigures":cls, attrs) $ cont ++ [Para capt] where@@ -105,7 +105,7 @@ let title' = case outFormat opts of f | isFormat "latex" f ->- RawInline (Format "tex") ("\\label{"++label++"}") : title+ RawInline (Format "tex") (mkLaTeXLabel label) : title _ -> applyTemplate idxStr title $ tableTemplate opts return $ Table title' align widths header cells replaceBlocks opts cb@(CodeBlock (label, classes, attrs) code)@@ -173,7 +173,7 @@ | "eq:" `isPrefixOf` label = case outFormat opts of f | isFormat "latex" f ->- let eqn = "\\begin{equation}"++eq++"\\label{"++label++"}\\end{equation}"+ let eqn = "\\begin{equation}"++eq++mkLaTeXLabel label++"\\end{equation}" in return $ RawInline (Format "tex") eqn _ -> do idxStr <- replaceAttr opts label (lookup "label" attrs) [] eqnRefs@@ -202,7 +202,7 @@ #if MIN_VERSION_pandoc(1,17,0) alt #else- RawInline (Format "tex") ("\\label{"++label++"}") : alt+ RawInline (Format "tex") (mkLaTeXLabel label) : alt #endif _ -> applyTemplate idxStr alt $ figureTemplate opts return $ Image attr alt' img@@ -263,7 +263,7 @@ let title' = fromMaybe title $ stripPrefix "fig:" title texlabel | null label = []- | otherwise = "\\label{" ++ label ++ "}"+ | otherwise = mkLaTeXLabel label texalt | "nocaption" `elem` cls = [] | otherwise = [ RawInline (Format "tex") "["] ++ alt ++ [ RawInline (Format "tex") "]"]
lib/Text/Pandoc/CrossRef/References/Refs.hs view
@@ -86,7 +86,7 @@ return $ p [texcit] where texcit =- RawInline (Format "tex") $ replace' '_' "ux5f" $+ RawInline (Format "tex") $ if cref opts then cref'++"{"++listLabels prefix "" "," "" cits++"}" else@@ -96,14 +96,10 @@ cap = maybe False isFirstUpper $ getLabelPrefix . citationId . head $ cits cref' | cap = "\\Cref" | otherwise = "\\cref"- replace' old new | prefix == "sec:" = replace old new- | otherwise = id- replace old new = intercalate new . split old- split a = filter (/=[a]) . groupBy ((&&) `on` (/= a)) listLabels :: String -> String -> String -> String -> [Citation] -> String listLabels prefix p sep s =- intercalate sep . map ((p ++) . (++ s) . (prefix++) . getLabelWithoutPrefix . citationId)+ intercalate sep . map ((p ++) . (++ s) . mkLaTeXLabel' . (prefix++) . getLabelWithoutPrefix . citationId) getLabelWithoutPrefix :: String -> String getLabelWithoutPrefix = drop 1 . dropWhile (/=':')
lib/Text/Pandoc/CrossRef/Util/Util.hs view
@@ -10,6 +10,8 @@ import Data.List (intercalate) import Data.Maybe (fromMaybe) import Data.Generics+import Text.Pandoc.Writers.LaTeX+import Data.Default isFormat :: String -> Maybe Format -> Bool isFormat fmt (Just (Format f)) = takeWhile (`notElem` "+-") f == fmt@@ -41,3 +43,11 @@ if q x' then return x' else gmapM (everywhereMBut' q f) x'++mkLaTeXLabel :: String -> String+mkLaTeXLabel l = "\\label{" ++ mkLaTeXLabel' l ++ "}"++mkLaTeXLabel' :: String -> String+mkLaTeXLabel' l =+ let ll = writeLaTeX def $ Pandoc nullMeta [Div (l, [], []) []]+ in takeWhile (/='}') . drop 1 . dropWhile (/='{') $ ll
pandoc-crossref.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: pandoc-crossref-version: 0.2.1.2+version: 0.2.1.3 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@@ -25,7 +25,7 @@ source-repository this type: git location: https://github.com/lierdakil/pandoc-crossref- tag: v0.2.1.2+ tag: v0.2.1.3 library exposed-modules: Text.Pandoc.CrossRef
test/test-pandoc-crossref.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleContexts, CPP #-} import Test.Hspec import Text.Pandoc hiding (readMarkdown) import Text.Pandoc.Builder@@ -266,7 +266,50 @@ m' = setMeta "chapters" True m runCrossRef m' Nothing crossRefBlocks b `shouldBe` Native.demochapters + describe "LaTeX" $ do+ let test = test' nullMeta+ infixr 5 `test`+ test' m i o = writeLaTeX def (Pandoc m $ runCrossRef m (Just $ Format "latex") crossRefBlocks (toList i)) `shouldBe` o + describe "Labels" $ do++ it "Section labels" $+ headerWith ("sec:section_label1", [], []) 1 (text "Section")+ <> para (citeGen "sec:section_label" [1])+ `test` "\\section{Section}\\label{sec:sectionux5flabel1}\n\nsec.~\\ref{sec:sectionux5flabel1}"++ it "Image labels" $+ figure "img.png" [] "Title" "figure_label1"+ <> para (citeGen "fig:figure_label" [1])+#if MIN_VERSION_pandoc(1,17,0)+ `test` "\\begin{figure}[htbp]\n\\centering\n\\includegraphics{img.png}\n\\caption{Title}\\label{fig:figureux5flabel1}\n\\end{figure}\n\nfig.~\\ref{fig:figureux5flabel1}"+#else+ `test` "\\begin{figure}[htbp]\n\\centering\n\\includegraphics{img.png}\n\\caption{\\label{fig:figureux5flabel1}Title}\n\\end{figure}\n\nfig.~\\ref{fig:figureux5flabel1}"+#endif++ it "Eqn labels" $+ equation "x^2" "some_equation1"+ <> para (citeGen "eq:some_equation" [1])+ `test` "\\begin{equation}x^2\\label{eq:someux5fequation1}\\end{equation}\n\neq.~\\ref{eq:someux5fequation1}"++ it "Tbl labels" $+ table' "A table" "some_table1"+ <> para (citeGen "tbl:some_table" [1])+#if MIN_VERSION_pandoc(1,17,0)+ `test` "\\begin{longtable}[]{@{}@{}}\n\\caption{\\label{tbl:someux5ftable1}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:someux5ftable1}"+#else+ `test` "\\begin{longtable}[c]{@{}@{}}\n\\caption{\\label{tbl:someux5ftable1}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:someux5ftable1}"+#endif++ it "Code block labels" $ do+ codeBlock' "A code block" "some_codeblock1"+ <> para (citeGen "lst:some_codeblock" [1])+ `test` "\\begin{codelisting}\n\\caption{A code block}\n\n\\hypertarget{lst:someux5fcodeblock1}{\\label{lst:someux5fcodeblock1}}\n\\begin{verbatim}\nmain :: IO ()\n\\end{verbatim}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:someux5fcodeblock1}"+ let test1 = test' $ setMeta "codeBlockCaptions" True nullMeta+ infixr 5 `test1`+ codeBlockForTable "some_codeblock1" <> paraText ": A code block"+ <> para (citeGen "lst:some_codeblock" [1])+ `test1` "\\begin{codelisting}\n\n\\caption{A code block}\n\n\\hypertarget{lst:someux5fcodeblock1}{\\label{lst:someux5fcodeblock1}}\n\\begin{verbatim}\nmain :: IO ()\n\\end{verbatim}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:someux5fcodeblock1}" citeGen :: String -> [Int] -> Inlines citeGen p l = cite (mconcat $ map (cit . (p++) . show) l) $ text $