packages feed

pandoc-crossref 0.3.18.2 → 0.3.19

raw patch · 44 files changed

+1500/−318 lines, 44 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

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: type CrossRefM a = Reader CrossRefEnv a
+ Text.Pandoc.CrossRef: data CrossRefM a
+ Text.Pandoc.CrossRef.Internal: CrossRefEnv :: Meta -> Options -> CrossRefEnv
+ Text.Pandoc.CrossRef.Internal: CrossRefM :: ReaderT CrossRefEnv (State References) a -> CrossRefM a
+ Text.Pandoc.CrossRef.Internal: [creOptions] :: CrossRefEnv -> Options
+ Text.Pandoc.CrossRef.Internal: [creSettings] :: CrossRefEnv -> Meta
+ Text.Pandoc.CrossRef.Internal: data CrossRefEnv
+ Text.Pandoc.CrossRef.Internal: instance Control.Monad.Reader.Class.MonadReader Text.Pandoc.CrossRef.Internal.CrossRefEnv Text.Pandoc.CrossRef.Internal.CrossRefM
+ Text.Pandoc.CrossRef.Internal: instance Control.Monad.State.Class.MonadState Text.Pandoc.CrossRef.References.Types.References Text.Pandoc.CrossRef.Internal.CrossRefM
+ Text.Pandoc.CrossRef.Internal: instance GHC.Base.Applicative Text.Pandoc.CrossRef.Internal.CrossRefM
+ Text.Pandoc.CrossRef.Internal: instance GHC.Base.Functor Text.Pandoc.CrossRef.Internal.CrossRefM
+ Text.Pandoc.CrossRef.Internal: instance GHC.Base.Monad Text.Pandoc.CrossRef.Internal.CrossRefM
+ Text.Pandoc.CrossRef.Internal: newtype CrossRefM a

Files

CHANGELOG.md view
@@ -1,3 +1,33 @@+## 0.3.19++### New features++-   Hiding items from list-of-X++    See <https://lierdakil.github.io/pandoc-crossref/#hiding-items-from-list-of-x-lists>.++-   New `listOfMetadata` option++    See <https://lierdakil.github.io/pandoc-crossref/#list-of-x-in-pandoc-templates>.++-   New template variables in list-of item templates++    See <https://lierdakil.github.io/pandoc-crossref/#list-item-templates>++### Fixes++-   Ensure references are also sorted in order of appearance inline++    This is a minor continuation of+    [#466](https://github.com/lierdakil/pandoc-crossref/issues/466), caught+    after the previous release.++### Maintenance++-   Remove long-redundant escapeLaTeX+-   General clean-up and some refactoring+-   Switch to GHC2021 and enable some extensions by default+ ## 0.3.18.2  -   Ensure items in list-of are in order of appearance
docs/index.md view
@@ -78,6 +78,67 @@  You can use other html entites of course, like `&nbsp;` etc. +## Using raw blocks to define elements++It may be useful/convenient to define some elements as raw blocks, as Pandoc+Markdown, while very powerful, doesn't support everything Pandoc can support+internally (e.g. colspan/rowspan in tables).++Pandoc-crossref relies on Pandoc's AST representation, thus simply using [raw+blocks](https://pandoc.org/MANUAL.html#extension-raw_attribute) won't work.++However, it's feasible if Pandoc can actually parse the contents of the raw+block with a little helper Lua filter. For example, something like this:++```lua+function Div(div)+  local id = div.attr.identifier+  if (id:match "^tbl:" or id:match "^fig:") and div.content[2].t == "RawBlock"+  then+    local raw = div.content[2]+    local elem = pandoc.read(raw.text, raw.format).blocks+    elem[1].caption = pandoc.Caption(div.content[1])+    elem[1].attr = div.attr+    return elem+  end+end+```++applied before pandoc-crossref, will reparse table definitions like this:++``````markdown+:::{#tbl:foo}+Caption++```{=html}+<table>+  <tr><th>Foo</th><th>Bar</th></tr>+  <tr><td rowspan=2>1</td><td>Quux</td></tr>+  <tr><td>Baz</td></tr>+</table>+```+:::+``````++This also will work for figures, e.g.:+++``````markdown+:::{#fig:foo}+Caption++```{=html}+<figure>+  <p>This is just a paragraph instead of an image in a figure, nothing to see+  here</p>+</figure>+```+:::+``````++Bear in mind that if Pandoc fails to parse the raw block, pandoc-crossref will+fail to interpret it.+ # Syntax  Syntax is loosely based on discussion in@@ -528,6 +589,53 @@  With HTML-compatible output, lists are wrapped into a `div` with classes `list` and `list-of-<prefix>`, where `<prefix>` is either `fig`, `tbl` or `lst` depending on the type of the list. This allows for ad-hoc style overrides in HTML. +### Hiding items from list-of-X lists++> NB: Highly experimental with LaTeX output (that includes PDF). Might not work+> as expected or break in some edge cases. Please check your output and raise+> issues!++If you need to hide a figure/table/code block from the corresponding `\listofX`,+you can set `hidden` attribute on the item, e.g.++```markdown+![Hidden figure](fig.png){#fig:hidden hidden="y"}+```++The following values are interpreted as "no", so setting `hidden` to those will+leave the object visible in the list-of-X: `no`, `n`, `false`, `f`, `off`, `0`,+`none`, `null`, `disable`, `disabled`, `unset`. Any other value (including empty+string!) will hide the item from list-of-X.++Additionally, this attribute can be set on sections. Since there isn't a+list-of-sections per se, table of contents notwithstanding, instead of hiding a+section, this will implicitly hide all items inside that section and all its+subsections.++You can override subsections or individual items inside a hidden section to be+visible by explicitly setting `hidden=no` (or to any other falsy value).++Same as with other attributes, to use this with tables, you need to use fenced+div syntax, not the short syntax.++### List-of-X in Pandoc templates++If you'd prefer to include list-of-X things in your custom template, rather than+use `\listofX` directly in the document, set the `listOfMetadata` option to+`true`, and add something like this to your template:++```+$if(list-of-figures)$+$list-of-figures$+$endif$+```++The following variables are supported:++- `list-of-figures`+- `list-of-tables`+- `list-of-listings`+ # Usage  Run pandoc with `--filter` option, passing path to pandoc-crossref@@ -586,6 +694,8 @@ -   `equationNumberTeX`, default `\\qquad`: use a LaTeX command for typesetting     equation numbers. Remember that metadata is parsed as Markdown, so you may need to escape backslashes.     This option doesn't affect LaTeX output (which offloads numbering to the LaTeX engine).+-   `listOfMetadata`, default `false`. Enables setting `list-of-figures` &c+    variables to pass through to the Pandoc's templating engine.  ### Item title format @@ -857,6 +967,16 @@ 4.  ... ::: ```++Variables available in these templates:++- `i` -- item number with chapter (if chapters are enabled), formatted according+  to `refIndexTemplate` or `subfigureRefIndexTemplate` if item is a subfigure+- `ri` -- "raw" item number, before applying formatting (but with chapter if+  chapters are enabled)+- `lt` -- title, linked back to the item (i.e. wrapped in an anchor element)+- `t` -- just the title itself, without any links+- `s` -- subfigure identifier, if any; empty if not a subfigure  ### LaTeX customization 
lib-internal/Text/Numeral/Roman.hs view
@@ -21,9 +21,6 @@ This file contains code covered by the license found in licenses/LICENSE.roman-numerals -} -{-# LANGUAGE FlexibleContexts  #-}-{-# LANGUAGE OverloadedStrings #-}- {-| Parsing and pretty printing of Roman numerals.  This module provides functions for parsing and pretty printing Roman
lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs view
@@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, ScopedTypeVariables-  , LambdaCase, NamedFieldPuns #-} module Text.Pandoc.CrossRef.References.Blocks   ( replaceAll   ) where@@ -31,6 +29,7 @@ import Text.Pandoc.Definition import Text.Pandoc.Shared (blocksToInlines) +import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.References.Blocks.CodeBlock import Text.Pandoc.CrossRef.References.Blocks.Header import Text.Pandoc.CrossRef.References.Blocks.Math@@ -65,10 +64,10 @@ replaceBlock :: Block -> WS (ReplacedResult Block) replaceBlock (Header n attr text') = runHeader n attr text' replaceBlock (Figure attr@(label, _, _) caption content)-  | "fig:" `T.isPrefixOf` label+  | label `hasPfx` PfxImg   = runFigure False attr caption content replaceBlock (Div attr@(label, _, _) content)-  | "fig:" `T.isPrefixOf` label+  | label `hasPfx` PfxImg   , Just caption <- extractCaption $ last content   = case init content of       [Figure ("", [], []) _ content'] -- nested figure due to implicit_figures...@@ -76,22 +75,22 @@       xs -> runSubfigures attr xs caption replaceBlock (Div attr@(label, _, _) [Table tattr (Caption short (btitle:rest)) colspec header cells foot])   | not $ null $ blocksToInlines [btitle]-  , "tbl:" `T.isPrefixOf` label+  , label `hasPfx` PfxTbl   = runTable attr (Just tattr) short btitle rest colspec header cells foot replaceBlock (Table attr@(label, _, _) (Caption short (btitle:rest)) colspec header cells foot)   | not $ null $ blocksToInlines [btitle]-  , "tbl:" `T.isPrefixOf` label+  , label `hasPfx` PfxTbl   = runTable attr Nothing short btitle rest colspec header cells foot replaceBlock (CodeBlock attr@(label, _, attrs) code)   | not $ T.null label-  , "lst:" `T.isPrefixOf` label+  , label `hasPfx` PfxLst   , Just caption <- lookup "caption" attrs   = runCodeBlock attr code $ Left caption replaceBlock   (Div (label,"listing":divClasses, divAttrs)     [Para caption, CodeBlock ("",cbClasses,cbAttrs) code])   | not $ T.null label-  , "lst:" `T.isPrefixOf` label+  , label `hasPfx` PfxLst   = runCodeBlock (label, nub $ divClasses <> cbClasses, divAttrs <> cbAttrs) code $ Right caption replaceBlock (Para [Span attr [Math DisplayMath eq]])   = runBlockMath attr eq@@ -100,13 +99,13 @@ replaceInlineMany :: [Inline] -> WS (ReplacedResult [Inline]) replaceInlineMany (Span spanAttr@(label,clss,attrs) [Math DisplayMath eq]:xs) = do   opts <- ask-  if "eq:" `T.isPrefixOf` label || T.null label && autoEqnLabels opts+  if label `hasPfx` PfxEqn || T.null label && autoEqnLabels opts   then do     replaceRecurse . (<> xs) =<< if isLatexFormat opts       then         pure [RawInline (Format "latex") "\\begin{equation}"         , Span spanAttr [RawInline (Format "latex") eq]-        , RawInline (Format "latex") $ "\\end{equation}"]+        , RawInline (Format "latex") "\\end{equation}"]       else do         ReplaceEqn{replaceEqnEq, replaceEqnIdx} <- replaceEqn eqnDisplayTemplate spanAttr eq         pure [Span (label,clss,setLabel opts replaceEqnIdx attrs) replaceEqnEq]@@ -116,7 +115,7 @@ divBlocks :: Block -> Block divBlocks (Table tattr (Caption short (btitle:rest)) colspec header cells foot)   | not $ null title-  , Just label <- getRefLabel "tbl" [last title]+  , Just label <- getRefLabel PfxTbl [last title]   = Div (label,[],[]) [     Table tattr (Caption short $ walkReplaceInlines (dropWhileEnd isSpace (init title)) title btitle:rest) colspec header cells foot]   where@@ -126,7 +125,7 @@ spanInlines :: Options -> [Inline] -> [Inline] spanInlines opts (math@(Math DisplayMath _eq):ils)   | c:ils' <- dropWhile isSpace ils-  , Just label <- getRefLabel "eq" [c]+  , Just label <- getRefLabel PfxEqn [c]   = Span (label,[],[]) [math]:ils'   | autoEqnLabels opts   = Span nullAttr [math]:ils
lib-internal/Text/Pandoc/CrossRef/References/Blocks/CodeBlock.hs view
@@ -18,17 +18,14 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, MultiWayIf #-}- module Text.Pandoc.CrossRef.References.Blocks.CodeBlock where  import Control.Monad.Reader.Class import qualified Data.Text as T import Text.Pandoc.Definition-import Text.Pandoc.Shared (stringify) import qualified Text.Pandoc.Builder as B-import Data.Function ((&)) +import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.References.Monad import Text.Pandoc.CrossRef.References.Blocks.Util import Text.Pandoc.CrossRef.Util.Options@@ -39,26 +36,27 @@ runCodeBlock (label, classes, attrs) code eCaption = do   opts <- ask       --if used with listings package,nothing should be done-  if  | isLatexFormat opts, listings opts ->-          eCaption & either-            (const noReplaceNoRecurse)-            (\caption -> replaceNoRecurse $-              CodeBlock (label,classes,("caption",escapeLaTeX $ stringify caption):attrs) code)+  if  | isLatexFormat opts, listings opts -> do+          let cap = either (B.toList . B.text) id eCaption+          ref <- replaceAttr (Just label) attrs cap SPfxLst+          let attrs' =+                [ ("nolol", "true") | refHideFromList ref ] <>+                (("caption", latexCaptionRaw ref) : filter (\(k, _) -> k /= "hidden") attrs)+          replaceNoRecurse $ CodeBlock (label, classes, attrs') code       --if not using listings, however, wrap it in a codelisting environment-      | isLatexFormat opts ->+      | isLatexFormat opts -> do+          let cap = either (B.toList . B.text) id eCaption+          ref <- replaceAttr (Just label) attrs cap SPfxLst           replaceNoRecurse $ Div nullAttr [               RawBlock (Format "latex") $ "\\begin{codelisting}"-            , Plain [-                RawInline (Format "latex") "\\caption"-              , Span nullAttr $ either (pure . Str) id eCaption-              , RawInline (Format "latex") $ mkLaTeXLabel label-              ]+            , Plain $ latexCaption ref             , CodeBlock ("", classes, attrs) code             , RawBlock (Format "latex") "\\end{codelisting}"             ]       | otherwise -> do           let cap = either (B.toList . B.text) id eCaption-          idxStr <- replaceAttr (Right label) attrs cap SPfxLst+          ref <- replaceAttr (Just label) attrs cap SPfxLst+          idxStr <- chapIndex ref           let caption' = applyTemplate idxStr cap $ listingTemplate opts           replaceNoRecurse $ Div (label, "listing":classes, []) [               mkCaption opts "Caption" caption'
lib-internal/Text/Pandoc/CrossRef/References/Blocks/Header.hs view
@@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, RecordWildCards, NamedFieldPuns #-}- module Text.Pandoc.CrossRef.References.Blocks.Header where  import Control.Monad.Reader.Class@@ -35,22 +33,27 @@ import Lens.Micro.Mtl import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.References.Monad-import Text.Pandoc.CrossRef.References.Blocks.Util (setLabel)+import Text.Pandoc.CrossRef.References.Blocks.Util (setLabel, checkHidden) import Text.Pandoc.CrossRef.Util.Options import Text.Pandoc.CrossRef.Util.Template import Text.Pandoc.CrossRef.Util.Util  runHeader :: Int -> Attr -> [Inline] -> WS (ReplacedResult Block)-runHeader n (label, cls, attrs) text'-  | "unnumbered" `elem` cls = do+runHeader n (label, cls, attrs) text' = do+  stHiddenHeaderLevel %= filter \HiddenHeader{hhLevel} -> hhLevel < n+  hhHidden <- checkHidden attrs+  stHiddenHeaderLevel %= (HiddenHeader { hhLevel = n, hhHidden }:)++  if "unnumbered" `elem` cls+    then do       label' <- mangleLabel       replaceNoRecurse $ Header n (label', cls, attrs) text'-  | otherwise = do+    else do       opts@Options{..} <- ask       label' <- mangleLabel       ctrsAt PfxSec %= \cc ->         let ln = length cc-            cl i = lookup "label" attrs <|> customHeadingLabel n i <|> customLabel "sec" i+            cl i = lookup "label" attrs <|> customHeadingLabel n i <|> customLabel (Pfx PfxSec) i             inc l = case S.viewr l of               EmptyR -> error "impossible"               init' :> last' ->@@ -67,12 +70,14 @@         in cc'       cc <- use $ ctrsAt PfxSec       globCtr <- stGlob <<%= (+ 1)-      when ("sec:" `T.isPrefixOf` label') $+      when (label' `hasPfx` PfxSec) $         refsAt PfxSec %= M.insert label' RefRec {           refIndex = cc         , refGlobal = globCtr         , refTitle = text'         , refSubfigure = Nothing+        , refHideFromList = hhHidden+        , refLabel = if T.null label' then Nothing else Just label'         }       let textCC             | numberSections@@ -91,6 +96,6 @@     mangleLabel = do       Options{autoSectionLabels} <- ask       pure $-        if autoSectionLabels && not ("sec:" `T.isPrefixOf` label)-        then "sec:" <> label+        if autoSectionLabels && not (label `hasPfx` PfxSec)+        then pfxTextCol PfxSec <> label         else label
lib-internal/Text/Pandoc/CrossRef/References/Blocks/Math.hs view
@@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, RecordWildCards #-}- module Text.Pandoc.CrossRef.References.Blocks.Math where  import Control.Monad.Reader.Class@@ -51,9 +49,10 @@ replaceEqn :: MkTemplate a t => (Options -> t) -> Attr -> T.Text -> WS (ReplaceEqn a) replaceEqn eqTemplate (label, _, attrs) eq = do   opts <- ask-  let label' | T.null label = Left "eq"-             | otherwise = Right label-  idxStrRaw <- replaceAttr label' attrs [] SPfxEqn+  let label' | T.null label = Nothing+             | otherwise = Just label+  ref <- replaceAttr label' attrs [] SPfxEqn+  idxStrRaw <- chapIndex ref   let idxStr = applyTemplate' (M.fromDistinctAscList [("i", idxStrRaw)]) $ eqnIndexTemplate opts       eqTxt :: [Inline]       eqTxt = applyTemplate' eqTxtVars $
lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs view
@@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, LambdaCase, MultiWayIf #-}- module Text.Pandoc.CrossRef.References.Blocks.Subfigures where  import Control.Monad.Reader@@ -32,7 +30,6 @@ import Data.Default (def) import Data.List import Data.Maybe-import Text.Pandoc.Walk (walk) import Lens.Micro import Lens.Micro.Mtl import Text.Pandoc.Shared (blocksToInlines)@@ -48,9 +45,11 @@ runSubfigures :: Attr -> [Block] -> [Inline] -> WS (ReplacedResult Block) runSubfigures (label, cls, attrs) images caption = do   opts <- ask-  idxStr <- replaceAttr (Right label) attrs caption SPfxImg+  ref <- replaceAttr (Just label) attrs caption SPfxImg+  idxStr <- chapIndex ref   glob <- use stGlob-  let (cont, st) = flip runState (References def def glob)+  hiddenHdr <- use stHiddenHeaderLevel+  let (cont, st) = flip runState (References def def glob hiddenHdr)         $ flip runReaderT opts'         $ runWS         $ runReplace (mkRR replaceSubfigs `extRR` doFigure) images@@ -59,7 +58,7 @@       doFigure _ = noReplaceRecurse       opts' = opts           { figureTemplate = subfigureChildTemplate opts-          , customLabel = \r i -> customLabel opts ("sub"<>r) i+          , customLabel = \r i -> customLabel opts (Sub r) i           }       collectedCaptions = B.toList $           intercalate' (B.fromList $ ccsDelim opts)@@ -84,15 +83,13 @@       mangleSubfigure v = v{refIndex = refIndex lastRef, refSubfigure = Just $ refIndex v}   refsAt PfxImg %= (<> mangledSubfigures)   stGlob .= st ^. stGlob-  if  | isLatexFormat opts ->+  -- stHiddenHeaderLevel shouldn't have changed, but for future-proofing...+  stHiddenHeaderLevel .= st ^. stHiddenHeaderLevel+  if  | isLatexFormat opts -> do           replaceNoRecurse $ Div nullAttr $             [ RawBlock (Format "latex") "\\begin{pandoccrossrefsubfigures}" ]             <> cont <>-            [ Para [RawInline (Format "latex") "\\caption["-                      , Span nullAttr (removeFootnotes caption)-                      , RawInline (Format "latex") "]"-                      , Span nullAttr caption]-            , RawBlock (Format "latex") $ mkLaTeXLabel label+            [ Para $ latexCaption ref             , RawBlock (Format "latex") "\\end{pandoccrossrefsubfigures}"]       | otherwise ->           replaceNoRecurse@@ -100,12 +97,8 @@                      (Caption Nothing [Para capt])             $ toTable opts cont   where-    removeFootnotes = walk removeFootnote-    removeFootnote Note{} = Str ""-    removeFootnote x = x     toTable :: Options -> [Block] -> [Block]     toTable opts blks-      | isLatexFormat opts = concatMap imagesToFigures blks       | subfigGrid opts = [simpleTable align (map ColWidth widths) (map (fmap pure . blkToRow) blks)]       | otherwise = blks       where@@ -146,56 +139,39 @@ replaceSubfigs :: [Inline] -> WS (ReplacedResult [Inline]) replaceSubfigs = (replaceNoRecurse . concat) <=< mapM replaceSubfig -imagesToFigures :: Block -> [Block]-imagesToFigures = \case-  x@Figure{} -> [x]-  Para xs -> mapMaybe imageToFigure xs-  Plain xs -> mapMaybe imageToFigure xs-  _ -> []--imageToFigure :: Inline -> Maybe Block-imageToFigure = \case-  Image (label,cls,attrs) alt tgt -> Just $-    Figure (label, cls, []) (Caption Nothing [Para alt])-      [Plain [Image ("",cls,attrs) alt tgt]]-  _ -> Nothing- replaceSubfig :: Inline -> WS [Inline] replaceSubfig x@(Image (label,cls,attrs) alt tgt) = do   opts <- ask-  let label' = normalizeLabel label-  idxStr <- replaceAttr label' attrs alt SPfxImg+  ref <- replaceAttr (normalizeLabel label) attrs alt SPfxImg+  idxStr <- chapIndex ref   let alt' = applyTemplate idxStr alt $ figureTemplate opts   pure $ if isLatexFormat opts-    then latexSubFigure x label-    else [Image (label, cls, setLabel opts idxStr attrs) alt' tgt]+    then latexSubFigure x ref+    else [Image (fromMaybe "" (refLabel ref), cls, setLabel opts idxStr attrs) alt' tgt] replaceSubfig x = pure [x] -latexSubFigure :: Inline -> T.Text -> [Inline]-latexSubFigure (Image (_, cls, attrs) alt (src, title)) label =+latexSubFigure :: Inline -> RefRec -> [Inline]+latexSubFigure (Image (_, cls, attrs) alt (src, title)) ref =   let     title' = fromMaybe title $ T.stripPrefix "fig:" title-    texlabel | T.null label = []-             | otherwise = [RawInline (Format "latex") $ mkLaTeXLabel label]     texalt | "nocaption" `elem` cls  = []            | otherwise = concat               [ [ RawInline (Format "latex") "["]               , alt               , [ RawInline (Format "latex") "]"]               ]-    img = Image (label, cls, attrs) alt (src, title')+    img = Image (fromMaybe "" (refLabel ref), cls, attrs) alt (src, title')   in concat [       [ RawInline (Format "latex") "\\subfloat" ]       , texalt-      , [Span nullAttr $ img:texlabel]+      , [Span nullAttr $ img : latexLabel ref]       ] latexSubFigure x _ = [x] -normalizeLabel :: T.Text -> Either T.Text T.Text+normalizeLabel :: T.Text -> Maybe T.Text normalizeLabel label-  | "fig:" `T.isPrefixOf` label = Right label-  | T.null label = Left "fig"-  | otherwise  = Right $ "fig:" <> label+  | T.null label = Nothing+  | otherwise  = Just label  simpleTable :: [Alignment] -> [ColWidth] -> [[[Block]]] -> Block simpleTable align width bod = Table nullAttr noCaption (zip align width)@@ -219,15 +195,19 @@             -- https://github.com/jgm/pandoc/issues/9720             (fattrs <> as, \capt -> [Plain [Image attr capt tgt]])         _ -> (fattrs, const content)-  idxStr <- replaceAttr label' attrs title SPfxImg+  ref <- replaceAttr label' attrs title SPfxImg+  idxStr <- chapIndex ref+  let listHidden = refHideFromList ref+  let short' | listHidden = Just mempty+             | otherwise = short   let title'         | isLatexFormat opts = title         | otherwise = applyTemplate idxStr title $ figureTemplate opts-      caption' = Caption short (walkReplaceInlines title' title btitle:rest)+      caption' = Caption short' (walkReplaceInlines title' title btitle:rest)   replaceNoRecurse $     if subFigure && isLatexFormat opts     then Plain $ case blocksToInlines content of-      ctHead:_ -> latexSubFigure ctHead label+      ctHead:_ -> latexSubFigure ctHead ref       _ -> 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/Blocks/Table.hs view
@@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts #-}- module Text.Pandoc.CrossRef.References.Blocks.Table where  import Control.Monad.Reader.Class@@ -29,6 +27,7 @@  import Text.Pandoc.CrossRef.References.Monad import Text.Pandoc.CrossRef.References.Blocks.Util+import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.Util.Options import Text.Pandoc.CrossRef.Util.Template import Text.Pandoc.CrossRef.Util.Util@@ -36,11 +35,14 @@ runTable :: Attr -> Maybe Attr -> Maybe ShortCaption -> Block -> [Block] -> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> WS (ReplacedResult Block) runTable (label, clss, attrs) mtattr short btitle rest colspec header cells foot = do   opts <- ask-  idxStr <- replaceAttr (Right label) attrs title SPfxTbl-  let title'-        | isLatexFormat opts = RawInline (Format "latex") (mkLaTeXLabel label) : title+  ref <- replaceAttr (Just label) attrs title SPfxTbl+  idxStr <- chapIndex ref+  let short' | refHideFromList ref = Just mempty+             | otherwise = short+      title'+        | isLatexFormat opts = latexLabel ref <> title         | otherwise = applyTemplate idxStr title $ tableTemplate opts-      caption' = Caption short (walkReplaceInlines title' title btitle:rest)+      caption' = Caption short' (walkReplaceInlines title' title btitle:rest)       label' | isLatexFormat opts = ""              | otherwise = label   replaceNoRecurse $ (mtattr &
lib-internal/Text/Pandoc/CrossRef/References/Blocks/Util.hs view
@@ -18,23 +18,35 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, RecordWildCards, ViewPatterns-  , LambdaCase #-}--module Text.Pandoc.CrossRef.References.Blocks.Util where+module Text.Pandoc.CrossRef.References.Blocks.Util+  ( replaceAttr+  , SPrefix(..)+  , latexCaption+  , latexCaptionRaw+  , chapIndex+  , mkCaption+  , setLabel+  , checkHidden+  , latexLabel+  , walkReplaceInlines+  ) where  import Control.Monad.Reader.Class import qualified Data.Map as M+import qualified Data.Set as Set+import Data.Set (Set) import qualified Data.Text as T import Text.Pandoc.Definition import Text.Pandoc.Shared (stringify) import Text.Pandoc.Walk (walk) import Control.Monad (when)+import Data.Maybe (fromMaybe)  import Text.Read (readMaybe)  import Control.Applicative import Lens.Micro.Mtl+import Text.Pandoc.Shared (deNote) import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.References.Monad import Text.Pandoc.CrossRef.Util.Options@@ -73,11 +85,11 @@   SPfxLst -> PfxLst  replaceAttr-  :: Either T.Text T.Text -- ^ Reference id+  :: Maybe T.Text -- ^ Reference id   -> [(T.Text, T.Text)] -- ^ Attributes   -> [Inline] -- ^ Title   -> SPrefix -- ^ Prefix type-  -> WS [Inline]+  -> WS RefRec replaceAttr label attrs title (toPrefix -> pfx) = do   let refLabel = lookup "label" attrs       number = readMaybe . T.unpack =<< lookup "number" attrs@@ -90,22 +102,102 @@         , chap' == chap         = succ . fst $ last'         | otherwise = 1-      index = chap S.|> (i, refLabel <|> customLabel ref i)-      ref = either id (T.takeWhile (/=':')) label-      label' = either (<> T.pack (':' : show index)) id label+      index = chap S.|> (i, refLabel <|> customLabel (Pfx pfx) i)+      label' = fromMaybe (T.pack (show pfx <> (':' : show index))) label   when (M.member label' prop') $     error . T.unpack $ "Duplicate label: " <> label'   globCtr <- stGlob <<%= (+ 1)   ctrsAt pfx .= index-  refsAt pfx %= M.insert label' RefRec {-    refIndex= index-  , refGlobal = globCtr-  , refTitle= title-  , refSubfigure = Nothing-  }-  return $ chapPrefix chapDelim index+  refHideFromList <- checkHidden attrs+  let rec' = RefRec {+      refIndex= index+    , refGlobal = globCtr+    , refTitle= title+    , refSubfigure = Nothing+    , refHideFromList+    , refLabel = label+    }+  refsAt pfx %= M.insert label' rec'+  pure rec' +chapIndex :: RefRec -> WS [Inline]+chapIndex r = do+  Options{chapDelim} <- ask+  pure $ chapPrefix chapDelim $ refIndex r+ mkCaption :: Options -> T.Text -> [Inline] -> Block mkCaption opts style   | outFormat opts == Just (Format "docx") = Div ("", [], [("custom-style", style)]) . return . Para   | otherwise = Para++latexLabel :: RefRec -> [Inline]+latexLabel RefRec{refLabel}+  | Just lab <- refLabel = [ RawInline (Format "latex") $ mkLaTeXLabel lab ]+  | otherwise = mempty++latexCaption :: RefRec -> [Inline]+latexCaption ref = latexCaptionGeneric lcsRich ref <> latexLabel ref+  where+    lcsRich = LatexCaptionSpec+      { lcsEmptyShort = \caption ->+          [ RawInline (Format "latex") "\\caption[]", Span nullAttr caption ]+      , lcsWithoutShort = \caption ->+          [ RawInline (Format "latex") "\\caption", Span nullAttr caption ]+      , lcsWithShort = \(Short short) long ->+          [ RawInline (Format "latex") "\\caption["+          , Span nullAttr short+          , RawInline (Format "latex") "]"+          , Span nullAttr long ]+      }++data LatexCaptionSpec a = LatexCaptionSpec+  { lcsEmptyShort :: [Inline] -> a+  , lcsWithShort :: Short -> [Inline] -> a+  , lcsWithoutShort :: [Inline] -> a+  }++newtype Short = Short [Inline]+  deriving Eq++-- | Only used in lstlistings code blocks.+latexCaptionRaw :: RefRec -> T.Text+latexCaptionRaw = latexCaptionGeneric lcsRaw+  where+    lcsRaw = LatexCaptionSpec+      { lcsEmptyShort = \caption -> "[]" <> stringify caption+      , lcsWithShort = \(Short short) long -> "[" <> stringify short <> "]" <> stringify long+      , lcsWithoutShort = stringify+      }++latexCaptionGeneric :: Monoid a => LatexCaptionSpec a -> RefRec -> a+latexCaptionGeneric LatexCaptionSpec{..} ref+  | refHideFromList ref = lcsEmptyShort caption+  | Short (refTitle ref) == sansFootnotes = lcsWithoutShort caption+  | otherwise = lcsWithShort sansFootnotes caption+  where+    caption = refTitle ref+    sansFootnotes = Short $ walk deNote caption++checkHidden :: [(T.Text, T.Text)] -> WS Bool+checkHidden attrs = do+  hiddenHdr <- use stHiddenHeaderLevel+  pure . fromMaybe (isHdrHidden hiddenHdr) $+    not . isFalseValue <$> lookup "hidden" attrs++isFalseValue :: T.Text -> Bool+isFalseValue = (`Set.member` falseValues) . T.strip . T.toLower++falseValues :: Set T.Text+falseValues = Set.fromList+  [ "no"+  , "n"+  , "false"+  , "f"+  , "off"+  , "0"+  , "none"+  , "null"+  , "disable"+  , "disabled"+  , "unset"+  ]
lib-internal/Text/Pandoc/CrossRef/References/List.hs view
@@ -18,14 +18,13 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings, RecordWildCards, LambdaCase #-}-module Text.Pandoc.CrossRef.References.List (listOf) where+module Text.Pandoc.CrossRef.References.List (listOf, listOfFigures, listOfTables, listOfListings) where  import Data.List import Control.Monad.Reader import qualified Data.Map as M-import qualified Data.Text as T import Text.Pandoc.Definition+import Text.Pandoc.Builder qualified as B import Data.Maybe  import Lens.Micro.Mtl@@ -41,28 +40,31 @@   False -> case blocks of     (RawBlock fmt "\\listoffigures":xs)       | isLaTeXRawBlockFmt fmt-      -> use (refsAt PfxImg) >>= makeList "fig" lofItemTemplate lofTitle xs+      -> (<> xs) <$> listOfFigures     (RawBlock fmt "\\listoftables":xs)       | isLaTeXRawBlockFmt fmt-      -> use (refsAt PfxTbl) >>= makeList "tbl" lotItemTemplate lotTitle xs+      -> (<> xs) <$> listOfTables     (RawBlock fmt "\\listoflistings":xs)       | isLaTeXRawBlockFmt fmt-      -> use (refsAt PfxLst) >>= makeList "lst" lolItemTemplate lolTitle xs+      -> (<> xs) <$> listOfListings     _ -> pure blocks +listOfFigures, listOfTables, listOfListings:: WS [Block]+listOfFigures = makeList PfxImg lofItemTemplate lofTitle+listOfTables = makeList PfxTbl lotItemTemplate lotTitle+listOfListings = makeList PfxLst lolItemTemplate lolTitle+ makeList-  :: T.Text+  :: Prefix   -> (Options -> BlockTemplate)   -> (Options -> [Block])-  -> [Block]-  -> M.Map T.Text RefRec   -> WS [Block]-makeList pfx tf titlef xs refs = do+makeList pfx tf titlef = do   o <- ask-  pure $ titlef o <> (Div ("", ["list", "list-of-" <> pfx], []) (items o) : xs)-  where-    items o = let is = items' o in fromMaybe is $ pure <$> mergeList Nothing [] is-    items' o = concatMap (itemChap o . snd) refsSorted+  refs <- use $ refsAt pfx+  let+    items = fromMaybe items' $ pure <$> mergeList Nothing [] items'+    items' = concatMap (itemChap . snd) refsSorted     mergeList Nothing acc (OrderedList style item : ys) =       mergeList (Just $ OrderedList style) (item <> acc) ys     mergeList Nothing acc (BulletList item : ys) =@@ -75,27 +77,31 @@       mergeList (Just BulletList) (item <> acc) ys     mergeList (Just cons) acc [] = Just $ cons $ reverse acc     mergeList _ _ _ = Nothing-    refsSorted = sortBy compare' $ M.toList refs+    refsSorted = sortBy compare' $ filter notHidden $ M.toList refs+    notHidden (_, RefRec{refHideFromList}) = not refHideFromList     compare'       (_,RefRec{refGlobal=i})       (_,RefRec{refGlobal=j})       = compare i j-    itemChap :: Options -> RefRec -> [Block]-    itemChap o ref@RefRec{..} = applyTemplate (numWithChap o ref) refTitle (tf o)-    numWithChap :: Options -> RefRec -> [Inline]-    numWithChap Options{..} RefRec{..} = case refSubfigure of-      Nothing ->-        let vars = M.fromDistinctAscList-              [ ("i", chapPrefix chapDelim refIndex)-              , ("suf", mempty)-              , ("t", refTitle)-              ]-        in applyTemplate' vars $ refIndexTemplate pfx-      Just s ->-        let vars = M.fromDistinctAscList-              [ ("i", chapPrefix chapDelim refIndex)-              , ("s", chapPrefix chapDelim s)-              , ("suf", mempty)-              , ("t", refTitle)-              ]-        in applyTemplate' vars subfigureRefIndexTemplate+    itemChap :: RefRec -> [Block]+    itemChap ref@RefRec{..} =+      let vars = M.fromDistinctAscList $+            [ ("i", numWithChap vars ref)+            , ("lt", linked refLabel refTitle)+            , ("ri", chapPrefix chapDelim refIndex)+            , ("s", maybe mempty (chapPrefix chapDelim) refSubfigure)+            , ("suf", mempty)+            , ("t", refTitle)+            ]+      in applyTemplate' vars $ tf o+      where+        Options{chapDelim} = o+    linked (Just lab) = B.toList . B.link ("#" <> lab) "" . B.fromList+    linked Nothing = id+    numWithChap vars RefRec{..} = applyTemplate' vars' $ case refSubfigure of+      Nothing -> refIndexTemplate pfx+      Just _ -> subfigureRefIndexTemplate+      where+        vars' = M.insert "i" (chapPrefix chapDelim refIndex) vars+        Options{chapDelim, refIndexTemplate, subfigureRefIndexTemplate} = o+  pure $ titlef o <> [Div ("", ["list", "list-of-" <> pfxText pfx], []) items]
lib-internal/Text/Pandoc/CrossRef/References/Monad.hs view
@@ -18,7 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Text.Pandoc.CrossRef.References.Monad where  import Control.Monad.State
lib-internal/Text/Pandoc/CrossRef/References/Refs.hs view
@@ -18,12 +18,12 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings, LambdaCase, RankNTypes #-} module Text.Pandoc.CrossRef.References.Refs (replaceRefs) where  import Control.Arrow as A import Control.Monad.Reader import Data.Function+import Numeric.Natural import Data.List import qualified Data.List.HT as HT import qualified Data.Map as M@@ -49,12 +49,10 @@   opts <- ask :: WS Options   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 (***)+    eqPrefix = (==) `on` getLabelPrefix . citationId     replaceRefs' :: Options -> NonEmpty Citation -> WS [Inline]     replaceRefs' opts cits'-      | Just prefix <- allCitsPrefix cits'+      | Just prefix <- getLabelPrefix . citationId $ NE.head cits'       = replaceRefs'' opts prefix cits'       | otherwise = return [Cite (NE.toList cits') il']         where@@ -72,23 +70,6 @@       else replaceRefsOther replaceRefs x = return x -pfxMap :: T.Text -> Maybe Prefix-pfxMap = \case-  "fig:" -> Just PfxImg-  "eq:"  -> Just PfxEqn-  "tbl:" -> Just PfxTbl-  "lst:" -> Just PfxLst-  "sec:" -> Just PfxSec-  _ -> Nothing--pfxMapR :: Prefix -> T.Text-pfxMapR = \case-  PfxImg -> "fig:"-  PfxEqn -> "eq:"-  PfxTbl -> "tbl:"-  PfxLst -> "lst:"-  PfxSec -> "sec:"- -- accessors to options prefMap :: Prefix -> (Options -> Bool -> Int -> [Inline], Options -> Template) prefMap = \case@@ -108,12 +89,6 @@   where (refprefixf, reftempl) = prefMap prefix         refprefix = refprefixf opts capitalize num -allCitsPrefix :: NonEmpty Citation -> Maybe Prefix-allCitsPrefix cits = find isCitationPrefix prefixes-  where-  isCitationPrefix p =-    all ((pfxMapR p `T.isPrefixOf`) . uncapitalizeFirst . citationId) cits- replaceRefsLatex :: Prefix -> Options -> NonEmpty Citation -> WS [Inline] replaceRefsLatex prefix opts cits   | cref opts@@ -140,7 +115,7 @@       | noPrefix       = getRefPrefix opts prefix cap (length cits - 1)       | otherwise = ((citationPrefix (NE.head cits) <> [Space]) <>)-    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . NE.head $ cits+    cap = isFirstUpper . citationId . NE.head $ cits     cref' | suppressAuthor = "\\labelcref"           | cap = "\\Cref"           | otherwise = "\\cref"@@ -148,19 +123,17 @@ 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)+  . map ((p <>) . (<> s) . mkLaTeXLabel' . (pfxTextCol prefix <>) . getLabelWithoutPrefix . citationId)   . NE.toList   getLabelWithoutPrefix :: T.Text -> T.Text getLabelWithoutPrefix = T.drop 1 . T.dropWhile (/=':') -getLabelPrefix :: T.Text -> Maybe T.Text-getLabelPrefix lab-  | Just pfx <- pfxMap (uncapitalizeFirst p)-  , pfx `elem` prefixes = Just p-  | otherwise = Nothing-  where p = flip T.snoc ':' . T.takeWhile (/=':') $ lab+getLabelPrefix :: T.Text -> Maybe Prefix+getLabelPrefix lab = find (p `hasPfx`) prefixes+  where+    p = uncapitalizeFirst $ flip T.snoc ':' . T.takeWhile (/=':') $ lab  replaceRefsOther :: Prefix -> Options -> NonEmpty Citation -> WS [Inline] replaceRefsOther prefix opts cits = toList . intercalate' (text ", ") . map fromList <$>@@ -173,7 +146,7 @@ replaceRefsOther' prefix opts cits = do   indices <- mapM (getRefIndex prefix opts) $ NE.toList cits   let-    cap = maybe False isFirstUpper $ getLabelPrefix . citationId . NE.head $ cits+    cap = isFirstUpper . citationId . NE.head $ cits     writePrefix | all ((==SuppressAuthor) . citationMode) cits                 = id                 | all (null . citationPrefix) cits@@ -185,17 +158,15 @@     cmap f x = f x   return $ writePrefix (makeIndices opts indices) -data RefData = RefData { rdLabel :: T.Text+data RefData = RefData { rdGlob :: Maybe Natural+                       , rdLabel :: T.Text                        , rdIdx :: Maybe Index                        , rdSubfig :: Maybe Index                        , rdSuffix :: [Inline]                        , rdTitle :: Maybe [Inline]-                       , rdPfx :: T.Text+                       , rdPfx :: Prefix                        } deriving (Eq) -instance Ord RefData where-  (<=) = (<=) `on` rdIdx- getRefIndex :: Prefix -> Options -> Citation -> WS RefData getRefIndex prefix _opts Citation{citationId=cid,citationSuffix=suf}   = do@@ -203,22 +174,24 @@     let sub = refSubfigure <$> ref         idx = refIndex <$> ref         tit = refTitle <$> ref+        glob = refGlobal <$> ref     return RefData-      { rdLabel = lab+      { rdGlob = glob+      , rdLabel = lab       , rdIdx = idx       , rdSubfig = join sub       , rdSuffix = suf       , rdTitle = tit-      , rdPfx = pfxMapR prefix+      , rdPfx = prefix       }   where   prop = refsAt prefix-  lab = pfxMapR prefix <> getLabelWithoutPrefix cid+  lab = pfxTextCol prefix <> getLabelWithoutPrefix cid  data RefItem = RefRange RefData RefData | RefSingle RefData  makeIndices :: Options -> [RefData] -> [Inline]-makeIndices o s = format $ concatMap f $ HT.groupBy g $ sort $ nub s+makeIndices o = format . concatMap f . HT.groupBy g . sortOn rdGlob . nub   where   g :: RefData -> RefData -> Bool   g a b = all (null . rdSuffix) [a, b] && (@@ -270,7 +243,7 @@                       , ("suf", suf)                       , ("t", fromMaybe mempty tit)                       ]-          in applyTemplate' vars $ refIndexTemplate o (T.dropEnd 1 pfx)+          in applyTemplate' vars $ refIndexTemplate o pfx   show' RefData{rdLabel=l, rdIdx=Nothing, rdSuffix = suf} =     trace (T.unpack $ "Undefined cross-reference: " <> l)           (strong (text $ "¿" <> l <> "?") <> fromList suf)
lib-internal/Text/Pandoc/CrossRef/References/Types.hs view
@@ -18,13 +18,13 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE TemplateHaskell, GeneralizedNewtypeDeriving, RankNTypes, DataKinds #-} module Text.Pandoc.CrossRef.References.Types where  import Data.Default import Numeric.Natural import qualified Data.Map as M import Data.Text (Text)+import qualified Data.Text as T import Lens.Micro.GHC import Lens.Micro.TH import Text.Pandoc.Definition@@ -36,6 +36,8 @@                      , refGlobal :: Natural                      , refTitle :: [Inline]                      , refSubfigure :: Maybe Index+                     , refHideFromList :: Bool+                     , refLabel :: Maybe Text                      } deriving (Show, Eq)  type RefMap = M.Map Text RefRec@@ -48,14 +50,46 @@   | PfxSec   deriving (Eq, Ord, Enum, Bounded, Show) +pfxText :: Prefix -> Text+pfxText = \case+  PfxEqn -> "eq"+  PfxImg -> "fig"+  PfxLst -> "lst"+  PfxSec -> "sec"+  PfxTbl -> "tbl"++pfxTextCol :: Prefix -> Text+pfxTextCol = (<> ":") . pfxText++hasPfx :: Text -> Prefix -> Bool+hasPfx lab pfx = pfxTextCol pfx `T.isPrefixOf` lab++data SubPfx = Pfx Prefix | Sub SubPfx+  deriving (Eq, Show)++subPfxText :: SubPfx -> Text+subPfxText = \case+  Pfx pfx -> pfxText pfx+  Sub pfx -> "sub" <> subPfxText pfx+ -- state data type data References = References { _stRefs :: M.Map Prefix RefMap                              , _stCtrs :: M.Map Prefix Index                              , _stGlob :: Natural+                             , _stHiddenHeaderLevel :: [HiddenHeader]                              } deriving (Show, Eq) +data HiddenHeader = HiddenHeader+  { hhLevel :: Int+  , hhHidden :: Bool+  } deriving (Show, Eq)++isHdrHidden :: [HiddenHeader] -> Bool+isHdrHidden [] = False+isHdrHidden (HiddenHeader{..}:_) = hhHidden+ instance Default References where-  def = References mempty mempty 0+  def = References mempty mempty 0 mempty  makeLenses ''References 
lib-internal/Text/Pandoc/CrossRef/Util/CodeBlockCaptions.hs view
@@ -18,7 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings, LambdaCase #-} module Text.Pandoc.CrossRef.Util.CodeBlockCaptions     (     mkCodeBlockCaptions@@ -28,6 +27,7 @@ import Data.List (stripPrefix) import Data.Maybe (fromMaybe) import qualified Data.Text as T+import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.References.Monad import Text.Pandoc.CrossRef.Util.Options import Text.Pandoc.CrossRef.Util.Util@@ -49,13 +49,13 @@   | codeBlockCaptions opts   , Just caption <- getCodeBlockCaption ils   , not $ T.null label-  , "lst" `T.isPrefixOf` label+  , label `hasPfx` PfxLst   = return $ Div (label,["listing"], [])       [Para caption, CodeBlock ("",classes,attrs) code] : xs orderAgnostic opts (Para ils:CodeBlock (_,classes,attrs) code:xs)   | codeBlockCaptions opts   , Just (caption, labinl) <- splitLast <$> getCodeBlockCaption ils-  , Just label <- getRefLabel "lst" labinl+  , Just label <- getRefLabel PfxLst labinl   = return $ Div (label,["listing"], [])       [Para $ init caption, CodeBlock ("",classes,attrs) code] : xs   where
lib-internal/Text/Pandoc/CrossRef/Util/CustomLabels.hs view
@@ -18,19 +18,18 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.CustomLabels (customLabel, customHeadingLabel) where  import qualified Data.Text as T import Text.Numeral.Roman import Text.Pandoc.CrossRef.Util.Meta import Text.Pandoc.Definition+import Text.Pandoc.CrossRef.References.Types -customLabel :: Meta -> T.Text -> Int -> Maybe T.Text-customLabel meta ref i-  | refLabel <- T.takeWhile (/=':') ref-  , Just cl <- lookupMeta (refLabel <> "Labels") meta-  = mkLabel i (refLabel <> "Labels") cl+customLabel :: Meta -> SubPfx -> Int -> Maybe T.Text+customLabel meta pfx i+  | Just cl <- lookupMeta (subPfxText pfx <> "Labels") meta+  = mkLabel i (subPfxText pfx <> "Labels") cl   | otherwise = Nothing  customHeadingLabel :: Meta -> Int -> Int -> Maybe T.Text
lib-internal/Text/Pandoc/CrossRef/Util/Meta.hs view
@@ -18,7 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE FlexibleContexts, Rank2Types #-} module Text.Pandoc.CrossRef.Util.Meta (     getMetaList   , getMetaBool
lib-internal/Text/Pandoc/CrossRef/Util/ModifyMeta.hs view
@@ -18,28 +18,40 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.ModifyMeta     (     modifyMeta     ) where  import Control.Monad.Writer-import Control.Monad (when, unless)+import Control.Monad (when, unless, (>=>))+import Data.Function ((&)) import qualified Data.Text as T import Text.Pandoc import Text.Pandoc.Builder hiding ((<>)) import Text.Pandoc.CrossRef.Util.Meta import Text.Pandoc.CrossRef.Util.Options+import Text.Pandoc.CrossRef.References.List+import Text.Pandoc.CrossRef.References.Monad -modifyMeta :: Options -> Meta -> Meta+modifyMeta :: Options -> Meta -> WS Meta modifyMeta opts meta-  | isLatexFormat opts-  = setMeta "header-includes"-      (headerInc $ lookupMeta "header-includes" meta)-      meta-  | otherwise = meta+  = meta+    & opt isLatexFormat (setMeta "header-includes" (headerInc $ lookupMeta "header-includes" meta))+    & optM listOfMetadata+        ( setMetaM "list-of-figures"    (fromList <$> listOfFigures)+        >=> setMetaM "list-of-tables"   (fromList <$> listOfTables)+        >=> setMetaM "list-of-listings" (fromList <$> listOfListings)+        )   where+    setMetaM :: ToMetaValue v => T.Text -> WS v -> Meta -> WS Meta+    setMetaM k m meta' = m >>= \v -> pure $ setMeta k v meta'+    opt q f+      | q opts = f+      | otherwise = id+    optM q f+      | q opts = f+      | otherwise = pure     headerInc :: Maybe MetaValue -> MetaValue     headerInc Nothing = incList     headerInc (Just (MetaList x)) = MetaList $ x <> [incList]
lib-internal/Text/Pandoc/CrossRef/Util/Options.hs view
@@ -18,11 +18,10 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings#-}- module Text.Pandoc.CrossRef.Util.Options (Options(..), isLatexFormat, isDocxFormat) where import Data.Text (Text) import Text.Pandoc.CrossRef.Util.Template+import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.Util.Util (isFormat) import Text.Pandoc.Definition @@ -52,7 +51,7 @@                        , eqnInlineTemplate :: Template                        , eqnInlineTableTemplate :: Template                        , eqnDisplayTemplate :: Template-                       , refIndexTemplate :: Text -> Template+                       , refIndexTemplate :: Prefix -> Template                        , subfigureRefIndexTemplate :: Template                        , secHeaderTemplate :: Template                        , chapDelim   :: [Inline]@@ -70,7 +69,7 @@                        , ccsTemplate :: Template                        , tableTemplate  :: Template                        , listingTemplate :: Template-                       , customLabel :: Text -> Int -> Maybe Text+                       , customLabel :: SubPfx -> Int -> Maybe Text                        , customHeadingLabel :: Int -> Int -> Maybe Text                        , ccsDelim :: [Inline]                        , ccsLabelSep :: [Inline]@@ -81,6 +80,7 @@                        , nameInLink :: Bool                        , setLabelAttribute :: Bool                        , equationNumberTeX :: Text+                       , listOfMetadata :: Bool                        }  isLatexFormat :: Options -> Bool
lib-internal/Text/Pandoc/CrossRef/Util/Settings.hs view
@@ -19,7 +19,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.Settings (getSettings, defaultMeta) where  import Control.Exception (IOException, handle)@@ -112,6 +111,7 @@   <> lofTitle (header 1 $ text "List of Figures")   <> lotTitle (header 1 $ text "List of Tables")   <> lolTitle (header 1 $ text "List of Listings")+  <> listOfMetadata False   <> figureTemplate (var "figureTitle" <> space <> var "i" <> var "titleDelim" <> space <> var "t")   <> tableTemplate (var "tableTitle" <> space <> var "i" <> var "titleDelim" <> space <> var "t")   <> listingTemplate (var "listingTitle" <> space <> var "i" <> var "titleDelim" <> space <> var "t")
lib-internal/Text/Pandoc/CrossRef/Util/Settings/Gen.hs view
@@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}--- {-# OPTIONS_GHC -ddump-splices #-} module Text.Pandoc.CrossRef.Util.Settings.Gen where  import Language.Haskell.TH (mkName)
lib-internal/Text/Pandoc/CrossRef/Util/Settings/Template.hs view
@@ -18,7 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE TemplateHaskell, RankNTypes, ViewPatterns, MultiWayIf #-} module Text.Pandoc.CrossRef.Util.Settings.Template where  import Data.List@@ -31,6 +30,7 @@ import Text.Pandoc.CrossRef.Util.CustomLabels import Text.Pandoc.CrossRef.Util.Meta import Text.Pandoc.CrossRef.Util.Template+import Text.Pandoc.CrossRef.References.Types  namedFields :: Con -> [VarStrictType] namedFields (RecC _ fs) = fs@@ -80,8 +80,8 @@     intT <- [t|$(conT t) -> Int|]     tmplT <- [t|$(conT t) -> Template|]     btmplT <- [t|$(conT t) -> BlockTemplate|]-    idxTmplT <- [t|$(conT t) -> Text -> Template|]-    clT <- [t|$(conT t) -> Text -> Int -> Maybe Text|]+    idxTmplT <- [t|$(conT t) -> Prefix -> Template|]+    clT <- [t|$(conT t) -> SubPfx -> Int -> Maybe Text|]     chlT <- [t|$(conT t) -> Int -> Int -> Maybe Text|]     let varName | Name (OccName n) _ <- accName = liftString n     let dtv = return $ VarE $ mkName "dtv"
lib-internal/Text/Pandoc/CrossRef/Util/Template.hs view
@@ -18,7 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE OverloadedStrings, MultiParamTypeClasses #-} module Text.Pandoc.CrossRef.Util.Template   ( Template   , BlockTemplate@@ -35,6 +34,7 @@ import qualified Data.Text as T import Text.Pandoc.Builder import Text.Pandoc.CrossRef.Util.Meta+import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.Generic import Text.Read @@ -55,7 +55,7 @@   applyTemplate' vars (BlockTemplate g) = g (internalVars vars)  makeTemplate :: MkTemplate a b => Meta -> [a] -> b-makeTemplate dtv xs' = mkTemplate $ \vf -> scan (\var -> vf var <|> lookupMeta var dtv) xs'+makeTemplate dtv xs' = mkTemplate \vf -> scan (\var -> vf var <|> lookupMeta var dtv) xs'   where   scan = bottomUp . go   go vf (x@(Math DisplayMath var):xs)@@ -74,14 +74,16 @@   go _ [] = []   replaceVar var val def' = maybe def' (toInlines ("variable " <> var)) val -makeIndexedTemplate :: T.Text -> Meta -> T.Text -> Template-makeIndexedTemplate name meta subname =+makeIndexedTemplate :: T.Text -> Meta -> Prefix -> Template+makeIndexedTemplate name meta pfx =   makeTemplate meta $ case lookupMeta name meta of     Just (MetaMap m) -> case lookupMeta subname (Meta m) of       Just x -> toInlines name x       Nothing -> getMetaInlines "default" (Meta m)     Just x -> toInlines name x     Nothing -> []+  where+    subname = pfxText pfx  internalVars :: M.Map T.Text [Inline] -> T.Text -> Maybe MetaValue internalVars vars x = MetaInlines <$> M.lookup x vars
lib-internal/Text/Pandoc/CrossRef/Util/Util.hs view
@@ -18,7 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE RankNTypes, OverloadedStrings, CPP #-} module Text.Pandoc.CrossRef.Util.Util   ( module Text.Pandoc.CrossRef.Util.Util   , module Data.Generics@@ -27,15 +26,12 @@ import Data.Char (isUpper, toLower, toUpper) import Data.Default import Data.Generics-import Data.List (find) import Data.Maybe (fromMaybe) import qualified Data.Text as T-import Data.Version import Text.Pandoc.Builder hiding ((<>)) import Text.Pandoc.Class import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.Writers.LaTeX-import Text.ParserCombinators.ReadP (readP_to_S) import qualified Data.Sequence as S  intercalate' :: (Eq a, Monoid a, Foldable f) => a -> f a -> a@@ -119,22 +115,13 @@             runPure (writeLaTeX def $ Pandoc nullMeta [Div (l, [], []) []])   in T.takeWhile (/='}') . T.drop 1 . T.dropWhile (/='{') $ ll -escapeLaTeX :: T.Text -> T.Text-escapeLaTeX l =-  let ll = either (error . show) id $-            runPure (writeLaTeX def $ Pandoc nullMeta [Plain [Str l]])-      pv = fmap fst . find (null . snd) . readP_to_S parseVersion $ VERSION_pandoc-      mv = makeVersion [2,11,0,1]-      cond = maybe False (mv >=) pv-  in if cond then ll else l--getRefLabel :: T.Text -> [Inline] -> Maybe T.Text+getRefLabel :: Prefix -> [Inline] -> Maybe T.Text getRefLabel _ [] = Nothing getRefLabel tag ils   | Str attr <- last ils   , all (==Space) (init ils)   , "}" `T.isSuffixOf` attr-  , ("{#"<>tag<>":") `T.isPrefixOf` attr+  , ("{#"<> pfxText tag <>":") `T.isPrefixOf` attr   = T.init `fmap` T.stripPrefix "{#" attr getRefLabel _ _ = Nothing 
lib/Text/Pandoc/CrossRef.hs view
@@ -42,8 +42,8 @@ >     go fmt p@(Pandoc meta _) = runCrossRefIO meta fmt action p >       where >         action (Pandoc _ bs) = do->           meta' <- crossRefMeta >           bs' <- crossRefBlocks bs+>           meta' <- crossRefMeta >           return $ Pandoc meta' bs'  This module also exports utility functions for setting up meta-settings for@@ -66,7 +66,6 @@ >       <> chaptersDepth (MetaString "2")  -}-{-# LANGUAGE RankNTypes #-}  module Text.Pandoc.CrossRef (     crossRefBlocks@@ -88,60 +87,51 @@ import Text.Pandoc.CrossRef.References.Monad import Text.Pandoc.CrossRef.Util.CodeBlockCaptions import Text.Pandoc.CrossRef.Util.ModifyMeta-import Text.Pandoc.CrossRef.Util.Options as O import Text.Pandoc.CrossRef.Util.Settings import Text.Pandoc.CrossRef.Util.Settings.Gen as SG --- | Enviromnent for 'CrossRefM'-data CrossRefEnv = CrossRefEnv {-                      creSettings :: Meta -- ^Metadata settings-                    , creOptions :: Options -- ^Internal pandoc-crossref options-                   }---- | Essentially a reader monad for basic pandoc-crossref environment-type CrossRefM a = R.Reader CrossRefEnv a+import Text.Pandoc.CrossRef.Internal  {- | Walk over blocks, while inserting cross-references, list-of, etc.  Works in 'CrossRefM' monad. -} crossRefBlocks :: [Block] -> CrossRefM [Block]-crossRefBlocks blocks = do-  opts <- R.asks creOptions-  let+crossRefBlocks blocks = CrossRefM $ R.withReaderT creOptions $ runWS doWalk+  where     doWalk =       bottomUpM mkCodeBlockCaptions blocks       >>= replaceAll       >>= bottomUpM replaceRefs       >>= bottomUpM listOf-    (result, st) = flip runState def $ flip R.runReaderT opts $ runWS doWalk-  st `seq` return result -{- | Modifies metadata for LaTeX output, adding header-includes instructions-to setup custom and builtin environments.+{- | Modifies metadata, adding header-includes instructions to setup custom and+builtin environments, plus list-of-x metadata fields if+'Text.Pandoc.CrossRef.Util.Settings.Gen.listOfMetadata' is enabled. -Note, that if output format is not "latex", this function does nothing.+Note for @listOfMetadata@ to work properly, this MUST be invoked AFTER+'crossRefBlocks'.  Works in 'CrossRefM' monad. -} crossRefMeta :: CrossRefM Meta crossRefMeta = do   opts <- R.asks creOptions   dtv <- R.asks creSettings-  return $ modifyMeta opts dtv+  CrossRefM $ R.withReaderT creOptions $ runWS $ modifyMeta opts dtv  {- | Combines 'crossRefMeta' and 'crossRefBlocks'  Works in 'CrossRefM' monad. -} defaultCrossRefAction :: Pandoc -> CrossRefM Pandoc defaultCrossRefAction (Pandoc _ bs) = do-  meta' <- crossRefMeta   bs' <- crossRefBlocks bs+  meta' <- crossRefMeta   return $ Pandoc meta' bs'  {- | Run an action in 'CrossRefM' monad with argument, and return pure result.  This is primary function to work with 'CrossRefM' -} runCrossRef :: forall a b. Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> b-runCrossRef meta fmt action arg = R.runReader (action arg) env+runCrossRef meta fmt action arg = runCrossRefInternal env $ action arg   where     settings = defaultMeta <> meta     env = CrossRefEnv {@@ -161,4 +151,9 @@             creSettings = settings           , creOptions = getOptions settings fmt          }-  return $ R.runReader (action arg) env+  pure $ runCrossRefInternal env $ action arg++runCrossRefInternal :: CrossRefEnv -> CrossRefM b -> b+runCrossRefInternal env (CrossRefM action) =+  let (res, st) = flip runState def $ flip R.runReaderT env action+   in st `seq` res
+ lib/Text/Pandoc/CrossRef/Internal.hs view
@@ -0,0 +1,51 @@+{-+pandoc-crossref is a pandoc filter for numbering figures,+equations, tables and cross-references to them.+Copyright (C) 2015  Nikolay Yakimov <root@livid.pp.ru>++This program is free software; you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation; either version 2 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License along+with this program; if not, write to the Free Software Foundation, Inc.,+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.+-}++{- |+   Module      : Text.Pandoc.CrossRef.Internal+   Copyright   : Copyright (C) 2025 Nikolay Yakimov+   License     : GNU GPL, version 2 or above++   Maintainer  : Nikolay Yakimov <root@livid.pp.ru>+   Stability   : alpha+   Portability : portable++Internal definitions, exported only for convenience. No stability guarantees.++-}++module Text.Pandoc.CrossRef.Internal (CrossRefEnv(..), CrossRefM(..)) where++import qualified Control.Monad.Reader as R+import Control.Monad.State+import Text.Pandoc++import Text.Pandoc.CrossRef.References+import Text.Pandoc.CrossRef.Util.Options++-- | Enviromnent for 'CrossRefM'+data CrossRefEnv = CrossRefEnv {+                      creSettings :: Meta -- ^Metadata settings+                    , creOptions :: Options -- ^Internal pandoc-crossref options+                   }++-- | Reader + State monad for pandoc-crossref.+newtype CrossRefM a = CrossRefM (R.ReaderT CrossRefEnv (State References) a)+  deriving (Functor, Applicative, Monad, R.MonadReader CrossRefEnv, MonadState References)
pandoc-crossref.cabal view
@@ -1,11 +1,11 @@ cabal-version: 2.0 --- This file has been generated from package.yaml by hpack version 0.37.0.+-- This file has been generated from package.yaml by hpack version 0.36.1. -- -- see: https://github.com/sol/hpack  name:           pandoc-crossref-version:        0.3.18.2+version:        0.3.19 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@@ -75,6 +75,12 @@     test/m2m/listings-code-block-caption-278/expect.md     test/m2m/listings-code-block-caption-278/expect.tex     test/m2m/listings-code-block-caption-278/input.md+    test/m2m/listOfHidden/expect.md+    test/m2m/listOfHidden/expect.tex+    test/m2m/listOfHidden/input.md+    test/m2m/listOfLinked/expect.md+    test/m2m/listOfLinked/expect.tex+    test/m2m/listOfLinked/input.md     test/m2m/listOfOrdering/expect.md     test/m2m/listOfOrdering/expect.tex     test/m2m/listOfOrdering/input.md@@ -136,17 +142,27 @@ library   exposed-modules:       Text.Pandoc.CrossRef+      Text.Pandoc.CrossRef.Internal   hs-source-dirs:       lib+  default-extensions:+      OverloadedStrings+      LambdaCase+      TemplateHaskell+      RecordWildCards+      ViewPatterns+      MultiWayIf+      ApplicativeDo+      BlockArguments   ghc-options: -Wall   build-depends:-      base >=4.11 && <5+      base >=4.16 && <5     , mtl >=1.1 && <2.4     , pandoc >=3.1.8 && <3.7     , pandoc-crossref-internal     , pandoc-types ==1.23.*     , text >=1.2.2 && <2.2-  default-language: Haskell2010+  default-language: GHC2021  library pandoc-crossref-internal   exposed-modules:@@ -175,8 +191,17 @@       Text.Pandoc.CrossRef.Util.Util   hs-source-dirs:       lib-internal+  default-extensions:+      OverloadedStrings+      LambdaCase+      TemplateHaskell+      RecordWildCards+      ViewPatterns+      MultiWayIf+      ApplicativeDo+      BlockArguments   build-depends:-      base >=4.11 && <5+      base >=4.16 && <5     , containers >=0.1 && <0.7     , data-default >=0.4 && <0.8     , directory >=1 && <1.4@@ -192,7 +217,7 @@     , template-haskell >=2.7.0.0 && <3.0.0.0     , text >=1.2.2 && <2.2     , utility-ht >=0.0.11 && <0.1.0-  default-language: Haskell2010+  default-language: GHC2021  executable pandoc-crossref   main-is: pandoc-crossref.hs@@ -200,9 +225,18 @@       ManData   hs-source-dirs:       src+  default-extensions:+      OverloadedStrings+      LambdaCase+      TemplateHaskell+      RecordWildCards+      ViewPatterns+      MultiWayIf+      ApplicativeDo+      BlockArguments   ghc-options: -Wall -threaded   build-depends:-      base >=4.11 && <5+      base >=4.16 && <5     , deepseq >=1.4 && <1.6     , gitrev >=1.3.1 && <1.4     , open-browser ==0.2.*@@ -213,18 +247,27 @@     , template-haskell >=2.7.0.0 && <3.0.0.0     , temporary >=1.2 && <1.4     , text >=1.2.2 && <2.2-  default-language: Haskell2010+  default-language: GHC2021  test-suite test-integrative   type: exitcode-stdio-1.0   main-is: test-integrative.hs   hs-source-dirs:       test+  default-extensions:+      OverloadedStrings+      LambdaCase+      TemplateHaskell+      RecordWildCards+      ViewPatterns+      MultiWayIf+      ApplicativeDo+      BlockArguments   ghc-options: -Wall -fno-warn-unused-do-bind -threaded   build-tool-depends:       pandoc-cli:pandoc   build-depends:-      base >=4.11 && <5+      base >=4.16 && <5     , directory >=1 && <1.4     , filepath >=1.1 && <1.6     , hspec >=2.4.4 && <3@@ -232,7 +275,7 @@     , pandoc-crossref     , pandoc-types ==1.23.*     , text >=1.2.2 && <2.2-  default-language: Haskell2010+  default-language: GHC2021   if flag(enable_flaky_tests)     cpp-options: -DFLAKY @@ -246,9 +289,18 @@       Paths_pandoc_crossref   hs-source-dirs:       test+  default-extensions:+      OverloadedStrings+      LambdaCase+      TemplateHaskell+      RecordWildCards+      ViewPatterns+      MultiWayIf+      ApplicativeDo+      BlockArguments   ghc-options: -Wall -fno-warn-unused-do-bind -threaded   build-depends:-      base >=4.11 && <5+      base >=4.16 && <5     , containers >=0.1 && <0.7     , data-default >=0.4 && <0.8     , hspec >=2.4.4 && <3@@ -259,7 +311,7 @@     , pandoc-crossref-internal     , pandoc-types ==1.23.*     , text >=1.2.2 && <2.2-  default-language: Haskell2010+  default-language: GHC2021   if flag(enable_flaky_tests)     cpp-options: -DFLAKY @@ -270,12 +322,21 @@       Native   hs-source-dirs:       test+  default-extensions:+      OverloadedStrings+      LambdaCase+      TemplateHaskell+      RecordWildCards+      ViewPatterns+      MultiWayIf+      ApplicativeDo+      BlockArguments   ghc-options: -Wall -fno-warn-unused-do-bind -threaded   build-depends:-      base >=4.11 && <5+      base >=4.16 && <5     , criterion >=1.5.9.0 && <1.7     , pandoc >=3.1.8 && <3.7     , pandoc-crossref     , pandoc-types ==1.23.*     , text >=1.2.2 && <2.2-  default-language: Haskell2010+  default-language: GHC2021
src/ManData.hs view
@@ -18,7 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE TemplateHaskellQuotes, OverloadedStrings #-} module ManData where  import Control.DeepSeq@@ -35,7 +34,7 @@  readDataFile :: IO T.Text readDataFile =-  withFile dataFile ReadMode $ \h -> do+  withFile dataFile ReadMode \h -> do     hSetEncoding h utf8     cont <- T.replace "* TOC\n{:toc}\n" "" <$> T.hGetContents h     return $!! cont
src/pandoc-crossref.hs view
@@ -18,8 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE ApplicativeDo, TemplateHaskell, CPP, OverloadedStrings,-  LambdaCase #-}+{-# LANGUAGE CPP #-} import Text.Pandoc import Text.Pandoc.JSON @@ -65,7 +64,7 @@       <> " and GHC " <> TOOL_VERSION_ghc     go (Just NumericVersion) _ = T.putStrLn VERSION_pandoc_crossref     go (Just Man    ) _ = T.putStrLn man-    go (Just HtmlMan) _ = withSystemTempFile "pandoc-crossref-manual.html" $ \fp h -> do+    go (Just HtmlMan) _ = withSystemTempFile "pandoc-crossref-manual.html" \fp h -> do       hSetEncoding h utf8       T.hPutStrLn h manHtml       hClose h
test/Native.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE CPP, OverloadedStrings #-}+{-# LANGUAGE CPP #-} module Native where  import Text.Pandoc.Definition
test/bench-simple.hs view
@@ -1,5 +1,3 @@-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE StandaloneDeriving, GeneralizedNewtypeDeriving #-} import Criterion.Main import Text.Pandoc.CrossRef import Text.Pandoc
+ test/m2m/listOfHidden/expect.md view
@@ -0,0 +1,196 @@+# main section {#main-section .unnumbered}++blah blah blah figs. 1, S.1++![Figure 1: first figure](figs/fig1.jpg){#fig:fig1}++furthermore, etc., (figs. 2, S.2)++![Figure 2: second figure](figs/fig2.jpg){#fig:fig2}++and finally (fig. 3)++![Figure 3: third figure](figs/fig3.jpg){#fig:fig3}++# S hidden supplemental section {#hidden-supplemental-section label="S"}++:::: {#fig:fig_s1 .figure}+![Figure S.1: hidden! first supp figure](figs/fig_s1.jpg){hidden="y"}++::: {.caption short-caption=""}+Figure S.1: hidden! first supp figure+:::+::::++:::: {#fig:fig_s2 .figure}+![Figure S.2: hidden! second supp figure](figs/fig_s2.jpg){hidden="y"}++::: {.caption short-caption=""}+Figure S.2: hidden! second supp figure+:::+::::++# 2 hidden section {#hidden-section hidden="y"}++:::: {#fig:fig_h1 .figure}+![Figure 2.1: hidden! first hidden figure](figs/fig_s1.jpg)++::: {.caption short-caption=""}+Figure 2.1: hidden! first hidden figure+:::+::::++:::: {#fig:fig_h2 .figure}+![Figure 2.2: hidden! second hidden figure](figs/fig_s2.jpg)++::: {.caption short-caption=""}+Figure 2.2: hidden! second hidden figure+:::+::::++## 2.1 subsection of a hidden section++:::: {#fig:fig_h1_s .figure}+![Figure 2.1.1: hidden! first hidden subsection figure](figs/fig_s1.jpg)++::: {.caption short-caption=""}+Figure 2.1.1: hidden! first hidden subsection figure+:::+::::++:::: {#fig:fig_h2_s .figure}+![Figure 2.1.2: hidden! second hidden subsection+figure](figs/fig_s2.jpg)++::: {.caption short-caption=""}+Figure 2.1.2: hidden! second hidden subsection figure+:::+::::++# 3 regular section++![Figure 3.1: first regular section+figure](figs/fig_s1.jpg){#fig:fig_r1}++![Figure 3.2: second regular section+figure](figs/fig_s2.jpg){#fig:fig_r2}++## 3.1 normal subsection {#normal-subsection hidden="n"}++![Figure 3.1.1: first normal subsection+figure](figs/fig_s1.jpg){#fig:fig_nss1}++![Figure 3.1.2: second normal subsection+figure](figs/fig_s2.jpg){#fig:fig_nss2}++## 3.2 hidden subsection {#hidden-subsection hidden="y"}++:::: {#fig:fig_ss1 .figure}+![Figure 3.2.1: hidden! first hidden subsection figure](figs/fig_s1.jpg)++::: {.caption short-caption=""}+Figure 3.2.1: hidden! first hidden subsection figure+:::+::::++:::: {#fig:fig_ss2 .figure}+![Figure 3.2.2: hidden! second hidden subsection+figure](figs/fig_s2.jpg)++::: {.caption short-caption=""}+Figure 3.2.2: hidden! second hidden subsection figure+:::+::::++![Figure 3.2.3: visible! overridden+visibility](figs/fig_s3.jpg){#fig:fig_ss3 hidden="n"}++:::: {#fig:subfigs .figure .subfigures}+![a](figs/fig_s2.jpg){#fig:fig_sss1}+![b](figs/fig_s2.jpg){#fig:fig_sss2}++::: caption+Figure 3.2.4: hidden! subfigures. a --- hidden! subfigure1, b ---+hidden! subfigure2+:::+::::++::: {#lst:listing .listing .haskell}+Listing 3.2.1: hidden!++``` haskell+main = putStrLn "Hello, World!"+```+:::++::: {#lst:listing2 .listing .haskell}+Listing 3.2.2: visible!++``` {.haskell hidden="n"}+main = putStrLn "Hello, World!"+```+:::++::: {#tbl:table1}+  foo   bar+  ----- -----+  1     10+  2     20+  3     30++  : Table 3.2.1: hidden! table+:::++::: {#tbl:table2 hidden="n"}+  foo   bar+  ----- -----+  1     10+  2     20+  3     30++  : Table 3.2.2: visible! table+:::++# 4 one more regular section++![Figure 4.1: first other regular section+figure](figs/fig_s1.jpg){#fig:fig_or1}++![Figure 4.2: second other regular section+figure](figs/fig_s2.jpg){#fig:fig_or2}++# List of Figures++::: {.list .list-of-fig}+1\. first figure\++2\. second figure\++3\. third figure\++3.1. first regular section figure\++3.2. second regular section figure\++3.1.1. first normal subsection figure\++3.1.2. second normal subsection figure\++3.2.3. visible! overridden visibility\++4.1. first other regular section figure\++4.2. second other regular section figure\+:::++# List of Listings++::: {.list .list-of-lst}+3.2.2. visible!\+:::++# List of Tables++::: {.list .list-of-tbl}+3.2.2. visible! table\+:::
+ test/m2m/listOfHidden/expect.tex view
@@ -0,0 +1,207 @@+\section*{main section}\label{main-section}+\addcontentsline{toc}{section}{main section}++blah blah blah figs.~\ref{fig:fig1}, \ref{fig:fig_s1}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig1.jpg}}+\caption{first figure}\label{fig:fig1}+\end{figure}++furthermore, etc., (figs.~\ref{fig:fig2}, \ref{fig:fig_s2})++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig2.jpg}}+\caption{second figure}\label{fig:fig2}+\end{figure}++and finally (fig.~\ref{fig:fig3})++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig3.jpg}}+\caption{third figure}\label{fig:fig3}+\end{figure}++\section{S hidden supplemental+section}\label{hidden-supplemental-section}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s1.jpg}}+\caption[]{hidden! first supp figure}\label{fig:fig_s1}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}+\caption[]{hidden! second supp figure}\label{fig:fig_s2}+\end{figure}++\section{2 hidden section}\label{hidden-section}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s1.jpg}}+\caption[]{hidden! first hidden figure}\label{fig:fig_h1}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}+\caption[]{hidden! second hidden figure}\label{fig:fig_h2}+\end{figure}++\subsection{2.1 subsection of a hidden+section}\label{subsection-of-a-hidden-section}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s1.jpg}}+\caption[]{hidden! first hidden subsection figure}\label{fig:fig_h1_s}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}+\caption[]{hidden! second hidden subsection figure}\label{fig:fig_h2_s}+\end{figure}++\section{3 regular section}\label{regular-section}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s1.jpg}}+\caption{first regular section figure}\label{fig:fig_r1}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}+\caption{second regular section figure}\label{fig:fig_r2}+\end{figure}++\subsection{3.1 normal subsection}\label{normal-subsection}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s1.jpg}}+\caption{first normal subsection figure}\label{fig:fig_nss1}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}+\caption{second normal subsection figure}\label{fig:fig_nss2}+\end{figure}++\subsection{3.2 hidden subsection}\label{hidden-subsection}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s1.jpg}}+\caption[]{hidden! first hidden subsection figure}\label{fig:fig_ss1}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}+\caption[]{hidden! second hidden subsection figure}\label{fig:fig_ss2}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s3.jpg}}+\caption{visible! overridden visibility}\label{fig:fig_ss3}+\end{figure}++\begin{pandoccrossrefsubfigures}++\subfloat[hidden!+subfigure1]{\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}\label{fig:fig_sss1}}+\subfloat[hidden!+subfigure2]{\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}\label{fig:fig_sss2}}++\caption[]{hidden! subfigures}\label{fig:subfigs}++\end{pandoccrossrefsubfigures}++\begin{codelisting}++\caption[]{hidden!}\label{lst:listing}++\begin{Shaded}+\begin{Highlighting}[]+\NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello, World!"}+\end{Highlighting}+\end{Shaded}++\end{codelisting}++\begin{codelisting}++\caption{visible!}\label{lst:listing2}++\begin{Shaded}+\begin{Highlighting}[]+\NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello, World!"}+\end{Highlighting}+\end{Shaded}++\end{codelisting}++\begin{longtable}[]{@{}ll@{}}+\caption[]{\label{tbl:table1}hidden! table}\tabularnewline+\toprule\noalign{}+foo & bar \\+\midrule\noalign{}+\endfirsthead+\toprule\noalign{}+foo & bar \\+\midrule\noalign{}+\endhead+\bottomrule\noalign{}+\endlastfoot+1 & 10 \\+2 & 20 \\+3 & 30 \\+\end{longtable}++\begin{longtable}[]{@{}ll@{}}+\caption{\label{tbl:table2}visible! table}\tabularnewline+\toprule\noalign{}+foo & bar \\+\midrule\noalign{}+\endfirsthead+\toprule\noalign{}+foo & bar \\+\midrule\noalign{}+\endhead+\bottomrule\noalign{}+\endlastfoot+1 & 10 \\+2 & 20 \\+3 & 30 \\+\end{longtable}++\section{4 one more regular section}\label{one-more-regular-section}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s1.jpg}}+\caption{first other regular section figure}\label{fig:fig_or1}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{figs/fig_s2.jpg}}+\caption{second other regular section figure}\label{fig:fig_or2}+\end{figure}++\listoffigures++\listoflistings++\listoftables
+ test/m2m/listOfHidden/input.md view
@@ -0,0 +1,115 @@+---+chapters: true+chaptersDepth: 1000+numberSections: true+codeBlockCaptions: true+---++# main section {-}++blah blah blah [@fig:fig1; @fig:fig_s1]++![first figure](figs/fig1.jpg){#fig:fig1}++furthermore, etc., ([@fig:fig2; @fig:fig_s2])++![second figure](figs/fig2.jpg){#fig:fig2}++and finally ([@fig:fig3])++![third figure](figs/fig3.jpg){#fig:fig3}++# hidden supplemental section {label="S"}++![hidden! first supp figure](figs/fig_s1.jpg){#fig:fig_s1 hidden=y}++![hidden! second supp figure](figs/fig_s2.jpg){#fig:fig_s2 hidden=y}++# hidden section {hidden=y}++![hidden! first hidden figure](figs/fig_s1.jpg){#fig:fig_h1}++![hidden! second hidden figure](figs/fig_s2.jpg){#fig:fig_h2}++## subsection of a hidden section++![hidden! first hidden subsection figure](figs/fig_s1.jpg){#fig:fig_h1_s}++![hidden! second hidden subsection figure](figs/fig_s2.jpg){#fig:fig_h2_s}++# regular section++![first regular section figure](figs/fig_s1.jpg){#fig:fig_r1}++![second regular section figure](figs/fig_s2.jpg){#fig:fig_r2}++## normal subsection {hidden=n}++![first normal subsection figure](figs/fig_s1.jpg){#fig:fig_nss1}++![second normal subsection figure](figs/fig_s2.jpg){#fig:fig_nss2}++## hidden subsection {hidden=y}++![hidden! first hidden subsection figure](figs/fig_s1.jpg){#fig:fig_ss1}++![hidden! second hidden subsection figure](figs/fig_s2.jpg){#fig:fig_ss2}++![visible! overridden visibility](figs/fig_s3.jpg){#fig:fig_ss3 hidden=n}++:::{#fig:subfigs}+![hidden! subfigure1](figs/fig_s2.jpg){#fig:fig_sss1}+![hidden! subfigure2](figs/fig_s2.jpg){#fig:fig_sss2}++hidden! subfigures+:::++```{#lst:listing .haskell}+main = putStrLn "Hello, World!"+```+: hidden!++<!---->++```{#lst:listing2 .haskell hidden=n}+main = putStrLn "Hello, World!"+```+: visible!++<!---->++foo bar+--- ---+1   10+2   20+3   30++: hidden! table {#tbl:table1}++:::{#tbl:table2 hidden=n}+foo bar+--- ---+1   10+2   20+3   30++: visible! table+:::++# one more regular section++![first other regular section figure](figs/fig_s1.jpg){#fig:fig_or1}++![second other regular section figure](figs/fig_s2.jpg){#fig:fig_or2}++<!---->++\listoffigures++<!---->++\listoflistings++<!---->++\listoftables
+ test/m2m/listOfLinked/expect.md view
@@ -0,0 +1,114 @@+![Figure 1: 1](fig1.png){#fig:1}++![Figure 2: 2](fig2.png){#fig:2}++![Figure 3: 3](fig3.png){#fig:3}++![Figure 4: 4](fig4.png){#fig:4}++![Figure 5: 5](fig5.png){#fig:5}++![Figure 6: 6](fig6.png){#fig:6}++![Figure 7: 7](fig7.png){#fig:7}++![Figure 8: 8](fig8.png){#fig:8}++![Figure 9: 9](fig9.png){#fig:9}++::: {#lst:code1 .listing .haskell}+Listing 1: Listing caption 1++``` haskell+main :: IO ()+main = putStrLn "Hello World!"+```+:::++::: {#lst:code2 .listing .haskell}+Listing 2: Listing caption 2++``` haskell+main :: IO ()+main = putStrLn "Hello World!"+```+:::++::: {#lst:code3 .listing .haskell}+Listing 3: Listing caption 3++``` haskell+main :: IO ()+main = putStrLn "Hello World!"+```+:::++::: {#lst:code4 .listing .haskell}+Listing 4: Listing caption 4++``` haskell+main :: IO ()+main = putStrLn "Hello World!"+```+:::++------------------------------------------------------------------------++::: {#tbl:mytable}+  a   b   c+  --- --- ---+  1   2   3+  4   5   6++  : Table 1: My table+:::++::: {#tbl:1}+  a   b+  --- ---+  1   2++  : Table 2: Table+:::++# List of Figures++::: {.list .list-of-fig}+Figure 1. [1](#fig:1)++Figure 2. [2](#fig:2)++Figure 3. [3](#fig:3)++Figure 4. [4](#fig:4)++Figure 5. [5](#fig:5)++Figure 6. [6](#fig:6)++Figure 7. [7](#fig:7)++Figure 8. [8](#fig:8)++Figure 9. [9](#fig:9)+:::++# List of Tables++::: {.list .list-of-tbl}+Title 1. [My table](#tbl:mytable)++Title 2. [Table](#tbl:1)+:::++# List of Listings++::: {.list .list-of-lst}+Listing 1. [Listing caption 1](#lst:code1)++Listing 2. [Listing caption 2](#lst:code2)++Listing 3. [Listing caption 3](#lst:code3)++Listing 4. [Listing caption 4](#lst:code4)+:::
+ test/m2m/listOfLinked/expect.tex view
@@ -0,0 +1,144 @@+\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig1.png}}+\caption{1}\label{fig:1}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig2.png}}+\caption{2}\label{fig:2}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig3.png}}+\caption{3}\label{fig:3}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig4.png}}+\caption{4}\label{fig:4}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig5.png}}+\caption{5}\label{fig:5}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig6.png}}+\caption{6}\label{fig:6}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig7.png}}+\caption{7}\label{fig:7}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig8.png}}+\caption{8}\label{fig:8}+\end{figure}++\begin{figure}+\centering+\pandocbounded{\includegraphics[keepaspectratio]{fig9.png}}+\caption{9}\label{fig:9}+\end{figure}++\begin{codelisting}++\caption{Listing caption 1}\label{lst:code1}++\begin{Shaded}+\begin{Highlighting}[]+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}+\NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello World!"}+\end{Highlighting}+\end{Shaded}++\end{codelisting}++\begin{codelisting}++\caption{Listing caption 2}\label{lst:code2}++\begin{Shaded}+\begin{Highlighting}[]+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}+\NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello World!"}+\end{Highlighting}+\end{Shaded}++\end{codelisting}++\begin{codelisting}++\caption{Listing caption 3}\label{lst:code3}++\begin{Shaded}+\begin{Highlighting}[]+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}+\NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello World!"}+\end{Highlighting}+\end{Shaded}++\end{codelisting}++\begin{codelisting}++\caption{Listing caption 4}\label{lst:code4}++\begin{Shaded}+\begin{Highlighting}[]+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}+\NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello World!"}+\end{Highlighting}+\end{Shaded}++\end{codelisting}++\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}++\begin{longtable}[]{@{}lll@{}}+\caption{\label{tbl:mytable}My table}\tabularnewline+\toprule\noalign{}+a & b & c \\+\midrule\noalign{}+\endfirsthead+\toprule\noalign{}+a & b & c \\+\midrule\noalign{}+\endhead+\bottomrule\noalign{}+\endlastfoot+1 & 2 & 3 \\+4 & 5 & 6 \\+\end{longtable}++\begin{longtable}[]{@{}ll@{}}+\caption{\label{tbl:1}Table}\tabularnewline+\toprule\noalign{}+a & b \\+\midrule\noalign{}+\endfirsthead+\toprule\noalign{}+a & b \\+\midrule\noalign{}+\endhead+\bottomrule\noalign{}+\endlastfoot+1 & 2 \\+\end{longtable}++\listoffigures++\listoftables++\listoflistings
+ test/m2m/listOfLinked/input.md view
@@ -0,0 +1,71 @@+---+lofItemTemplate: "Figure $$i$$. $$lt$$"+lotItemTemplate: "Title $$i$$. $$lt$$"+lolItemTemplate: "Listing $$i$$. $$lt$$"+codeBlockCaptions: true+---++![1](fig1.png){#fig:1}++![2](fig2.png){#fig:2}++![3](fig3.png){#fig:3}++![4](fig4.png){#fig:4}++![5](fig5.png){#fig:5}++![6](fig6.png){#fig:6}++![7](fig7.png){#fig:7}++![8](fig8.png){#fig:8}++![9](fig9.png){#fig:9}++```haskell+main :: IO ()+main = putStrLn "Hello World!"+```+: Listing caption 1 {#lst:code1}++```haskell+main :: IO ()+main = putStrLn "Hello World!"+```++: Listing caption 2 {#lst:code2}++```{#lst:code3 .haskell}+main :: IO ()+main = putStrLn "Hello World!"+```+: Listing caption 3++```{#lst:code4 .haskell}+main :: IO ()+main = putStrLn "Hello World!"+```++: Listing caption 4++***++a   b   c+--- --- ---+1   2   3+4   5   6++: My table {#tbl:mytable}++| a | b |+|---|---|+| 1 | 2 |++: Table {#tbl:1}++\listoffigures++\listoftables++\listoflistings
test/m2m/listOfOrdering/expect.md view
@@ -4,7 +4,7 @@  ![Figure 1: first figure](figs/fig1.jpg){#fig:fig1} -furthermore, etc., (figs. S.2, 2)+furthermore, etc., (figs. 2, S.2)  ![Figure 2: second figure](figs/fig2.jpg){#fig:fig2} 
test/m2m/subfigures-ccsDelim/expect.tex view
@@ -14,9 +14,7 @@ \subfloat[8]{\pandocbounded{\includegraphics[keepaspectratio]{fig8.png}}} \subfloat[9]{\pandocbounded{\includegraphics[keepaspectratio]{fig9.png}}\label{fig:subfig9}} -\caption[{Caption}]{Caption}--\label{fig:subfigures}+\caption{Caption}\label{fig:subfigures}  \end{pandoccrossrefsubfigures} @@ -40,9 +38,7 @@  \subfloat[9]{\pandocbounded{\includegraphics[keepaspectratio]{fig9.png}}\label{fig:subfig29}} -\caption[{Caption}]{Caption}--\label{fig:subfigures2}+\caption{Caption}\label{fig:subfigures2}  \end{pandoccrossrefsubfigures} 
test/m2m/subfigures-grid/expect.tex view
@@ -14,9 +14,7 @@ \subfloat[8]{\includegraphics[width=0.3\linewidth,height=\textheight,keepaspectratio]{fig8.png}} \subfloat[9]{\includegraphics[width=0.3\linewidth,height=\textheight,keepaspectratio]{fig9.png}\label{fig:subfig9}} -\caption[{Caption}]{Caption}--\label{fig:subfigures}+\caption{Caption}\label{fig:subfigures}  \end{pandoccrossrefsubfigures} @@ -40,9 +38,7 @@  \subfloat[9]{\pandocbounded{\includegraphics[keepaspectratio]{fig9.png}}\label{fig:subfig29}} -\caption[{Caption}]{Caption}--\label{fig:subfigures2}+\caption{Caption}\label{fig:subfigures2}  \end{pandoccrossrefsubfigures} 
test/m2m/subfigures-one-row/expect.tex view
@@ -10,9 +10,7 @@ \subfloat[cooler caption]{\includegraphics[width=0.4\linewidth,height=\textheight,keepaspectratio]{/tmp/LaTeX_logo.svg.png}\label{fig:logo2}} -\caption[{Copies of the LaTeX logo}]{Copies of the LaTeX logo}--\label{fig:latex}+\caption{Copies of the LaTeX logo}\label{fig:latex}  \end{pandoccrossrefsubfigures} 
test/m2m/subfigures/expect.tex view
@@ -14,9 +14,7 @@ \subfloat[8]{\pandocbounded{\includegraphics[keepaspectratio]{fig8.png}}} \subfloat[9]{\pandocbounded{\includegraphics[keepaspectratio]{fig9.png}}\label{fig:subfig9}} -\caption[{Caption}]{Caption}--\label{fig:subfigures}+\caption{Caption}\label{fig:subfigures}  \end{pandoccrossrefsubfigures} @@ -40,9 +38,7 @@  \subfloat[9]{\pandocbounded{\includegraphics[keepaspectratio]{fig9.png}}\label{fig:subfig29}} -\caption[{Caption}]{Caption}--\label{fig:subfigures2}+\caption{Caption}\label{fig:subfigures2}  \end{pandoccrossrefsubfigures} 
test/test-integrative.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE CPP, OverloadedStrings #-}+{-# LANGUAGE CPP #-} import Test.Hspec import Text.Pandoc hiding (runIO) import qualified Text.Pandoc as P (runIO)
test/test-pandoc-crossref.hs view
@@ -18,8 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE FlexibleContexts, CPP, OverloadedStrings, RankNTypes-  , ScopedTypeVariables, OverloadedLists #-}+{-# LANGUAGE CPP, OverloadedLists #-} import Test.Hspec import Text.Pandoc hiding (getDataFileName) import Text.Pandoc.Builder hiding (figure)@@ -120,31 +119,43 @@                                             refIndex = [(1,Nothing)],                                             refGlobal = 1,                                             refTitle = [Str "Test",Space,Str "figure",Space,Str "1"],+                                            refHideFromList = False,+                                            refLabel = Just "fig:figure1",                                             refSubfigure = Just [(1, Just "a")]}),                                     ("fig:figure2",RefRec {                                             refIndex = [(1,Nothing)],                                             refGlobal = 2,                                             refTitle = [Str "Test",Space,Str "figure",Space,Str "2"],+                                            refHideFromList = False,+                                            refLabel = Just "fig:figure2",                                             refSubfigure = Just [(2, Just "b")]}),                                     ("fig:subfigure",RefRec {                                             refIndex = [(1,Nothing)],                                             refGlobal = 0,                                             refTitle = [Str "figure",Space,Str "caption"],+                                            refHideFromList = False,+                                            refLabel = Just "fig:subfigure",                                             refSubfigure = Nothing}),                                     ("fig:figure21",RefRec {                                             refIndex = [(2,Nothing)],                                             refGlobal = 4,                                             refTitle = [Str "Test",Space,Str "figure",Space,Str "21"],+                                            refHideFromList = False,+                                            refLabel = Just "fig:figure21",                                             refSubfigure = Just [(1, Just "a")]}),                                     ("fig:figure22",RefRec {                                             refIndex = [(2,Nothing)],                                             refGlobal = 5,                                             refTitle = [Str "Test",Space,Str "figure",Space,Str "22"],+                                            refHideFromList = False,+                                            refLabel = Just "fig:figure22",                                             refSubfigure = Just [(2, Just "b")]}),                                     ("fig:subfigure2",RefRec {                                             refIndex = [(2,Nothing)],                                             refGlobal = 3,                                             refTitle = [Str "figure",Space,Str "caption",Space,Str "2"],+                                            refHideFromList = False,+                                            refLabel = Just "fig:subfigure2",                                             refSubfigure = Nothing})                                    ]             )@@ -362,13 +373,13 @@ refGen' p l1 l2 = M.fromList $ mconcat $ zipWith refRec''' (((uncapitalizeFirst p<>) . T.pack . show) `map` l1) l2  refRec' :: T.Text -> Int -> T.Text -> [(T.Text, RefRec)]-refRec' ref i tit = [(ref, RefRec{refIndex=[(i,Nothing)],refGlobal=0,refTitle=toList $ text tit,refSubfigure=Nothing})]+refRec' ref i tit = [(ref, RefRec{refLabel=Just ref,refIndex=[(i,Nothing)],refGlobal=0,refHideFromList=False,refTitle=toList $ text tit,refSubfigure=Nothing})]  refRec'' :: T.Text -> Int -> [(T.Text, RefRec)] refRec'' ref i = refRec' ref i ""  refRec''' :: T.Text -> (Int, Int) -> [(T.Text, RefRec)]-refRec''' ref (c,i) = [(ref, RefRec{refIndex=[(c,Nothing), (i,Nothing)],refGlobal=0,refTitle=toList $ text "",refSubfigure=Nothing})]+refRec''' ref (c,i) = [(ref, RefRec{refLabel=Just ref,refIndex=[(c,Nothing), (i,Nothing)],refGlobal=0,refHideFromList=False,refTitle=toList $ text "",refSubfigure=Nothing})]  testRefs' :: T.Text -> [Int] -> [Int] -> Prefix -> T.Text -> Expectation testRefs' p l1 l2 prop res = testRefs (para $ citeGen p l1) (set (refsAt prop) (refGen p l1 l2) def) (para $ text res)@@ -469,3 +480,7 @@   & ctrsAt a .~ (refIndex $ last $ M.elems b)   & refsAt a .~ b   & stGlob %~ (+ fromIntegral (M.size b))+  & stHiddenHeaderLevel .~+    if a == PfxSec+    then [HiddenHeader { hhLevel = 1, hhHidden = False }]+    else []