packages feed

pandoc-crossref 0.3.18.0 → 0.3.18.1

raw patch · 6 files changed

+87/−36 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Text.Pandoc.CrossRef: autoEqnLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: autoSectionLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: ccsDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: ccsLabelSep :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: ccsTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: chapDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: chapters :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: chaptersDepth :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: codeBlockCaptions :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: cref :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: crossrefYaml :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: customHeadingLabel :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: customLabel :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnBlockInlineMath :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnBlockTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnDisplayTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnIndexTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnInlineTableTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnInlineTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnPrefix :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: eqnPrefixTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: equationNumberTeX :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: figLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: figPrefix :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: figPrefixTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: figureTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: figureTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: getOptions :: Meta -> Maybe Format -> Options
+ Text.Pandoc.CrossRef: lastDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: linkReferences :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: listItemTitleDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: listingTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: listingTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: listings :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lofItemTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lofItemTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lofTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lolItemTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lolItemTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lolTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lotItemTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lotItemTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lotTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lstLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lstPrefix :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: lstPrefixTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: nameInLink :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: numberSections :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: outFormat :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: pairDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: rangeDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: refDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: refIndexTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: secHeaderDelim :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: secHeaderTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: secLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: secPrefix :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: secPrefixTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: sectionsDepth :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: setLabelAttribute :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: subfigGrid :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: subfigLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: subfigureChildTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: subfigureRefIndexTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: subfigureTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: tableEqns :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: tableTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: tableTitle :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: tblLabels :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: tblPrefix :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: tblPrefixTemplate :: ToMetaValue a => a -> Meta
+ Text.Pandoc.CrossRef: titleDelim :: ToMetaValue a => a -> Meta
- Text.Pandoc.CrossRef: runCrossRef :: forall a b. Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> b
+ Text.Pandoc.CrossRef: runCrossRef :: Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> b
- Text.Pandoc.CrossRef: runCrossRefIO :: forall a b. Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> IO b
+ Text.Pandoc.CrossRef: runCrossRefIO :: Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> IO b

Files

CHANGELOG.md view
@@ -1,3 +1,14 @@+## 0.3.18.1++-   Minor refactor to avoid new warnings introduced in GHC 9.8.++-   Switch CI compiler to GHC 9.8.4.++-   Add some potentially useful references to the documentation.++-   Fix image scaling in docx for `subfigGrid`. See+    [#394](https://github.com/lierdakil/pandoc-crossref/issues/394) for details.+ ## 0.3.18.0  -   Add `eqnInlineTableTemplate` and `eqnDisplayTemplate` options.
docs/index.md view
@@ -1,16 +1,40 @@ --- author: Nikolay Yakimov-date: November 2017+date: December 2024 title: 'pandoc-crossref(1)' ---  pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them. +Bug tracker: <https://github.com/lierdakil/pandoc-crossref/issues>+ * TOC {:toc}  # Caveats++## LaTeX input (a.k.a. converting LaTeX to docx/epub/etc)++The principal aim of pandoc-crossref is to add references to Markdown.++Other input formats may happen to work also (basically if you can make Pandoc+citation syntax to work), but that's more of a happy coincidence than a+deliberate design decision.++In particular, LaTeX syntax is generally not recognized, although under some+specific conditions it may seem to kinda-sorta work.++Converting TeX to anything editable in general is nigh impossible, with TeX+being a Turing-complete layout language rather than a markup language. That was+one of the motivations for pandoc-crossref in the first place.++All that said, if you really need to use LaTeX as an input format, see the+discussions in <https://github.com/lierdakil/pandoc-crossref/issues/250>.++For best results, consider using a purpose-built filter instead of+pandoc-crossref. For example,+[pandoc-text-numbering](https://github.com/fncokg/pandoc-tex-numbering).  ## LaTeX output and `--include-in-header` 
lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs view
@@ -127,13 +127,19 @@           = perc/100.0           | otherwise = error "Only percent allowed in subfigure width!"         blkToRow :: Block -> [Block]-        blkToRow (Para inls) = mapMaybe inlToCell inls+        blkToRow (Para inls) = zipWith inlToCell widths $ mapMaybe getImg inls         blkToRow x = [x]-        inlToCell :: Inline -> Maybe Block-        inlToCell (Image (id', cs, as) txt tgt) = Just $-          Figure (id', cs, []) (Caption Nothing [Para txt]) [Plain [Image ("", cs, setW as) txt tgt]]-        inlToCell _ = Nothing-        setW as = ("width", "100%"):filter ((/="width") . fst) as+        getImg (Image (id', cs, as) txt tgt) = Just (id', cs, as, txt, tgt)+        getImg _ = Nothing+        inlToCell w (id', cs, as, txt, tgt) =+          Figure (id', cs, []) (Caption Nothing [Para txt]) [Plain [Image ("", cs, setW w as) txt tgt]]+        setW w as = ("width", width):filter ((/="width") . fst) as+          where+            -- With docx, since pandoc 3.0, 100% is interpreted as "page width",+            -- even in table cells. Hence, this hack.+            width+              | isDocxFormat opts = T.pack (show $ w * 100) <> "%"+              | otherwise = "100%"  replaceSubfigs :: [Inline] -> WS (ReplacedResult [Inline]) replaceSubfigs = (replaceNoRecurse . concat) <=< mapM replaceSubfig@@ -218,6 +224,8 @@       caption' = Caption short (walkReplaceInlines title' title btitle:rest)   replaceNoRecurse $     if subFigure && isLatexFormat opts-    then Plain $ latexSubFigure (head $ blocksToInlines content) label+    then Plain $ case blocksToInlines content of+      ctHead:_ -> latexSubFigure ctHead label+      _ -> error "The impossible happened: empty content in subfigures"     else Figure (label,cls,setLabel opts idxStr fattrs) caption' (content' title') runFigure _ _ _ _ = noReplaceNoRecurse
lib-internal/Text/Pandoc/CrossRef/References/Refs.hs view
@@ -33,6 +33,8 @@ import qualified Data.Sequence as S import Data.Sequence (ViewR(..)) import Control.Monad (liftM2, join)+import qualified Data.List.NonEmpty as NE+import Data.List.NonEmpty (NonEmpty)  import Debug.Trace import Lens.Micro.Mtl@@ -45,25 +47,25 @@ replaceRefs :: [Inline] -> WS [Inline] replaceRefs (Cite cits _:xs) = do   opts <- ask :: WS Options-  toList . (<> fromList xs) . intercalate' (text ", ") . map fromList <$> mapM (replaceRefs' opts) (groupBy eqPrefix cits)+  toList . (<> fromList xs) . intercalate' (text ", ") . map fromList <$> mapM (replaceRefs' opts) (NE.groupBy eqPrefix cits)   where     eqPrefix a b = uncurry (==) $       (fmap uncapitalizeFirst . getLabelPrefix . citationId) <***> (a,b)     (<***>) = join (***)-    replaceRefs' :: Options -> [Citation] -> WS [Inline]+    replaceRefs' :: Options -> NonEmpty Citation -> WS [Inline]     replaceRefs' opts cits'       | Just prefix <- allCitsPrefix cits'       = replaceRefs'' opts prefix cits'-      | otherwise = return [Cite cits' il']+      | otherwise = return [Cite (NE.toList cits') il']         where           il' = toList $               str "["-            <> intercalate' (text "; ") (map citationToInlines cits')+            <> intercalate' (text "; ") (map citationToInlines $ NE.toList cits')             <> str "]"           citationToInlines c =             fromList (citationPrefix c) <> text ("@" <> citationId c)               <> fromList (citationSuffix c)-    replaceRefs'' :: Options -> Prefix -> [Citation] -> WS [Inline]+    replaceRefs'' :: Options -> Prefix -> NonEmpty Citation -> WS [Inline]     replaceRefs'' opts = ($ opts) . flip $       if isLatexFormat opts       then replaceRefsLatex@@ -106,21 +108,21 @@   where (refprefixf, reftempl) = prefMap prefix         refprefix = refprefixf opts capitalize num -allCitsPrefix :: [Citation] -> Maybe Prefix+allCitsPrefix :: NonEmpty Citation -> Maybe Prefix allCitsPrefix cits = find isCitationPrefix prefixes   where   isCitationPrefix p =     all ((pfxMapR p `T.isPrefixOf`) . uncapitalizeFirst . citationId) cits -replaceRefsLatex :: Prefix -> Options -> [Citation] -> WS [Inline]+replaceRefsLatex :: Prefix -> Options -> NonEmpty Citation -> WS [Inline] replaceRefsLatex prefix opts cits   | cref opts   = replaceRefsLatex' prefix opts cits   | otherwise   = toList . intercalate' (text ", ") . map fromList <$>-      mapM (replaceRefsLatex' prefix opts) (groupBy citationGroupPred cits)+      mapM (replaceRefsLatex' prefix opts) (NE.groupBy citationGroupPred cits) -replaceRefsLatex' :: Prefix -> Options -> [Citation] -> WS [Inline]+replaceRefsLatex' :: Prefix -> Options -> NonEmpty Citation -> WS [Inline] replaceRefsLatex' prefix opts cits =   return $ p [texcit]   where@@ -137,16 +139,19 @@       = id       | noPrefix       = getRefPrefix opts prefix cap (length cits - 1)-      | otherwise = ((citationPrefix (head cits) <> [Space]) <>)-    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . head $ cits+      | otherwise = ((citationPrefix (NE.head cits) <> [Space]) <>)+    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . NE.head $ cits     cref' | suppressAuthor = "\\labelcref"           | cap = "\\Cref"           | otherwise = "\\cref" -listLabels :: Prefix -> T.Text -> T.Text -> T.Text -> [Citation] -> T.Text-listLabels prefix p sep s =-  T.intercalate sep . map ((p <>) . (<> s) . mkLaTeXLabel' . (pfxMapR prefix <>) . getLabelWithoutPrefix . citationId)+listLabels :: Prefix -> T.Text -> T.Text -> T.Text -> NonEmpty Citation -> T.Text+listLabels prefix p sep s+  = T.intercalate sep+  . map ((p <>) . (<> s) . mkLaTeXLabel' . (pfxMapR prefix <>) . getLabelWithoutPrefix . citationId)+  . NE.toList + getLabelWithoutPrefix :: T.Text -> T.Text getLabelWithoutPrefix = T.drop 1 . T.dropWhile (/=':') @@ -157,24 +162,24 @@   | otherwise = Nothing   where p = flip T.snoc ':' . T.takeWhile (/=':') $ lab -replaceRefsOther :: Prefix -> Options -> [Citation] -> WS [Inline]+replaceRefsOther :: Prefix -> Options -> NonEmpty Citation -> WS [Inline] replaceRefsOther prefix opts cits = toList . intercalate' (text ", ") . map fromList <$>-    mapM (replaceRefsOther' prefix opts) (groupBy citationGroupPred cits)+    traverse (replaceRefsOther' prefix opts) (NE.groupBy citationGroupPred cits)  citationGroupPred :: Citation -> Citation -> Bool citationGroupPred = (==) `on` liftM2 (,) citationPrefix citationMode -replaceRefsOther' :: Prefix -> Options -> [Citation] -> WS [Inline]+replaceRefsOther' :: Prefix -> Options -> NonEmpty Citation -> WS [Inline] replaceRefsOther' prefix opts cits = do-  indices <- mapM (getRefIndex prefix opts) cits+  indices <- mapM (getRefIndex prefix opts) $ NE.toList cits   let-    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . head $ cits+    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . NE.head $ cits     writePrefix | all ((==SuppressAuthor) . citationMode) cits                 = id                 | all (null . citationPrefix) cits                 = cmap $ getRefPrefix opts prefix cap (length cits - 1)                 | otherwise-                = cmap $ toList . ((fromList (citationPrefix (head cits)) <> space) <>) . fromList+                = cmap $ toList . ((fromList (citationPrefix (NE.head cits)) <> space) <>) . fromList     cmap f [Link attr t w]       | nameInLink opts = [Link attr (f t) w]     cmap f x = f x
lib-internal/Text/Pandoc/CrossRef/Util/Options.hs view
@@ -20,7 +20,7 @@  {-# LANGUAGE OverloadedStrings#-} -module Text.Pandoc.CrossRef.Util.Options (Options(..), isLatexFormat) where+module Text.Pandoc.CrossRef.Util.Options (Options(..), isLatexFormat, isDocxFormat) where import Data.Text (Text) import Text.Pandoc.CrossRef.Util.Template import Text.Pandoc.CrossRef.Util.Util (isFormat)@@ -85,3 +85,6 @@  isLatexFormat :: Options -> Bool isLatexFormat = ((||) <$> (isFormat "latex") <*> (isFormat "beamer")) . outFormat++isDocxFormat :: Options -> Bool+isDocxFormat = isFormat "docx" . outFormat
pandoc-crossref.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           pandoc-crossref-version:        0.3.18.0+version:        0.3.18.1 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@@ -139,7 +139,7 @@   build-depends:       base >=4.11 && <5     , mtl >=1.1 && <2.4-    , pandoc >=3.1.8 && <3.5+    , pandoc >=3.1.8 && <3.7     , pandoc-crossref-internal     , pandoc-types ==1.23.*     , text >=1.2.2 && <2.2@@ -183,7 +183,7 @@     , microlens-mtl >=0.2.0.1 && <0.3.0.0     , microlens-th >=0.4.3.10 && <0.5.0.0     , mtl >=1.1 && <2.4-    , pandoc >=3.1.8 && <3.5+    , pandoc >=3.1.8 && <3.7     , pandoc-types ==1.23.*     , syb >=0.4 && <0.8     , template-haskell >=2.7.0.0 && <3.0.0.0@@ -204,7 +204,7 @@     , gitrev >=1.3.1 && <1.4     , open-browser ==0.2.*     , optparse-applicative >=0.13 && <0.19-    , pandoc >=3.1.8 && <3.5+    , pandoc >=3.1.8 && <3.7     , pandoc-crossref     , pandoc-types ==1.23.*     , template-haskell >=2.7.0.0 && <3.0.0.0@@ -225,7 +225,7 @@     , directory >=1 && <1.4     , filepath >=1.1 && <1.6     , hspec >=2.4.4 && <3-    , pandoc >=3.1.8 && <3.5+    , pandoc >=3.1.8 && <3.7     , pandoc-crossref     , pandoc-types ==1.23.*     , text >=1.2.2 && <2.2@@ -251,7 +251,7 @@     , hspec >=2.4.4 && <3     , microlens >=0.4.12.0 && <0.5.0.0     , mtl >=1.1 && <2.4-    , pandoc >=3.1.8 && <3.5+    , pandoc >=3.1.8 && <3.7     , pandoc-crossref     , pandoc-crossref-internal     , pandoc-types ==1.23.*@@ -271,7 +271,7 @@   build-depends:       base >=4.11 && <5     , criterion >=1.5.9.0 && <1.7-    , pandoc >=3.1.8 && <3.5+    , pandoc >=3.1.8 && <3.7     , pandoc-crossref     , pandoc-types ==1.23.*     , text >=1.2.2 && <2.2