pandoc-crossref 0.3.4.2 → 0.3.5.0
raw patch · 24 files changed
+319/−251 lines, 24 filesdep ~pandocdep ~pandoc-typesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: pandoc, pandoc-types
API changes (from Hackage documentation)
- Text.Pandoc.CrossRef: autoEqnLabels :: forall a_azJO. ToMetaValue a_azJO => a_azJO -> Meta
+ Text.Pandoc.CrossRef: autoEqnLabels :: forall a_aAqt. ToMetaValue a_aAqt => a_aAqt -> Meta
- Text.Pandoc.CrossRef: autoSectionLabels :: forall a_azJf. ToMetaValue a_azJf => a_azJf -> Meta
+ Text.Pandoc.CrossRef: autoSectionLabels :: forall a_aApU. ToMetaValue a_aApU => a_aApU -> Meta
- Text.Pandoc.CrossRef: ccsDelim :: forall a_azJL. ToMetaValue a_azJL => a_azJL -> Meta
+ Text.Pandoc.CrossRef: ccsDelim :: forall a_aAqq. ToMetaValue a_aAqq => a_aAqq -> Meta
- Text.Pandoc.CrossRef: ccsLabelSep :: forall a_azJM. ToMetaValue a_azJM => a_azJM -> Meta
+ Text.Pandoc.CrossRef: ccsLabelSep :: forall a_aAqr. ToMetaValue a_aAqr => a_aAqr -> Meta
- Text.Pandoc.CrossRef: ccsTemplate :: forall a_azJH. ToMetaValue a_azJH => a_azJH -> Meta
+ Text.Pandoc.CrossRef: ccsTemplate :: forall a_aAqm. ToMetaValue a_aAqm => a_aAqm -> Meta
- Text.Pandoc.CrossRef: chapDelim :: forall a_azJv. ToMetaValue a_azJv => a_azJv -> Meta
+ Text.Pandoc.CrossRef: chapDelim :: forall a_aAqa. ToMetaValue a_aAqa => a_aAqa -> Meta
- Text.Pandoc.CrossRef: chapters :: forall a_aA8s. ToMetaValue a_aA8s => a_aA8s -> Meta
+ Text.Pandoc.CrossRef: chapters :: forall a_aAQZ. ToMetaValue a_aAQZ => a_aAQZ -> Meta
- Text.Pandoc.CrossRef: chaptersDepth :: forall a_azJc. ToMetaValue a_azJc => a_azJc -> Meta
+ Text.Pandoc.CrossRef: chaptersDepth :: forall a_aApR. ToMetaValue a_aApR => a_aApR -> Meta
- Text.Pandoc.CrossRef: codeBlockCaptions :: forall a_azJe. ToMetaValue a_azJe => a_azJe -> Meta
+ Text.Pandoc.CrossRef: codeBlockCaptions :: forall a_aApT. ToMetaValue a_aApT => a_aApT -> Meta
- Text.Pandoc.CrossRef: cref :: forall a_azJb. ToMetaValue a_azJb => a_azJb -> Meta
+ Text.Pandoc.CrossRef: cref :: forall a_aApQ. ToMetaValue a_aApQ => a_aApQ -> Meta
- Text.Pandoc.CrossRef: crossrefYaml :: forall a_aA8q. ToMetaValue a_aA8q => a_aA8q -> Meta
+ Text.Pandoc.CrossRef: crossrefYaml :: forall a_aAQX. ToMetaValue a_aAQX => a_aAQX -> Meta
- Text.Pandoc.CrossRef: customLabel :: forall a_azJK. ToMetaValue a_azJK => a_azJK -> Meta
+ Text.Pandoc.CrossRef: customLabel :: forall a_aAqp. ToMetaValue a_aAqp => a_aAqp -> Meta
- Text.Pandoc.CrossRef: eqLabels :: forall a_aA8u. ToMetaValue a_aA8u => a_aA8u -> Meta
+ Text.Pandoc.CrossRef: eqLabels :: forall a_aAR1. ToMetaValue a_aAR1 => a_aAR1 -> Meta
- Text.Pandoc.CrossRef: eqnPrefix :: forall a_azJj. ToMetaValue a_azJj => a_azJj -> Meta
+ Text.Pandoc.CrossRef: eqnPrefix :: forall a_aApY. ToMetaValue a_aApY => a_aApY -> Meta
- Text.Pandoc.CrossRef: eqnPrefixTemplate :: forall a_azJo. ToMetaValue a_azJo => a_azJo -> Meta
+ Text.Pandoc.CrossRef: eqnPrefixTemplate :: forall a_aAq3. ToMetaValue a_aAq3 => a_aAq3 -> Meta
- Text.Pandoc.CrossRef: figLabels :: forall a_aA8t. ToMetaValue a_aA8t => a_aA8t -> Meta
+ Text.Pandoc.CrossRef: figLabels :: forall a_aAR0. ToMetaValue a_aAR0 => a_aAR0 -> Meta
- Text.Pandoc.CrossRef: figPrefix :: forall a_azJi. ToMetaValue a_azJi => a_azJi -> Meta
+ Text.Pandoc.CrossRef: figPrefix :: forall a_aApX. ToMetaValue a_aApX => a_aApX -> Meta
- Text.Pandoc.CrossRef: figPrefixTemplate :: forall a_azJn. ToMetaValue a_azJn => a_azJn -> Meta
+ Text.Pandoc.CrossRef: figPrefixTemplate :: forall a_aAq2. ToMetaValue a_aAq2 => a_aAq2 -> Meta
- Text.Pandoc.CrossRef: figureTemplate :: forall a_azJE. ToMetaValue a_azJE => a_azJE -> Meta
+ Text.Pandoc.CrossRef: figureTemplate :: forall a_aAqj. ToMetaValue a_aAqj => a_aAqj -> Meta
- Text.Pandoc.CrossRef: figureTitle :: forall a_aA8m. ToMetaValue a_aA8m => a_aA8m -> Meta
+ Text.Pandoc.CrossRef: figureTitle :: forall a_aAQT. ToMetaValue a_aAQT => a_aAQT -> Meta
- Text.Pandoc.CrossRef: lastDelim :: forall a_azJy. ToMetaValue a_azJy => a_azJy -> Meta
+ Text.Pandoc.CrossRef: lastDelim :: forall a_aAqd. ToMetaValue a_aAqd => a_aAqd -> Meta
- Text.Pandoc.CrossRef: linkReferences :: forall a_azJQ. ToMetaValue a_azJQ => a_azJQ -> Meta
+ Text.Pandoc.CrossRef: linkReferences :: forall a_aAqv. ToMetaValue a_aAqv => a_aAqv -> Meta
- Text.Pandoc.CrossRef: listingTemplate :: forall a_azJJ. ToMetaValue a_azJJ => a_azJJ -> Meta
+ Text.Pandoc.CrossRef: listingTemplate :: forall a_aAqo. ToMetaValue a_aAqo => a_aAqo -> Meta
- Text.Pandoc.CrossRef: listingTitle :: forall a_aA8o. ToMetaValue a_aA8o => a_aA8o -> Meta
+ Text.Pandoc.CrossRef: listingTitle :: forall a_aAQV. ToMetaValue a_aAQV => a_aAQV -> Meta
- Text.Pandoc.CrossRef: listings :: forall a_azJd. ToMetaValue a_azJd => a_azJd -> Meta
+ Text.Pandoc.CrossRef: listings :: forall a_aApS. ToMetaValue a_aApS => a_aApS -> Meta
- Text.Pandoc.CrossRef: lofTitle :: forall a_azJA. ToMetaValue a_azJA => a_azJA -> Meta
+ Text.Pandoc.CrossRef: lofTitle :: forall a_aAqf. ToMetaValue a_aAqf => a_aAqf -> Meta
- Text.Pandoc.CrossRef: lolTitle :: forall a_azJC. ToMetaValue a_azJC => a_azJC -> Meta
+ Text.Pandoc.CrossRef: lolTitle :: forall a_aAqh. ToMetaValue a_aAqh => a_aAqh -> Meta
- Text.Pandoc.CrossRef: lotTitle :: forall a_azJB. ToMetaValue a_azJB => a_azJB -> Meta
+ Text.Pandoc.CrossRef: lotTitle :: forall a_aAqg. ToMetaValue a_aAqg => a_aAqg -> Meta
- Text.Pandoc.CrossRef: lstLabels :: forall a_aA8w. ToMetaValue a_aA8w => a_aA8w -> Meta
+ Text.Pandoc.CrossRef: lstLabels :: forall a_aAR3. ToMetaValue a_aAR3 => a_aAR3 -> Meta
- Text.Pandoc.CrossRef: lstPrefix :: forall a_azJl. ToMetaValue a_azJl => a_azJl -> Meta
+ Text.Pandoc.CrossRef: lstPrefix :: forall a_aAq0. ToMetaValue a_aAq0 => a_aAq0 -> Meta
- Text.Pandoc.CrossRef: lstPrefixTemplate :: forall a_azJq. ToMetaValue a_azJq => a_azJq -> Meta
+ Text.Pandoc.CrossRef: lstPrefixTemplate :: forall a_aAq5. ToMetaValue a_aAq5 => a_aAq5 -> Meta
- Text.Pandoc.CrossRef: nameInLink :: forall a_azJR. ToMetaValue a_azJR => a_azJR -> Meta
+ Text.Pandoc.CrossRef: nameInLink :: forall a_aAqw. ToMetaValue a_aAqw => a_aAqw -> Meta
- Text.Pandoc.CrossRef: numberSections :: forall a_azJg. ToMetaValue a_azJg => a_azJg -> Meta
+ Text.Pandoc.CrossRef: numberSections :: forall a_aApV. ToMetaValue a_aApV => a_aApV -> Meta
- Text.Pandoc.CrossRef: outFormat :: forall a_azJD. ToMetaValue a_azJD => a_azJD -> Meta
+ Text.Pandoc.CrossRef: outFormat :: forall a_aAqi. ToMetaValue a_aAqi => a_aAqi -> Meta
- Text.Pandoc.CrossRef: pairDelim :: forall a_azJx. ToMetaValue a_azJx => a_azJx -> Meta
+ Text.Pandoc.CrossRef: pairDelim :: forall a_aAqc. ToMetaValue a_aAqc => a_aAqc -> Meta
- Text.Pandoc.CrossRef: rangeDelim :: forall a_azJw. ToMetaValue a_azJw => a_azJw -> Meta
+ Text.Pandoc.CrossRef: rangeDelim :: forall a_aAqb. ToMetaValue a_aAqb => a_aAqb -> Meta
- Text.Pandoc.CrossRef: refDelim :: forall a_azJz. ToMetaValue a_azJz => a_azJz -> Meta
+ Text.Pandoc.CrossRef: refDelim :: forall a_aAqe. ToMetaValue a_aAqe => a_aAqe -> Meta
- Text.Pandoc.CrossRef: refIndexTemplate :: forall a_azJs. ToMetaValue a_azJs => a_azJs -> Meta
+ Text.Pandoc.CrossRef: refIndexTemplate :: forall a_aAq7. ToMetaValue a_aAq7 => a_aAq7 -> Meta
- Text.Pandoc.CrossRef: secHeaderDelim :: forall a_aA8y. ToMetaValue a_aA8y => a_aA8y -> Meta
+ Text.Pandoc.CrossRef: secHeaderDelim :: forall a_aAR5. ToMetaValue a_aAR5 => a_aAR5 -> Meta
- Text.Pandoc.CrossRef: secHeaderTemplate :: forall a_azJu. ToMetaValue a_azJu => a_azJu -> Meta
+ Text.Pandoc.CrossRef: secHeaderTemplate :: forall a_aAq9. ToMetaValue a_aAq9 => a_aAq9 -> Meta
- Text.Pandoc.CrossRef: secLabels :: forall a_aA8x. ToMetaValue a_aA8x => a_aA8x -> Meta
+ Text.Pandoc.CrossRef: secLabels :: forall a_aAR4. ToMetaValue a_aAR4 => a_aAR4 -> Meta
- Text.Pandoc.CrossRef: secPrefix :: forall a_azJm. ToMetaValue a_azJm => a_azJm -> Meta
+ Text.Pandoc.CrossRef: secPrefix :: forall a_aAq1. ToMetaValue a_aAq1 => a_aAq1 -> Meta
- Text.Pandoc.CrossRef: secPrefixTemplate :: forall a_azJr. ToMetaValue a_azJr => a_azJr -> Meta
+ Text.Pandoc.CrossRef: secPrefixTemplate :: forall a_aAq6. ToMetaValue a_aAq6 => a_aAq6 -> Meta
- Text.Pandoc.CrossRef: sectionsDepth :: forall a_azJh. ToMetaValue a_azJh => a_azJh -> Meta
+ Text.Pandoc.CrossRef: sectionsDepth :: forall a_aApW. ToMetaValue a_aApW => a_aApW -> Meta
- Text.Pandoc.CrossRef: subfigGrid :: forall a_azJP. ToMetaValue a_azJP => a_azJP -> Meta
+ Text.Pandoc.CrossRef: subfigGrid :: forall a_aAqu. ToMetaValue a_aAqu => a_aAqu -> Meta
- Text.Pandoc.CrossRef: subfigLabels :: forall a_aA8r. ToMetaValue a_aA8r => a_aA8r -> Meta
+ Text.Pandoc.CrossRef: subfigLabels :: forall a_aAQY. ToMetaValue a_aAQY => a_aAQY -> Meta
- Text.Pandoc.CrossRef: subfigureChildTemplate :: forall a_azJG. ToMetaValue a_azJG => a_azJG -> Meta
+ Text.Pandoc.CrossRef: subfigureChildTemplate :: forall a_aAql. ToMetaValue a_aAql => a_aAql -> Meta
- Text.Pandoc.CrossRef: subfigureRefIndexTemplate :: forall a_azJt. ToMetaValue a_azJt => a_azJt -> Meta
+ Text.Pandoc.CrossRef: subfigureRefIndexTemplate :: forall a_aAq8. ToMetaValue a_aAq8 => a_aAq8 -> Meta
- Text.Pandoc.CrossRef: subfigureTemplate :: forall a_azJF. ToMetaValue a_azJF => a_azJF -> Meta
+ Text.Pandoc.CrossRef: subfigureTemplate :: forall a_aAqk. ToMetaValue a_aAqk => a_aAqk -> Meta
- Text.Pandoc.CrossRef: tableEqns :: forall a_azJN. ToMetaValue a_azJN => a_azJN -> Meta
+ Text.Pandoc.CrossRef: tableEqns :: forall a_aAqs. ToMetaValue a_aAqs => a_aAqs -> Meta
- Text.Pandoc.CrossRef: tableTemplate :: forall a_azJI. ToMetaValue a_azJI => a_azJI -> Meta
+ Text.Pandoc.CrossRef: tableTemplate :: forall a_aAqn. ToMetaValue a_aAqn => a_aAqn -> Meta
- Text.Pandoc.CrossRef: tableTitle :: forall a_aA8n. ToMetaValue a_aA8n => a_aA8n -> Meta
+ Text.Pandoc.CrossRef: tableTitle :: forall a_aAQU. ToMetaValue a_aAQU => a_aAQU -> Meta
- Text.Pandoc.CrossRef: tblLabels :: forall a_aA8v. ToMetaValue a_aA8v => a_aA8v -> Meta
+ Text.Pandoc.CrossRef: tblLabels :: forall a_aAR2. ToMetaValue a_aAR2 => a_aAR2 -> Meta
- Text.Pandoc.CrossRef: tblPrefix :: forall a_azJk. ToMetaValue a_azJk => a_azJk -> Meta
+ Text.Pandoc.CrossRef: tblPrefix :: forall a_aApZ. ToMetaValue a_aApZ => a_aApZ -> Meta
- Text.Pandoc.CrossRef: tblPrefixTemplate :: forall a_azJp. ToMetaValue a_azJp => a_azJp -> Meta
+ Text.Pandoc.CrossRef: tblPrefixTemplate :: forall a_aAq4. ToMetaValue a_aAq4 => a_aAq4 -> Meta
- Text.Pandoc.CrossRef: titleDelim :: forall a_aA8p. ToMetaValue a_aA8p => a_aA8p -> Meta
+ Text.Pandoc.CrossRef: titleDelim :: forall a_aAQW. ToMetaValue a_aAQW => a_aAQW -> Meta
Files
- CHANGELOG.md +19/−0
- lib/Text/Pandoc/CrossRef.hs +1/−1
- lib/Text/Pandoc/CrossRef/References/Blocks.hs +54/−51
- lib/Text/Pandoc/CrossRef/References/List.hs +3/−1
- lib/Text/Pandoc/CrossRef/References/Refs.hs +27/−25
- lib/Text/Pandoc/CrossRef/References/Types.hs +3/−2
- lib/Text/Pandoc/CrossRef/Util/CodeBlockCaptions.hs +7/−5
- lib/Text/Pandoc/CrossRef/Util/CustomLabels.hs +9/−8
- lib/Text/Pandoc/CrossRef/Util/Meta.hs +17/−13
- lib/Text/Pandoc/CrossRef/Util/ModifyMeta.hs +18/−18
- lib/Text/Pandoc/CrossRef/Util/Options.hs +2/−1
- lib/Text/Pandoc/CrossRef/Util/Settings.hs +4/−3
- lib/Text/Pandoc/CrossRef/Util/Settings/Gen.hs +1/−1
- lib/Text/Pandoc/CrossRef/Util/Settings/Template.hs +4/−2
- lib/Text/Pandoc/CrossRef/Util/Template.hs +10/−7
- lib/Text/Pandoc/CrossRef/Util/Util.hs +29/−25
- pandoc-crossref.cabal +10/−10
- src/ManData.hs +6/−3
- src/pandoc-crossref.hs +27/−6
- test/Native.hs +1/−1
- test/m2m/listing-captions-ids/expect.tex +1/−2
- test/m2m/subfigures-grid/expect.md +6/−6
- test/test-integrative.hs +1/−1
- test/test-pandoc-crossref.hs +59/−59
CHANGELOG.md view
@@ -1,3 +1,22 @@+## 0.3.5.0++- Updates for pandoc 2.8++- Pandoc < 2.8 no longer supported++- Check pandoc version when running through pandoc and issue a warning+ when it doesn't match the one pandoc-crossref was built with.++- Running pandoc-crossref as a UNIX pipe implicitly, i.e.+ `pandoc -t json text.md | pandoc-crossref | pandoc -f json`+ is no longer supported. Use the `--pipe` (short `-p` is also supported) option, e.g.+ `pandoc -t json text.md | pandoc-crossref --pipe | pandoc -f json`++- Running pandoc-crossref as a UNIX pipe with specified output format, i.e.+ `pandoc -t json text.md | pandoc-crossref html | pandoc -f json`+ is deprecated. Please use the `--pipe` (short `-p` is also supported) option, e.g.+ `pandoc -t json text.md | pandoc-crossref --pipe html | pandoc -f json`+ ## 0.3.4.2 - Fix eqLabels in documentation and default meta
lib/Text/Pandoc/CrossRef.hs view
@@ -142,7 +142,7 @@ runCrossRef :: forall a b. Meta -> Maybe Format -> (a -> CrossRefM b) -> a -> b runCrossRef meta fmt action arg = R.runReader (action arg) env where- settings = meta <> defaultMeta+ settings = defaultMeta <> meta env = CrossRefEnv { creSettings = settings , creOptions = getOptions settings fmt
lib/Text/Pandoc/CrossRef/References/Blocks.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE Rank2Types, MultiWayIf #-}+{-# LANGUAGE Rank2Types, MultiWayIf, OverloadedStrings #-} module Text.Pandoc.CrossRef.References.Blocks ( replaceAll ) where@@ -31,6 +31,8 @@ import Data.Maybe import Data.Monoid import qualified Data.Map as M+import qualified Data.Text as T+import qualified Data.Text.Read as T import Data.Accessor import Data.Accessor.Monad.Trans.State@@ -56,19 +58,19 @@ replaceBlock :: Options -> Block -> WS (ReplacedResult Block) replaceBlock opts (Header n (label, cls, attrs) text') = do- let label' = if autoSectionLabels opts && not ("sec:" `isPrefixOf` label)- then "sec:"++label+ let label' = if autoSectionLabels opts && not ("sec:" `T.isPrefixOf` label)+ then "sec:"<>label else label unless ("unnumbered" `elem` cls) $ do modify curChap $ \cc -> let ln = length cc cl = lookup "label" attrs- inc l = init l ++ [(fst (last l) + 1, cl)]+ inc l = init l <> [(fst (last l) + 1, cl)] cc' | ln > n = inc $ take n cc | ln == n = inc cc- | otherwise = cc ++ take (n-ln-1) (zip [1,1..] $ repeat Nothing) ++ [(1,cl)]+ | otherwise = cc <> take (n-ln-1) (zip [1,1..] $ repeat Nothing) <> [(1,cl)] in cc'- when ("sec:" `isPrefixOf` label') $ do+ when ("sec:" `T.isPrefixOf` label') $ do index <- get curChap modify secRefs $ M.insert label' RefRec { refIndex=index@@ -81,17 +83,17 @@ || n <= if sectionsDepth opts == 0 then chaptersDepth opts else sectionsDepth opts , "unnumbered" `notElem` cls = applyTemplate' (M.fromDistinctAscList [- ("i", [Str (intercalate "." $ map show' cc)])- , ("n", [Str $ show $ n - 1])+ ("i", [Str (T.intercalate "." $ map show' cc)])+ , ("n", [Str $ T.pack $ show $ n - 1]) , ("t", text') ]) $ secHeaderTemplate opts | otherwise = text' show' (_, Just s) = s- show' (i, Nothing) = show i+ show' (i, Nothing) = T.pack $ show i replaceNoRecurse $ Header n (label', cls, attrs) textCC -- subfigures replaceBlock opts (Div (label,cls,attrs) images)- | "fig:" `isPrefixOf` label+ | "fig:" `T.isPrefixOf` label , Para caption <- last images = do idxStr <- replaceAttr opts (Right label) (lookup "label" attrs) caption imgRefs@@ -124,7 +126,7 @@ f | isLatexFormat f -> replaceNoRecurse $ Div nullAttr $ [ RawBlock (Format "latex") "\\begin{figure}\n\\centering" ]- ++ cont +++ <> cont <> [ Para [RawInline (Format "latex") "\\caption" , Span nullAttr caption] , RawBlock (Format "latex") $ mkLaTeXLabel label@@ -133,12 +135,12 @@ where opts' = opts { figureTemplate = subfigureChildTemplate opts- , customLabel = \r i -> customLabel opts ("sub"++r) i+ , customLabel = \r i -> customLabel opts ("sub"<>r) i } toTable :: [Block] -> [Inline] -> [Block] toTable blks capt | subfigGrid opts = [Table [] align widths [] $ map blkToRow blks, mkCaption opts "Image Caption" capt]- | otherwise = blks ++ [mkCaption opts "Image Caption" capt]+ | otherwise = blks <> [mkCaption opts "Image Caption" capt] where align | Para ils:_ <- blks = replicate (length $ mapMaybe getWidth ils) AlignCenter | otherwise = error "Misformatted subfigures block"@@ -155,10 +157,9 @@ in if nz>0 then map (\x -> if x == 0 then rzw else x) ws else ws- percToDouble :: String -> Double+ percToDouble :: T.Text -> Double percToDouble percs- | '%' <- last percs- , perc <- read $ init percs+ | Right (perc, "%") <- T.double percs = perc/100.0 | otherwise = error "Only percent allowed in subfigure width!" blkToRow :: Block -> [[Block]]@@ -170,7 +171,7 @@ setW as = ("width", "100%"):filter ((/="width") . fst) as replaceBlock opts (Div divOps@(label,_,attrs) [Table title align widths header cells]) | not $ null title- , "tbl:" `isPrefixOf` label+ , "tbl:" `T.isPrefixOf` label = do idxStr <- replaceAttr opts (Right label) (lookup "label" attrs) title tblRefs let title' =@@ -180,8 +181,8 @@ _ -> applyTemplate idxStr title $ tableTemplate opts replaceNoRecurse $ Div divOps [Table title' align widths header cells] replaceBlock opts cb@(CodeBlock (label, classes, attrs) code)- | not $ null label- , "lst:" `isPrefixOf` label+ | not $ T.null label+ , "lst:" `T.isPrefixOf` label , Just caption <- lookup "caption" attrs = case outFormat opts of f@@ -205,13 +206,13 @@ let caption' = applyTemplate idxStr cap $ listingTemplate opts replaceNoRecurse $ Div (label, "listing":classes, []) [ mkCaption opts "Caption" caption'- , CodeBlock ([], classes, attrs \\ [("caption", caption)]) code+ , CodeBlock ("", classes, attrs \\ [("caption", caption)]) code ] replaceBlock opts (Div (label,"listing":_, [])- [Para caption, CodeBlock ([],classes,attrs) code])- | not $ null label- , "lst:" `isPrefixOf` label+ [Para caption, CodeBlock ("",classes,attrs) code])+ | not $ T.null label+ , "lst:" `T.isPrefixOf` label = case outFormat opts of f --if used with listings package, return code block with caption@@ -233,37 +234,38 @@ let caption' = applyTemplate idxStr caption $ listingTemplate opts replaceNoRecurse $ Div (label, "listing":classes, []) [ mkCaption opts "Caption" caption'- , CodeBlock ([], classes, attrs) code+ , CodeBlock ("", classes, attrs) code ] replaceBlock opts (Para [Span attrs [Math DisplayMath eq]]) | not $ isLatexFormat (outFormat opts) , tableEqns opts = do (eq', idx) <- replaceEqn opts attrs eq- replaceNoRecurse $ Div attrs [Table [] [AlignCenter, AlignRight] [0.9, 0.09] [] [[[Plain [Math DisplayMath eq']], [Plain [Math DisplayMath $ "(" ++ idx ++ ")"]]]]]+ replaceNoRecurse $ Div attrs [Table [] [AlignCenter, AlignRight] [0.9, 0.09] [] [[[Plain [Math DisplayMath eq']], [Plain [Math DisplayMath $ "(" <> idx <> ")"]]]]] replaceBlock _ _ = noReplaceRecurse -replaceEqn :: Options -> Attr -> String -> WS (String, String)+replaceEqn :: Options -> Attr -> T.Text -> WS (T.Text, T.Text) replaceEqn opts (label, _, attrs) eq = do- let label' | null label = Left "eq"+ let label' | T.null label = Left "eq" | otherwise = Right label idxStr <- replaceAttr opts label' (lookup "label" attrs) [] eqnRefs let eq' | tableEqns opts = eq- | otherwise = eq++"\\qquad("++stringify idxStr++")"- return (eq', stringify idxStr)+ | otherwise = eq<>"\\qquad("<>idxTxt<>")"+ idxTxt = stringify idxStr+ return (eq', idxTxt) replaceInline :: Options -> Inline -> WS (ReplacedResult Inline) replaceInline opts (Span attrs@(label,_,_) [Math DisplayMath eq])- | "eq:" `isPrefixOf` label || null label && autoEqnLabels opts+ | "eq:" `T.isPrefixOf` label || T.null label && autoEqnLabels opts = case outFormat opts of f | isLatexFormat f ->- let eqn = "\\begin{equation}"++eq++mkLaTeXLabel label++"\\end{equation}"+ let eqn = "\\begin{equation}"<>eq<>mkLaTeXLabel label<>"\\end{equation}" in replaceNoRecurse $ RawInline (Format "latex") eqn _ -> do (eq', _) <- replaceEqn opts attrs eq replaceNoRecurse $ Span attrs [Math DisplayMath eq'] replaceInline opts (Image attr@(label,_,attrs) alt img@(_, tit))- | "fig:" `isPrefixOf` label && "fig:" `isPrefixOf` tit+ | "fig:" `T.isPrefixOf` label && "fig:" `T.isPrefixOf` tit = do idxStr <- replaceAttr opts (Right label) (lookup "label" attrs) alt imgRefs let alt' = case outFormat opts of@@ -278,18 +280,18 @@ replaceSubfig :: Options -> Inline -> WS [Inline] replaceSubfig opts x@(Image (label,cls,attrs) alt (src, tit)) = do- let label' | "fig:" `isPrefixOf` label = Right label- | null label = Left "fig"- | otherwise = Right $ "fig:" ++ label+ let label' | "fig:" `T.isPrefixOf` label = Right label+ | T.null label = Left "fig"+ | otherwise = Right $ "fig:" <> label idxStr <- replaceAttr opts label' (lookup "label" attrs) alt imgRefs case outFormat opts of f | isLatexFormat f -> return $ latexSubFigure x label _ -> let alt' = applyTemplate idxStr alt $ figureTemplate opts- tit' | "nocaption" `elem` cls = fromMaybe tit $ stripPrefix "fig:" tit- | "fig:" `isPrefixOf` tit = tit- | otherwise = "fig:" ++ tit+ tit' | "nocaption" `elem` cls = fromMaybe tit $ T.stripPrefix "fig:" tit+ | "fig:" `T.isPrefixOf` tit = tit+ | otherwise = "fig:" <> tit in return [Image (label, cls, attrs) alt' (src, tit')] replaceSubfig _ x = return [x] @@ -302,7 +304,7 @@ splitMath :: [Block] -> [Block] splitMath (Para ils:xs)- | length ils > 1 = map Para (split [] [] ils) ++ xs+ | length ils > 1 = map Para (split [] [] ils) <> xs where split res acc [] = reverse (reverse acc : res) split res acc (x@(Span _ [Math DisplayMath _]):ys) =@@ -321,16 +323,17 @@ = Span nullAttr [math]:ils spanInlines _ x = x -replaceAttr :: Options -> Either String String -> Maybe String -> [Inline] -> Accessor References RefMap -> WS [Inline]+replaceAttr :: Options -> Either T.Text T.Text -> Maybe T.Text -> [Inline] -> Accessor References RefMap -> WS [Inline] replaceAttr o label refLabel title prop = do chap <- take (chaptersDepth o) `fmap` get curChap- i <- (1+) `fmap` (M.size . M.filter (\x -> (chap == init (refIndex x)) && isNothing (refSubfigure x)) <$> get prop)- let index = chap ++ [(i, refLabel <> customLabel o label' i)]- label' = either (++ ':':show index) id label- hasLabel <- M.member label' <$> get prop- when hasLabel $- error $ "Duplicate label: " ++ label'+ prop' <- get prop+ let i = 1+ (M.size . M.filter (\x -> (chap == init (refIndex x)) && isNothing (refSubfigure x)) $ prop')+ index = chap <> [(i, refLabel <> customLabel o ref i)]+ ref = either id (T.takeWhile (/=':')) label+ label' = either (<> T.pack (':' : show index)) id label+ when (M.member label' prop') $+ error . T.unpack $ "Duplicate label: " <> label' modify prop $ M.insert label' RefRec { refIndex= index , refTitle= title@@ -338,11 +341,11 @@ } return $ chapPrefix (chapDelim o) index -latexSubFigure :: Inline -> String -> [Inline]+latexSubFigure :: Inline -> T.Text -> [Inline] latexSubFigure (Image (_, cls, attrs) alt (src, title)) label = let- title' = fromMaybe title $ stripPrefix "fig:" title- texlabel | null label = []+ title' = fromMaybe title $ T.stripPrefix "fig:" title+ texlabel | T.null label = [] | otherwise = [RawInline (Format "latex") $ mkLaTeXLabel label] texalt | "nocaption" `elem` cls = [] | otherwise = concat@@ -358,7 +361,7 @@ ] latexSubFigure x _ = [x] -mkCaption :: Options -> String -> [Inline] -> Block+mkCaption :: Options -> T.Text -> [Inline] -> Block mkCaption opts style- | outFormat opts == Just (Format "docx") = Div ([], [], [("custom-style", style)]) . return . Para+ | outFormat opts == Just (Format "docx") = Div ("", [], [("custom-style", style)]) . return . Para | otherwise = Para
lib/Text/Pandoc/CrossRef/References/List.hs view
@@ -18,6 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} +{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.References.List (listOf) where import Text.Pandoc.Definition@@ -25,6 +26,7 @@ import Control.Arrow import Data.List import qualified Data.Map as M+import qualified Data.Text as T import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.Util.Util@@ -43,7 +45,7 @@ = get lstRefs >>= makeList opts lolTitle xs listOf _ x = return x -makeList :: Options -> (Options -> [Block]) -> [Block] -> M.Map String RefRec -> WS [Block]+makeList :: Options -> (Options -> [Block]) -> [Block] -> M.Map T.Text RefRec -> WS [Block] makeList opts titlef xs refs = return $ titlef opts ++
lib/Text/Pandoc/CrossRef/References/Refs.hs view
@@ -18,6 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} +{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.References.Refs (replaceRefs) where import Text.Pandoc.Definition@@ -25,6 +26,7 @@ import Control.Monad.State hiding (get, modify) import Data.List import qualified Data.List.HT as HT+import qualified Data.Text as T import Data.Maybe import Data.Function import qualified Data.Map as M@@ -57,7 +59,7 @@ <> intercalate' (text "; ") (map citationToInlines cits') <> str "]" citationToInlines c =- fromList (citationPrefix c) <> text ("@" ++ citationId c)+ fromList (citationPrefix c) <> text ("@" <> citationId c) <> fromList (citationSuffix c) replaceRefs'' = case outFormat opts of f | isLatexFormat f -> replaceRefsLatex@@ -65,7 +67,7 @@ replaceRefs _ x = return x -- accessors to state variables-accMap :: M.Map String (Accessor References RefMap)+accMap :: M.Map T.Text (Accessor References RefMap) accMap = M.fromList [("fig:",imgRefs) ,("eq:" ,eqnRefs) ,("tbl:",tblRefs)@@ -74,7 +76,7 @@ ] -- accessors to options-prefMap :: M.Map String (Options -> Bool -> Int -> [Inline], Options -> Template)+prefMap :: M.Map T.Text (Options -> Bool -> Int -> [Inline], Options -> Template) prefMap = M.fromList [("fig:",(figPrefix, figPrefixTemplate)) ,("eq:" ,(eqnPrefix, eqnPrefixTemplate)) ,("tbl:",(tblPrefix, tblPrefixTemplate))@@ -82,10 +84,10 @@ ,("sec:",(secPrefix, secPrefixTemplate)) ] -prefixes :: [String]+prefixes :: [T.Text] prefixes = M.keys accMap -getRefPrefix :: Options -> String -> Bool -> Int -> [Inline] -> [Inline]+getRefPrefix :: Options -> T.Text -> Bool -> Int -> [Inline] -> [Inline] getRefPrefix opts prefix capitalize num cit = applyTemplate' (M.fromDistinctAscList [("i", cit), ("p", refprefix)]) $ reftempl opts@@ -96,13 +98,13 @@ lookupUnsafe :: Ord k => k -> M.Map k v -> v lookupUnsafe = (fromJust .) . M.lookup -allCitsPrefix :: [Citation] -> Maybe String+allCitsPrefix :: [Citation] -> Maybe T.Text allCitsPrefix cits = find isCitationPrefix prefixes where isCitationPrefix p =- all (p `isPrefixOf`) $ map (uncapitalizeFirst . citationId) cits+ all (p `T.isPrefixOf`) $ map (uncapitalizeFirst . citationId) cits -replaceRefsLatex :: String -> Options -> [Citation] -> WS [Inline]+replaceRefsLatex :: T.Text -> Options -> [Citation] -> WS [Inline] replaceRefsLatex prefix opts cits | cref opts = replaceRefsLatex' prefix opts cits@@ -110,14 +112,14 @@ = toList . intercalate' (text ", ") . map fromList <$> mapM (replaceRefsLatex' prefix opts) (groupBy citationGroupPred cits) -replaceRefsLatex' :: String -> Options -> [Citation] -> WS [Inline]+replaceRefsLatex' :: T.Text -> Options -> [Citation] -> WS [Inline] replaceRefsLatex' prefix opts cits = return $ p [texcit] where texcit = RawInline (Format "tex") $ if cref opts then- cref'++"{"++listLabels prefix "" "," "" cits++"}"+ cref'<>"{"<>listLabels prefix "" "," "" cits<>"}" else listLabels prefix "\\ref{" ", " "}" cits suppressAuthor = all (==SuppressAuthor) $ map citationMode cits@@ -127,33 +129,33 @@ = id | noPrefix = getRefPrefix opts prefix cap (length cits - 1)- | otherwise = ((citationPrefix (head cits) ++ [Space]) ++)+ | otherwise = ((citationPrefix (head cits) <> [Space]) <>) cap = maybe False isFirstUpper $ getLabelPrefix . citationId . head $ cits cref' | suppressAuthor = "\\labelcref" | cap = "\\Cref" | otherwise = "\\cref" -listLabels :: String -> String -> String -> String -> [Citation] -> String+listLabels :: T.Text -> T.Text -> T.Text -> T.Text -> [Citation] -> T.Text listLabels prefix p sep s =- intercalate sep . map ((p ++) . (++ s) . mkLaTeXLabel' . (prefix++) . getLabelWithoutPrefix . citationId)+ T.intercalate sep . map ((p <>) . (<> s) . mkLaTeXLabel' . (prefix<>) . getLabelWithoutPrefix . citationId) -getLabelWithoutPrefix :: String -> String-getLabelWithoutPrefix = drop 1 . dropWhile (/=':')+getLabelWithoutPrefix :: T.Text -> T.Text+getLabelWithoutPrefix = T.drop 1 . T.dropWhile (/=':') -getLabelPrefix :: String -> Maybe String+getLabelPrefix :: T.Text -> Maybe T.Text getLabelPrefix lab | uncapitalizeFirst p `elem` prefixes = Just p | otherwise = Nothing- where p = (++ ":") . takeWhile (/=':') $ lab+ where p = flip T.snoc ':' . T.takeWhile (/=':') $ lab -replaceRefsOther :: String -> Options -> [Citation] -> WS [Inline]+replaceRefsOther :: T.Text -> Options -> [Citation] -> WS [Inline] replaceRefsOther prefix opts cits = toList . intercalate' (text ", ") . map fromList <$> mapM (replaceRefsOther' prefix opts) (groupBy citationGroupPred cits) citationGroupPred :: Citation -> Citation -> Bool citationGroupPred = (==) `on` liftM2 (,) citationPrefix citationMode -replaceRefsOther' :: String -> Options -> [Citation] -> WS [Inline]+replaceRefsOther' :: T.Text -> Options -> [Citation] -> WS [Inline] replaceRefsOther' prefix opts cits = do indices <- mapM (getRefIndex prefix opts) cits let@@ -169,7 +171,7 @@ cmap f x = f x return $ writePrefix (makeIndices opts indices) -data RefData = RefData { rdLabel :: String+data RefData = RefData { rdLabel :: T.Text , rdIdx :: Maybe Index , rdSubfig :: Maybe Index , rdSuffix :: [Inline]@@ -178,7 +180,7 @@ instance Ord RefData where (<=) = (<=) `on` rdIdx -getRefIndex :: String -> Options -> Citation -> WS RefData+getRefIndex :: T.Text -> Options -> Citation -> WS RefData getRefIndex prefix _opts Citation{citationId=cid,citationSuffix=suf} = do ref <- M.lookup lab <$> get prop@@ -192,7 +194,7 @@ } where prop = lookupUnsafe prefix accMap- lab = prefix ++ getLabelWithoutPrefix cid+ lab = prefix <> getLabelWithoutPrefix cid data RefItem = RefRange RefData RefData | RefSingle RefData @@ -231,7 +233,7 @@ show'' (RefRange x y) = show' x <> fromList (rangeDelim o) <> show' y show' :: RefData -> Inlines show' RefData{rdLabel=l, rdIdx=Just i, rdSubfig = sub, rdSuffix = suf}- | linkReferences o = link ('#':l) "" (fromList txt)+ | linkReferences o = link ('#' `T.cons` l) "" (fromList txt) | otherwise = fromList txt where txt@@ -249,5 +251,5 @@ ] in applyTemplate' vars $ refIndexTemplate o show' RefData{rdLabel=l, rdIdx=Nothing, rdSuffix = suf} =- trace ("Undefined cross-reference: " ++ l)- (strong (text $ "¿" ++ l ++ "?") <> fromList suf)+ trace (T.unpack $ "Undefined cross-reference: " <> l)+ (strong (text $ "¿" <> l <> "?") <> fromList suf)
lib/Text/Pandoc/CrossRef/References/Types.hs view
@@ -26,15 +26,16 @@ import Control.Monad.State import Data.Default import Data.Accessor.Template+import Data.Text (Text) -type Index = [(Int, Maybe String)]+type Index = [(Int, Maybe Text)] data RefRec = RefRec { refIndex :: Index , refTitle :: [Inline] , refSubfigure :: Maybe Index } deriving (Show, Eq) -type RefMap = M.Map String RefRec+type RefMap = M.Map Text RefRec -- state data type data References = References { imgRefs_ :: RefMap
lib/Text/Pandoc/CrossRef/Util/CodeBlockCaptions.hs view
@@ -18,17 +18,19 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} +{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.CodeBlockCaptions ( mkCodeBlockCaptions ) where import Text.Pandoc.Definition-import Data.List (isPrefixOf, stripPrefix)+import Data.List (stripPrefix) import Data.Maybe (fromMaybe) import Text.Pandoc.CrossRef.References.Types import Text.Pandoc.CrossRef.Util.Options import Text.Pandoc.CrossRef.Util.Util+import qualified Data.Text as T mkCodeBlockCaptions :: Options -> [Block] -> WS [Block] mkCodeBlockCaptions opts x@(cb@(CodeBlock _ _):p@(Para _):xs)@@ -41,16 +43,16 @@ orderAgnostic opts (Para ils:CodeBlock (label,classes,attrs) code:xs) | codeBlockCaptions opts , Just caption <- getCodeBlockCaption ils- , not $ null label- , "lst" `isPrefixOf` label+ , not $ T.null label+ , "lst" `T.isPrefixOf` label = return $ Div (label,"listing":classes, [])- [Para caption, CodeBlock ([],classes,attrs) code] : xs+ [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 = return $ Div (label,"listing":classes, [])- [Para $ init caption, CodeBlock ([],classes,attrs) code] : xs+ [Para $ init caption, CodeBlock ("",classes,attrs) code] : xs where splitLast xs' = splitAt (length xs' - 1) xs' orderAgnostic _ _ = Nothing
lib/Text/Pandoc/CrossRef/Util/CustomLabels.hs view
@@ -18,21 +18,22 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} +{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.CustomLabels (customLabel) where import Text.Pandoc.Definition import Text.Pandoc.CrossRef.Util.Meta-import Data.List import Text.Numeral.Roman+import qualified Data.Text as T -customLabel :: Meta -> String -> Int -> Maybe String+customLabel :: Meta -> T.Text -> Int -> Maybe T.Text customLabel meta ref i- | refLabel <- takeWhile (/=':') ref- , Just cl <- lookupMeta (refLabel++"Labels") meta- = mkLabel i (refLabel++"Labels") cl+ | refLabel <- T.takeWhile (/=':') ref+ , Just cl <- lookupMeta (refLabel <> "Labels") meta+ = mkLabel i (refLabel <> "Labels") cl | otherwise = Nothing -mkLabel :: Int -> String -> MetaValue -> Maybe String+mkLabel :: Int -> T.Text -> MetaValue -> Maybe T.Text mkLabel i n lt | MetaList _ <- lt , Just val <- toString n <$> getList (i-1) lt@@ -41,6 +42,6 @@ = Nothing | toString n lt == "roman" = Just $ toRoman i- | Just (startWith:_) <- stripPrefix "alpha " $ toString n lt- = Just [[startWith..] !! (i-1)]+ | Just (startWith, _) <- T.uncons =<< T.stripPrefix "alpha " (toString n lt)+ = Just . T.singleton $ [startWith..] !! (i-1) | otherwise = error $ "Unknown numeration type: " ++ show lt
lib/Text/Pandoc/CrossRef/Util/Meta.hs view
@@ -37,23 +37,24 @@ import Data.Default import Text.Pandoc.Walk import Text.Pandoc.Shared hiding (capitalize, toString)+import qualified Data.Text as T -getMetaList :: (Default a) => (MetaValue -> a) -> String -> Meta -> Int -> a+getMetaList :: (Default a) => (MetaValue -> a) -> T.Text -> Meta -> Int -> a getMetaList f name meta i = maybe def f $ lookupMeta name meta >>= getList i -getMetaBool :: String -> Meta -> Bool+getMetaBool :: T.Text -> Meta -> Bool getMetaBool = getScalar toBool -getMetaInlines :: String -> Meta -> [Inline]+getMetaInlines :: T.Text -> Meta -> [Inline] getMetaInlines = getScalar toInlines -getMetaBlock :: String -> Meta -> [Block]+getMetaBlock :: T.Text -> Meta -> [Block] getMetaBlock = getScalar toBlocks -getMetaString :: String -> Meta -> String+getMetaString :: T.Text -> Meta -> T.Text getMetaString = getScalar toString -getScalar :: Def b => (String -> MetaValue -> b) -> String -> Meta -> b+getScalar :: Def b => (T.Text -> MetaValue -> b) -> T.Text -> Meta -> b getScalar conv name meta = maybe def' (conv name) $ lookupMeta name meta class Def a where@@ -65,8 +66,11 @@ instance Def [a] where def' = [] -unexpectedError :: forall a. String -> String -> MetaValue -> a-unexpectedError e n x = error $ "Expected " <> e <> " in metadata field " <> n <> " but got " <> g x+instance Def T.Text where+ def' = T.empty++unexpectedError :: forall a. String -> T.Text -> MetaValue -> a+unexpectedError e n x = error $ "Expected " <> e <> " in metadata field " <> T.unpack n <> " but got " <> g x where g (MetaBlocks _) = "blocks" g (MetaString _) = "string"@@ -75,23 +79,23 @@ g (MetaMap _) = "map" g (MetaList _) = "list" -toInlines :: String -> MetaValue -> [Inline]+toInlines :: T.Text -> MetaValue -> [Inline] toInlines _ (MetaBlocks s) = blocksToInlines s toInlines _ (MetaInlines s) = s toInlines _ (MetaString s) = toList $ text s toInlines n x = unexpectedError "inlines" n x -toBool :: String -> MetaValue -> Bool+toBool :: T.Text -> MetaValue -> Bool toBool _ (MetaBool b) = b toBool n x = unexpectedError "bool" n x -toBlocks :: String -> MetaValue -> [Block]+toBlocks :: T.Text -> MetaValue -> [Block] toBlocks _ (MetaBlocks bs) = bs toBlocks _ (MetaInlines ils) = [Plain ils] toBlocks _ (MetaString s) = toList $ plain $ text s toBlocks n x = unexpectedError "blocks" n x -toString :: String -> MetaValue -> String+toString :: T.Text -> MetaValue -> T.Text toString _ (MetaString s) = s toString _ (MetaBlocks b) = stringify b toString _ (MetaInlines i) = stringify i@@ -106,7 +110,7 @@ getList _ x = Just x tryCapitalizeM :: (Functor m, Monad m, Walkable Inline a, Default a, Eq a) =>- (String -> m a) -> String -> Bool -> m a+ (T.Text -> m a) -> T.Text -> Bool -> m a tryCapitalizeM f varname capitalize | capitalize = do res <- f (capitalizeFirst varname)
lib/Text/Pandoc/CrossRef/Util/ModifyMeta.hs view
@@ -18,12 +18,12 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} +{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.ModifyMeta ( modifyMeta ) where -import Data.List (intercalate) import Text.Pandoc import Text.Pandoc.Builder hiding ((<>)) import Text.Pandoc.CrossRef.Util.Options@@ -42,9 +42,9 @@ where headerInc :: Maybe MetaValue -> MetaValue headerInc Nothing = incList- headerInc (Just (MetaList x)) = MetaList $ x ++ [incList]+ headerInc (Just (MetaList x)) = MetaList $ x <> [incList] headerInc (Just x) = MetaList [x, incList]- incList = MetaBlocks $ return $ RawBlock (Format "latex") $ unlines $ execWriter $ do+ incList = MetaBlocks $ return $ RawBlock (Format "latex") $ T.unlines $ execWriter $ do tell [ "\\makeatletter" ] tell subfig tell floatnames@@ -65,30 +65,30 @@ ] floatnames = [ "\\AtBeginDocument{%"- , "\\renewcommand*\\figurename{"++metaString "figureTitle"++"}"- , "\\renewcommand*\\tablename{"++metaString "tableTitle"++"}"+ , "\\renewcommand*\\figurename{" <> metaString "figureTitle" <> "}"+ , "\\renewcommand*\\tablename{" <> metaString "tableTitle" <> "}" , "}" ] listnames = [ "\\AtBeginDocument{%"- , "\\renewcommand*\\listfigurename{"++metaString' "lofTitle"++"}"- , "\\renewcommand*\\listtablename{"++metaString' "lotTitle"++"}"+ , "\\renewcommand*\\listfigurename{" <> metaString' "lofTitle" <> "}"+ , "\\renewcommand*\\listtablename{" <> metaString' "lotTitle" <> "}" , "}" ] codelisting = [ usepackage [] "float" , "\\floatstyle{ruled}" , "\\@ifundefined{c@chapter}{\\newfloat{codelisting}{h}{lop}}{\\newfloat{codelisting}{h}{lop}[chapter]}"- , "\\floatname{codelisting}{"++metaString "listingTitle"++"}"+ , "\\floatname{codelisting}{" <> metaString "listingTitle" <> "}" ] lolcommand | listings opts = [ "\\newcommand*\\listoflistings\\lstlistoflistings" , "\\AtBeginDocument{%"- , "\\renewcommand*{\\lstlistlistingname}{"++metaString' "lolTitle"++"}"+ , "\\renewcommand*{\\lstlistlistingname}{" <> metaString' "lolTitle" <> "}" , "}" ]- | otherwise = ["\\newcommand*\\listoflistings{\\listof{codelisting}{"++metaString' "lolTitle"++"}}"]+ | otherwise = ["\\newcommand*\\listoflistings{\\listof{codelisting}{" <> metaString' "lolTitle" <> "}}"] cleveref = [ usepackage cleverefOpts "cleveref" ] <> crefname "figure" figPrefix <> crefname "table" tblPrefix@@ -102,14 +102,14 @@ cleverefOpts | nameInLink opts = [ "nameinlink" ] | otherwise = [] crefname n f = [- "\\crefname{" ++ n ++ "}" ++ prefix f False- , "\\Crefname{" ++ n ++ "}" ++ prefix f True+ "\\crefname{" <> n <> "}" <> prefix f False+ , "\\Crefname{" <> n <> "}" <> prefix f True ]- usepackage [] p = "\\@ifpackageloaded{"++p++"}{}{\\usepackage{"++p++"}}"- usepackage xs p = "\\@ifpackageloaded{"++p++"}{}{\\usepackage"++o++"{"++p++"}}"- where o = "[" ++ intercalate "," xs ++ "]"- toLatex = either (error . show) T.unpack . runPure . writeLaTeX def . Pandoc nullMeta . return . Plain+ usepackage [] p = "\\@ifpackageloaded{" <> p <> "}{}{\\usepackage{" <> p <> "}}"+ usepackage xs p = "\\@ifpackageloaded{" <> p <> "}{}{\\usepackage" <> o <> "{" <> p <> "}}"+ where o = "[" <> T.intercalate "," xs <> "]"+ toLatex = either (error . show) id . runPure . writeLaTeX def . Pandoc nullMeta . return . Plain metaString s = toLatex $ getMetaInlines s meta metaString' s = toLatex [Str $ getMetaString s meta]- prefix f uc = "{" ++ toLatex (f opts uc 0) ++ "}" ++- "{" ++ toLatex (f opts uc 1) ++ "}"+ prefix f uc = "{" <> toLatex (f opts uc 0) <> "}" <>+ "{" <> toLatex (f opts uc 1) <> "}"
lib/Text/Pandoc/CrossRef/Util/Options.hs view
@@ -21,6 +21,7 @@ module Text.Pandoc.CrossRef.Util.Options (Options(..)) where import Text.Pandoc.Definition import Text.Pandoc.CrossRef.Util.Template+import Data.Text (Text) data Options = Options { cref :: Bool , chaptersDepth :: Int@@ -57,7 +58,7 @@ , ccsTemplate :: Template , tableTemplate :: Template , listingTemplate :: Template- , customLabel :: String -> Int -> Maybe String+ , customLabel :: Text -> Int -> Maybe Text , ccsDelim :: [Inline] , ccsLabelSep :: [Inline] , tableEqns :: Bool
lib/Text/Pandoc/CrossRef/Util/Settings.hs view
@@ -19,6 +19,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} +{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.Settings (getSettings, defaultMeta) where import Text.Pandoc@@ -34,11 +35,11 @@ getSettings :: Maybe Format -> Meta -> IO Meta getSettings fmt meta = do- dirConfig <- readConfig (getMetaString "crossrefYaml" (meta <> defaultMeta))+ dirConfig <- readConfig (T.unpack $ getMetaString "crossrefYaml" (meta <> defaultMeta)) home <- getHomeDirectory globalConfig <- readConfig (home </> ".pandoc-crossref" </> "config.yaml") formatConfig <- maybe (return nullMeta) (readFmtConfig home) fmt- return $ meta <> dirConfig <> formatConfig <> globalConfig <> defaultMeta+ return $ defaultMeta <> globalConfig <> formatConfig <> dirConfig <> meta where readConfig path = handle handler $ do@@ -51,7 +52,7 @@ readFmtConfig home fmt' = readConfig (home </> ".pandoc-crossref" </> "config-" ++ fmtStr fmt' ++ ".yaml") handler :: IOException -> IO Meta handler _ = return nullMeta- fmtStr (Format fmtstr) = fmtstr+ fmtStr (Format fmtstr) = T.unpack fmtstr defaultMeta :: Meta
lib/Text/Pandoc/CrossRef/Util/Settings/Gen.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TemplateHaskell, OverloadedStrings #-} -- {-# OPTIONS_GHC -ddump-splices #-} module Text.Pandoc.CrossRef.Util.Settings.Gen where
lib/Text/Pandoc/CrossRef/Util/Settings/Template.hs view
@@ -30,6 +30,8 @@ import Data.List import Text.Pandoc.CrossRef.Util.Template import Text.Pandoc.CrossRef.Util.CustomLabels (customLabel)+import Data.Text (Text)+import qualified Data.Text as T namedFields :: Con -> [VarStrictType] namedFields (RecC _ fs) = fs@@ -77,13 +79,13 @@ boolT <- [t|$(conT t) -> Bool|] intT <- [t|$(conT t) -> Int|] tmplT <- [t|$(conT t) -> Template|]- clT <- [t|$(conT t) -> String -> Int -> Maybe String|]+ clT <- [t|$(conT t) -> Text -> Int -> Maybe Text|] let varName | Name (OccName n) _ <- accName = liftString n let dtv = return $ VarE $ mkName "dtv" body <- if | t' == boolT -> [|getMetaBool $(varName) $(dtv)|]- | t' == intT -> [|read $ getMetaString $(varName) $(dtv)|]+ | t' == intT -> [|read $ T.unpack $ getMetaString $(varName) $(dtv)|] | t' == funT -> [|tryCapitalizeM (flip (getMetaList (toInlines $(varName))) $(dtv)) $(varName)|] | t' == inlT -> [|getMetaInlines $(varName) $(dtv)|] | t' == blkT -> [|getMetaBlock $(varName) $(dtv)|]
lib/Text/Pandoc/CrossRef/Util/Template.hs view
@@ -18,6 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} +{-# LANGUAGE OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.Template ( Template , makeTemplate@@ -32,8 +33,9 @@ import Text.Pandoc.CrossRef.Util.Meta import Control.Applicative import Text.Read+import qualified Data.Text as T -type VarFunc = String -> Maybe MetaValue+type VarFunc = T.Text -> Maybe MetaValue newtype Template = Template (VarFunc -> [Inline]) makeTemplate :: Meta -> [Inline] -> Template@@ -41,10 +43,11 @@ where scan = bottomUp . go go vf (x@(Math DisplayMath var):xs)- | '[' `elem` var && ']' == last var =- let (vn, idxBr) = span (/='[') var- idxVar = drop 1 $ takeWhile (/=']') idxBr- idx = readMaybe . toString ("index variable " ++ idxVar) =<< vf idxVar+ | (vn, idxBr) <- T.span (/='[') var+ , not (T.null idxBr)+ , T.last idxBr == ']'+ = let idxVar = T.drop 1 $ T.takeWhile (/=']') idxBr+ idx = readMaybe . T.unpack . toString ("index variable " <> idxVar) =<< vf idxVar arr = do i <- idx v <- lookupMeta vn dtv@@ -53,9 +56,9 @@ | otherwise = toList $ fromList (replaceVar var (vf var) [x]) <> fromList xs go _ (x:xs) = toList $ singleton x <> fromList xs go _ [] = []- replaceVar var val def' = maybe def' (toInlines ("variable " ++ var)) val+ replaceVar var val def' = maybe def' (toInlines ("variable " <> var)) val -applyTemplate' :: M.Map String [Inline] -> Template -> [Inline]+applyTemplate' :: M.Map T.Text [Inline] -> Template -> [Inline] applyTemplate' vars (Template g) = g internalVars where internalVars x | Just v <- M.lookup x vars = Just $ MetaInlines v
lib/Text/Pandoc/CrossRef/Util/Util.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE RankNTypes, OverloadedStrings #-} module Text.Pandoc.CrossRef.Util.Util ( module Text.Pandoc.CrossRef.Util.Util , module Data.Generics@@ -29,7 +29,6 @@ import Text.Pandoc.Builder hiding ((<>)) import Text.Pandoc.Class import Data.Char (toUpper, toLower, isUpper)-import Data.List (isSuffixOf, isPrefixOf, stripPrefix) import Data.Maybe (fromMaybe) import Data.Generics import Text.Pandoc.Writers.LaTeX@@ -38,30 +37,35 @@ import qualified Data.Text as T intercalate' :: (Eq a, Monoid a, Foldable f) => a -> f a -> a-intercalate' s = foldr (\x acc -> if acc == mempty then x else x <> s <> acc) mempty+intercalate' s xs+ | null xs = mempty+ | otherwise = foldr1 (\x acc -> x <> s <> acc) xs -isFormat :: String -> Maybe Format -> Bool-isFormat fmt (Just (Format f)) = takeWhile (`notElem` "+-") f == fmt+isFormat :: T.Text -> Maybe Format -> Bool+isFormat fmt (Just (Format f)) = T.takeWhile (`notElem` ("+-" :: String)) f == fmt isFormat _ Nothing = False isLatexFormat :: Maybe Format -> Bool isLatexFormat = isFormat "latex" `or'` isFormat "beamer" where a `or'` b = (||) <$> a <*> b -capitalizeFirst :: String -> String-capitalizeFirst (x:xs) = toUpper x : xs-capitalizeFirst [] = []+capitalizeFirst :: T.Text -> T.Text+capitalizeFirst t+ | Just (x, xs) <- T.uncons t = toUpper x `T.cons` xs+ | otherwise = T.empty -uncapitalizeFirst :: String -> String-uncapitalizeFirst (x:xs) = toLower x : xs-uncapitalizeFirst [] = []+uncapitalizeFirst :: T.Text -> T.Text+uncapitalizeFirst t+ | Just (x, xs) <- T.uncons t = toLower x `T.cons` xs+ | otherwise = T.empty -isFirstUpper :: String -> Bool-isFirstUpper (x:_) = isUpper x-isFirstUpper [] = False+isFirstUpper :: T.Text -> Bool+isFirstUpper xs+ | Just (x, _) <- T.uncons xs = isUpper x+ | otherwise = False chapPrefix :: [Inline] -> Index -> [Inline]-chapPrefix delim index = toList $ intercalate' (fromList delim) (map (str . uncurry (fromMaybe . show)) index)+chapPrefix delim index = toList $ intercalate' (fromList delim) (map (str . uncurry (fromMaybe . T.pack . show)) index) data ReplacedResult a = Replaced Bool a | NotReplaced Bool type GenRR m = forall a. Data a => (a -> m (ReplacedResult a))@@ -102,25 +106,25 @@ noReplaceNoRecurse :: Monad m => m (ReplacedResult a) noReplaceNoRecurse = noReplace False -mkLaTeXLabel :: String -> String+mkLaTeXLabel :: T.Text -> T.Text mkLaTeXLabel l- | null l = []- | otherwise = "\\label{" ++ mkLaTeXLabel' l ++ "}"+ | T.null l = ""+ | otherwise = "\\label{" <> mkLaTeXLabel' l <> "}" -mkLaTeXLabel' :: String -> String+mkLaTeXLabel' :: T.Text -> T.Text mkLaTeXLabel' l =- let ll = either (error . show) T.unpack $+ let ll = either (error . show) id $ runPure (writeLaTeX def $ Pandoc nullMeta [Div (l, [], []) []])- in takeWhile (/='}') . drop 1 . dropWhile (/='{') $ ll+ in T.takeWhile (/='}') . T.drop 1 . T.dropWhile (/='{') $ ll -getRefLabel :: String -> [Inline] -> Maybe String+getRefLabel :: T.Text -> [Inline] -> Maybe T.Text getRefLabel _ [] = Nothing getRefLabel tag ils | Str attr <- last ils , all (==Space) (init ils)- , "}" `isSuffixOf` attr- , ("{#"++tag++":") `isPrefixOf` attr- = init `fmap` stripPrefix "{#" attr+ , "}" `T.isSuffixOf` attr+ , ("{#"<>tag<>":") `T.isPrefixOf` attr+ = T.init `fmap` T.stripPrefix "{#" attr getRefLabel _ _ = Nothing isSpace :: Inline -> Bool
pandoc-crossref.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: edd11ea020cd9236b745c8aa8d2a9728ac41f337c5648fc1d98b28e62e7f4584+-- hash: 687fe16beac2bf05405a0f58a865e76f50971758d90614f06a51116717839e64 name: pandoc-crossref-version: 0.3.4.2+version: 0.3.5.0 synopsis: Pandoc filter for cross-references description: pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them. category: Text@@ -104,8 +104,8 @@ , directory >=1 && <1.4 , filepath >=1.1 && <1.5 , mtl >=1.1 && <2.3- , pandoc >=2.3 && <2.8- , pandoc-types >=1.17.5.1 && <1.18+ , pandoc >=2.8 && <2.9+ , pandoc-types >=1.20 && <1.21 , roman-numerals ==0.5.* , syb >=0.4 && <0.8 , template-haskell >=2.7.0.0 && <3.0.0.0@@ -135,9 +135,9 @@ , mtl >=1.1 && <2.3 , open-browser >=0.2 && <0.3 , optparse-applicative >=0.13 && <0.16- , pandoc >=2.3 && <2.8+ , pandoc >=2.8 && <2.9 , pandoc-crossref- , pandoc-types >=1.17.5.1 && <1.18+ , pandoc-types >=1.20 && <1.21 , roman-numerals ==0.5.* , syb >=0.4 && <0.8 , template-haskell >=2.7.0.0 && <3.0.0.0@@ -163,9 +163,9 @@ , filepath >=1.1 && <1.5 , hspec >=2.4.4 && <3 , mtl >=1.1 && <2.3- , pandoc >=2.3 && <2.8+ , pandoc >=2.8 && <2.9 , pandoc-crossref- , pandoc-types >=1.17.5.1 && <1.18+ , pandoc-types >=1.20 && <1.21 , roman-numerals ==0.5.* , syb >=0.4 && <0.8 , template-haskell >=2.7.0.0 && <3.0.0.0@@ -212,8 +212,8 @@ , filepath >=1.1 && <1.5 , hspec >=2.4.4 && <3 , mtl >=1.1 && <2.3- , pandoc >=2.3 && <2.8- , pandoc-types >=1.17.5.1 && <1.18+ , pandoc >=2.8 && <2.9+ , pandoc-types >=1.20 && <1.21 , roman-numerals ==0.5.* , syb >=0.4 && <0.8 , template-haskell >=2.7.0.0 && <3.0.0.0
src/ManData.hs view
@@ -18,13 +18,14 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE TemplateHaskellQuotes #-}+{-# LANGUAGE TemplateHaskellQuotes, OverloadedStrings #-} module ManData where import Language.Haskell.TH.Syntax import qualified Data.Text as T import System.IO import qualified Text.Pandoc as P+import qualified Text.Pandoc.Templates as PT import Control.DeepSeq import Data.String import Text.Pandoc.Highlighting (pygments)@@ -58,9 +59,11 @@ embedManualHtml :: Q Exp embedManualHtml = do- t <- runIO $ fmap (either (error . show) id) $ P.runIO $ P.getDefaultTemplate "html5"+ tt <- fmap (either (error . show) id) . runIO . P.runIO+ $ P.getDefaultTemplate "html5"+ >>= fmap (either (error . show) id) . PT.compileTemplate "" embedManual $ P.writeHtml5String P.def{- P.writerTemplate = Just t+ P.writerTemplate = Just tt , P.writerHighlightStyle = Just pygments }
src/pandoc-crossref.hs view
@@ -18,7 +18,8 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE ApplicativeDo, TemplateHaskell, CPP, OverloadedStrings #-}+{-# LANGUAGE ApplicativeDo, TemplateHaskell, CPP, OverloadedStrings,+ LambdaCase #-} import Text.Pandoc import Text.Pandoc.JSON @@ -26,6 +27,7 @@ import Options.Applicative import qualified Options.Applicative as O import Control.Monad+import System.Environment as Env import Web.Browser import System.IO.Temp import System.IO hiding (putStrLn)@@ -41,7 +43,7 @@ man = T.pack $(embedManualText) manHtml = T.pack $(embedManualHtml) -data Flag = NumericVersion | Version | Man | HtmlMan+data Flag = NumericVersion | Version | Man | HtmlMan | Pipe run :: Parser (IO ()) run = do@@ -49,8 +51,9 @@ vers <- flag Nothing (Just Version) (long "version" <> short 'v' <> help "Print version") man' <- flag Nothing (Just Man) (long "man" <> help "Show manpage") hman <- flag Nothing (Just HtmlMan) (long "man-html" <> help "Show html manpage")+ pipe <- flag Nothing (Just Pipe) (short 'p' <> long "pipe" <> help "Run in \"pipe mode\", i.e. read pandoc JSON from stdin and output it to stdout") fmt <- optional $ strArgument (metavar "FORMAT")- return $ go (numVers <|> vers <|> man' <|> hman) fmt+ return $ go (numVers <|> vers <|> man' <|> hman <|> pipe) fmt where go :: Maybe Flag -> Maybe String -> IO () go (Just Version) _ = T.putStrLn $@@ -69,9 +72,27 @@ void $ openBrowser $ "file:///" <> fp threadDelay 5000000 return ()- go Nothing _ = toJSONFilter f- f fmt p@(Pandoc meta _) =- runCrossRefIO meta fmt defaultCrossRefAction p+ go (Just Pipe) _ = toJSONFilter f+ go Nothing Nothing = hPutStr stderr $ unlines+ [ "Running pandoc-crossref without arguments is not supported. Try"+ , "\tpandoc-crossref --help"+ , "If you want to run in \"pipe mode\", run with"+ , "\tpandoc-crossref --pipe [FORMAT]"+ ]+ go Nothing _ = do+ Env.lookupEnv "PANDOC_VERSION" >>= \case+ Just runv ->+ when (VERSION_pandoc /= runv) $ hPutStrLn stderr $+ "WARNING: pandoc-crossref was compiled with pandoc " <> VERSION_pandoc <>+ " but is being run through " <> runv <> ". This is not supported. " <>+ "Strange things may (and likely will) happen silently."+ Nothing -> hPutStr stderr $ unlines+ [ "WARNING: Running pandoc-crossref in \"pipe mode\" implicitly is deprecated. Please use"+ , "\tpandoc-crossref --pipe [FORMAT]"+ , "instead."+ ]+ toJSONFilter f+ f fmt p@(Pandoc meta _) = runCrossRefIO meta fmt defaultCrossRefAction p main :: IO () main = join $ execParser opts
test/Native.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE CPP #-}+{-# LANGUAGE CPP, OverloadedStrings #-} module Native where import Text.Pandoc.Definition
test/m2m/listing-captions-ids/expect.tex view
@@ -140,7 +140,7 @@ \end{codelisting} -\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}+\begin{center}\rule{0.5\linewidth}{0.5pt}\end{center} : Listing caption 15 (invalid) @@ -159,4 +159,3 @@ \NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello World!"} \end{Highlighting} \end{Shaded}-
test/m2m/subfigures-grid/expect.md view
@@ -2,16 +2,16 @@ ::: {#fig:subfigures .subfigures} +:------------------:+:------------------:+:------------------:+-| {#fi | {#fi | {wid |-| g:subfig1 | g:subfig2 | th="100%"} |+| {#fig:subfig1 | .png){#fig:subfig2 | png){width="100%"} | | width="100%"} | width="100%"} | | +--------------------+--------------------+--------------------+-| {#fi | {wid | {#fi |-| g:subfig4 | th="100%"} | g:subfig6 |+| {#fig:subfig4 | png){width="100%"} | .png){#fig:subfig6 | | width="100%"} | | width="100%"} | +--------------------+--------------------+--------------------+-| {#fi | {wid | {#fi |-| g:subfig7 | th="100%"} | g:subfig9 |+| {#fig:subfig7 | png){width="100%"} | .png){#fig:subfig9 | | width="100%"} | | width="100%"} | +--------------------+--------------------+--------------------+
test/test-integrative.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE CPP #-}+{-# LANGUAGE CPP, OverloadedStrings #-} import Test.Hspec import Text.Pandoc hiding (runIO) import qualified Text.Pandoc as P (runIO)
test/test-pandoc-crossref.hs view
@@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -} -{-# LANGUAGE FlexibleContexts, CPP #-}+{-# LANGUAGE FlexibleContexts, CPP, OverloadedStrings #-} import Test.Hspec import Text.Pandoc hiding (getDataFileName) import Text.Pandoc.Builder@@ -50,7 +50,7 @@ describe "References.Blocks.replaceInlines" $ do it "Labels equations" $ testAll (equation' "a^2+b^2=c^2" "equation")- (spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" []),+ (spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" ""), eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) it "Labels equations in the middle of text" $ testAll (@@ -59,7 +59,7 @@ <> text " it should be labeled") ( text "This is an equation: "- <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" [])+ <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" "") <> text " it should be labeled", eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) it "Labels equations in the beginning of text" $@@ -67,7 +67,7 @@ equation' "a^2+b^2=c^2" "equation" <> text " it should be labeled") (- spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" [])+ spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" "") <> text " it should be labeled", eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) it "Labels equations in the end of text" $@@ -76,7 +76,7 @@ <> equation' "a^2+b^2=c^2" "equation") ( text "This is an equation: "- <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" []),+ <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" ""), eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) -- TODO:@@ -85,31 +85,31 @@ describe "References.Blocks.replaceBlocks" $ do it "Labels images" $- testAll (figure "test.jpg" [] "Test figure" "figure")- (figure "test.jpg" [] "Figure 1: Test figure" "figure",+ testAll (figure "test.jpg" "" "Test figure" "figure")+ (figure "test.jpg" "" "Figure 1: Test figure" "figure", imgRefs =: M.fromList $ refRec' "fig:figure" 1 "Test figure") it "Labels subfigures" $ testAll ( divWith ("fig:subfigure",[],[]) (- para (figure' "fig:" "test1.jpg" [] "Test figure 1" "figure1")- <>para (figure' "fig:" "test2.jpg" [] "Test figure 2" "figure2")+ para (figure' "fig:" "test1.jpg" "" "Test figure 1" "figure1")+ <>para (figure' "fig:" "test2.jpg" "" "Test figure 2" "figure2") <>para (text "figure caption") ) <> divWith ("fig:subfigure2",[],[]) (- para (figure' "fig:" "test21.jpg" [] "Test figure 21" "figure21")- <>para (figure' "fig:" "test22.jpg" [] "Test figure 22" "figure22")+ para (figure' "fig:" "test21.jpg" "" "Test figure 21" "figure21")+ <>para (figure' "fig:" "test22.jpg" "" "Test figure 22" "figure22") <>para (text "figure caption 2") ) ) ( divWith ("fig:subfigure",["subfigures"],[]) (- para (figure' "fig:" "test1.jpg" [] "a" "figure1")- <> para (figure' "fig:" "test2.jpg" [] "b" "figure2")+ para (figure' "fig:" "test1.jpg" "" "a" "figure1")+ <> para (figure' "fig:" "test2.jpg" "" "b" "figure2") <> para (text "Figure 1: figure caption. a — Test figure 1, b — Test figure 2") ) <> divWith ("fig:subfigure2",["subfigures"],[]) (- para (figure' "fig:" "test21.jpg" [] "a" "figure21")- <> para (figure' "fig:" "test22.jpg" [] "b" "figure22")+ para (figure' "fig:" "test21.jpg" "" "a" "figure21")+ <> para (figure' "fig:" "test22.jpg" "" "b" "figure22") <> para (text "Figure 2: figure caption 2. a — Test figure 21, b — Test figure 22") ) , imgRefs =: M.fromList [("fig:figure1",RefRec {@@ -140,7 +140,7 @@ ) it "Labels equations" $ testAll (equation "a^2+b^2=c^2" "equation")- (para $ spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" []),+ (para $ spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" ""), eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) it "Labels equations in the middle of text" $ testAll (para $@@ -149,7 +149,7 @@ <> text " it should be labeled") (para $ text "This is an equation: "- <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" [])+ <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" "") <> text " it should be labeled", eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) it "Labels equations in the beginning of text" $@@ -157,7 +157,7 @@ equation' "a^2+b^2=c^2" "equation" <> text " it should be labeled") (para $- spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" [])+ spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" "") <> text " it should be labeled", eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) it "Labels equations in the end of text" $@@ -166,11 +166,11 @@ <> equation' "a^2+b^2=c^2" "equation") (para $ text "This is an equation: "- <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" []),+ <> spanWith ("eq:equation", [], []) (equation' "a^2+b^2=c^2\\qquad(1)" ""), eqnRefs =: M.fromList $ refRec'' "eq:equation" 1) it "Labels tables" $ testAll (table' "Test table" "table")- (divWith ("tbl:table", [], []) $ table' "Table 1: Test table" [],+ (divWith ("tbl:table", [], []) $ table' "Table 1: Test table" "", tblRefs =: M.fromList $ refRec' "tbl:table" 1 "Test table") it "Labels code blocks" $ testAll (codeBlock' "Test code block" "codeblock")@@ -208,7 +208,7 @@ it "References multiple sections" $ testRefs' "sec:" [1..3] [4..6] secRefs "secs.\160\&4-6" it "Separates references to different chapter items by a comma" $- testRefs'' "lst:" [1..6] (zip [1,1..] [4..6] ++ zip [2,2..] [7..9]) lstRefs "lsts.\160\&1.4-1.6, 2.7-2.9"+ testRefs'' "lst:" [1..6] (zip [1,1..] [4..6] <> zip [2,2..] [7..9]) lstRefs "lsts.\160\&1.4-1.6, 2.7-2.9" describe "References.Refs.replaceRefs capitalization" $ do it "References one image" $@@ -236,11 +236,11 @@ it "Generates list of tables" $ testList (rawBlock "latex" "\\listoftables") (tblRefs =: M.fromList $ refRec' "tbl:1" 4 "4" <> refRec' "tbl:2" 5 "5" <> refRec' "tbl:3" 6 "6")- (header 1 (text "List of Tables") <> orderedList ((plain . str . show) `map` [4..6 :: Int]))+ (header 1 (text "List of Tables") <> orderedList ((plain . str . T.pack . show) `map` [4..6 :: Int])) it "Generates list of figures" $ testList (rawBlock "latex" "\\listoffigures") (imgRefs =: M.fromList $ refRec' "fig:1" 4 "4" <> refRec' "fig:2" 5 "5" <> refRec' "fig:3" 6 "6")- (header 1 (text "List of Figures") <> orderedList ((plain . str . show) `map` [4..6 :: Int]))+ (header 1 (text "List of Figures") <> orderedList ((plain . str . T.pack . show) `map` [4..6 :: Int])) describe "Util.CodeBlockCaptions" $ it "Transforms table-style codeBlock captions to codeblock divs" $ do@@ -266,8 +266,8 @@ testRefs cits def cits it "Should not separate citation groups with different unknown prefixes" $ do- let cits = para $ cite (mconcat $ map (cit . uncurry (++) . second show) l) $ text $- "[" ++ intercalate "; " (map (("@"++) . uncurry (++) . second show) l) ++ "]"+ let cits = para $ cite (mconcat $ map (cit . uncurry (<>) . second (T.pack . show)) l) $ text $+ "[" <> T.intercalate "; " (map (("@" <>) . uncurry (<>) . second (T.pack . show)) l) <> "]" l = zip ["unk1:", "unk2:"] [1,2::Int] testRefs cits def cits @@ -300,7 +300,7 @@ `test` "\\hypertarget{sec:section_label1}{%\n\\section{Section}\\label{sec:section_label1}}\n\nsec.~\\ref{sec:section_label1}" it "Image labels" $- figure "img.png" [] "Title" "figure_label1"+ figure "img.png" "" "Title" "figure_label1" <> para (citeGen "fig:figure_label" [1]) `test` "\\begin{figure}\n\\hypertarget{fig:figure_label1}{%\n\\centering\n\\includegraphics{img.png}\n\\caption{Title}\\label{fig:figure_label1}\n}\n\\end{figure}\n\nfig.~\\ref{fig:figure_label1}" @@ -329,29 +329,29 @@ <> para (citeGen "lst:some_codeblock" [1]) `test1` "\\begin{codelisting}\n\n\\caption{A code block}\n\n\\hypertarget{lst:some_codeblock1}{%\n\\label{lst:some_codeblock1}}%\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\OtherTok{main ::} \\DataTypeTok{IO}\\NormalTok{ ()}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:some_codeblock1}" -citeGen :: String -> [Int] -> Inlines-citeGen p l = cite (mconcat $ map (cit . (p++) . show) l) $ text $- "[" ++ intercalate "; " (map (("@"++) . (p++) . show) l) ++ "]"+citeGen :: T.Text -> [Int] -> Inlines+citeGen p l = cite (mconcat $ map (cit . (p<>) . T.pack . show) l) $ text $+ "[" <> T.intercalate "; " (map (("@"<>) . (p<>) . T.pack . show) l) <> "]" -refGen :: String -> [Int] -> [Int] -> M.Map String RefRec-refGen p l1 l2 = M.fromList $ mconcat $ zipWith refRec'' (((uncapitalizeFirst p++) . show) `map` l1) l2+refGen :: T.Text -> [Int] -> [Int] -> M.Map T.Text RefRec+refGen p l1 l2 = M.fromList $ mconcat $ zipWith refRec'' (((uncapitalizeFirst p<>) . T.pack . show) `map` l1) l2 -refGen' :: String -> [Int] -> [(Int, Int)] -> M.Map String RefRec-refGen' p l1 l2 = M.fromList $ mconcat $ zipWith refRec''' (((uncapitalizeFirst p++) . show) `map` l1) l2+refGen' :: T.Text -> [Int] -> [(Int, Int)] -> M.Map T.Text RefRec+refGen' p l1 l2 = M.fromList $ mconcat $ zipWith refRec''' (((uncapitalizeFirst p<>) . T.pack . show) `map` l1) l2 -refRec' :: String -> Int -> String -> [(String, RefRec)]+refRec' :: T.Text -> Int -> T.Text -> [(T.Text, RefRec)] refRec' ref i tit = [(ref, RefRec{refIndex=[(i,Nothing)],refTitle=toList $ text tit,refSubfigure=Nothing})] -refRec'' :: String -> Int -> [(String, RefRec)]-refRec'' ref i = refRec' ref i []+refRec'' :: T.Text -> Int -> [(T.Text, RefRec)]+refRec'' ref i = refRec' ref i "" -refRec''' :: String -> (Int, Int) -> [(String, RefRec)]-refRec''' ref (c,i) = [(ref, RefRec{refIndex=[(c,Nothing), (i,Nothing)],refTitle=toList $ text [],refSubfigure=Nothing})]+refRec''' :: T.Text -> (Int, Int) -> [(T.Text, RefRec)]+refRec''' ref (c,i) = [(ref, RefRec{refIndex=[(c,Nothing), (i,Nothing)],refTitle=toList $ text "",refSubfigure=Nothing})] -testRefs' :: String -> [Int] -> [Int] -> Accessor References (M.Map String RefRec) -> String -> Expectation+testRefs' :: T.Text -> [Int] -> [Int] -> Accessor References (M.Map T.Text RefRec) -> T.Text -> Expectation testRefs' p l1 l2 prop res = testRefs (para $ citeGen p l1) (setVal prop (refGen p l1 l2) def) (para $ text res) -testRefs'' :: String -> [Int] -> [(Int, Int)] -> Accessor References (M.Map String RefRec) -> String -> Expectation+testRefs'' :: T.Text -> [Int] -> [(Int, Int)] -> Accessor References (M.Map T.Text RefRec) -> T.Text -> Expectation testRefs'' p l1 l2 prop res = testRefs (para $ citeGen p l1) (setVal prop (refGen' p l1 l2) def) (para $ text res) testAll :: (Eq a, Data a, Show a) => Many a -> (Many a, References) -> Expectation@@ -371,46 +371,46 @@ testList :: Blocks -> References -> Blocks -> Expectation testList bs st res = runState (bottomUpM (References.List.listOf defaultOptions) (toList bs)) st `shouldBe` (toList res,st) -figure :: String -> String -> String -> String -> Blocks+figure :: T.Text -> T.Text -> T.Text -> T.Text -> Blocks figure = (((para .) .) .) . figure' "fig:" -figure' :: String -> String -> String -> String -> String -> Inlines-figure' p src title alt ref = imageWith ("fig:" ++ ref, [], []) src (p ++ title) (text alt)+figure' :: T.Text -> T.Text -> T.Text -> T.Text -> T.Text -> Inlines+figure' p src title alt ref = imageWith ("fig:" <> ref, [], []) src (p <> title) (text alt) -section :: String -> Int -> String -> Blocks-section text' level label = headerWith ("sec:" ++ label,[],[]) level (text text')+section :: T.Text -> Int -> T.Text -> Blocks+section text' level label = headerWith ("sec:" <> label,[],[]) level (text text') -equation :: String -> String -> Blocks+equation :: T.Text -> T.Text -> Blocks equation = (para .) . equation' -equation' :: String -> String -> Inlines+equation' :: T.Text -> T.Text -> Inlines equation' eq ref = displayMath eq <> ref' "eq" ref -table' :: String -> String -> Blocks+table' :: T.Text -> T.Text -> Blocks table' title ref = table (text title <> ref' "tbl" ref) [] [para $ str "H1", para $ str "H2"] [[para $ str "C1", para $ str "C2"]] -codeBlock' :: String -> String -> Blocks+codeBlock' :: T.Text -> T.Text -> Blocks codeBlock' title ref = codeBlockWith- ("lst:"++ref,["haskell"],[("caption",title)]) "main :: IO ()"+ ("lst:"<>ref,["haskell"],[("caption",title)]) "main :: IO ()" -codeBlockForTable :: String -> Blocks+codeBlockForTable :: T.Text -> Blocks codeBlockForTable ref = codeBlockWith- ("lst:"++ref,["haskell"],[]) "main :: IO ()"+ ("lst:"<>ref,["haskell"],[]) "main :: IO ()" -paraText :: String -> Blocks+paraText :: T.Text -> Blocks paraText s = para $ text s -codeBlockDiv :: String -> String -> Blocks-codeBlockDiv title ref = divWith ("lst:"++ref, ["listing","haskell"],[]) $+codeBlockDiv :: T.Text -> T.Text -> Blocks+codeBlockDiv title ref = divWith ("lst:"<>ref, ["listing","haskell"],[]) $ para (text title) <> codeBlockWith ("",["haskell"],[]) "main :: IO ()" -ref' :: String -> String -> Inlines-ref' p n | null n = mempty- | otherwise = space <> str ("{#"++p++":"++n++"}")+ref' :: T.Text -> T.Text -> Inlines+ref' p n | T.null n = mempty+ | otherwise = space <> str ("{#"<>p<>":"<>n<>"}") defaultOptions :: Options defaultOptions = getOptions defaultMeta Nothing@@ -424,7 +424,7 @@ ,citationMode = NormalCitation } -cit :: String -> [Citation]+cit :: T.Text -> [Citation] cit r = [defCit{citationId=r}] infixr 0 =: