git.iko.soy/typeable/pandoc
on master help sign in
Allow compilation with base 4.15
commit105a50569be6d2c1b37cc290abcbfbae1cd0fd1e authorAlbert Krewinkel <albert@zeitkraut.de> dateTue 25 May 2021, 17:49 (5 years ago) parentbb2530c
4 files changed+72−77
src/Text/Pandoc/Options.hs+17−17 src/Text/Pandoc/Readers/Docx/Combine.hs+3−3 src/Text/Pandoc/Readers/Odt/ContentReader.hs+5−6 src/Text/Pandoc/Writers/OpenDocument.hs+47−51
src/Text/Pandoc/Options.hs+17−17
@@ -315,6 +315,23 @@ defaultMathJaxURL = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.j
315315defaultKaTeXURL :: Text
316316defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/"
317317
318+-- Update documentation in doc/filters.md if this is changed.
319+$(deriveJSON defaultOptions{ constructorTagModifier =
320+ camelCaseStrToHyphenated
321+ } ''TrackChanges)
322+
323+$(deriveJSON defaultOptions{ constructorTagModifier =
324+ camelCaseStrToHyphenated
325+ } ''WrapOption)
326+
327+$(deriveJSON defaultOptions{ constructorTagModifier =
328+ camelCaseStrToHyphenated . drop 8
329+ } ''TopLevelDivision)
330+
331+$(deriveJSON defaultOptions{ constructorTagModifier =
332+ camelCaseStrToHyphenated
333+ } ''ReferenceLocation)
334+
318335-- Update documentation in doc/filters.md if this is changed.
319336$(deriveJSON defaultOptions ''ReaderOptions)
320337
@@ -338,20 +355,3 @@ $(deriveJSON defaultOptions{ constructorTagModifier =
338355 } ''ObfuscationMethod)
339356
340357$(deriveJSON defaultOptions ''HTMLSlideVariant)
341−
342−-- Update documentation in doc/filters.md if this is changed.
343−$(deriveJSON defaultOptions{ constructorTagModifier =
344− camelCaseStrToHyphenated
345− } ''TrackChanges)
346−
347−$(deriveJSON defaultOptions{ constructorTagModifier =
348− camelCaseStrToHyphenated
349− } ''WrapOption)
350−
351−$(deriveJSON defaultOptions{ constructorTagModifier =
352− camelCaseStrToHyphenated . drop 8
353− } ''TopLevelDivision)
354−
355−$(deriveJSON defaultOptions{ constructorTagModifier =
356− camelCaseStrToHyphenated
357− } ''ReferenceLocation)
src/Text/Pandoc/Readers/Docx/Combine.hs+3−3
@@ -61,7 +61,7 @@ import Data.List
6161import Data.Bifunctor
6262import Data.Sequence ( ViewL (..), ViewR (..), viewl, viewr, spanr, spanl
6363 , (><), (|>) )
64−import Text.Pandoc.Builder
64+import Text.Pandoc.Builder as B
6565
6666data Modifier a = Modifier (a -> a)
6767 | AttrModifier (Attr -> a -> a) Attr
@@ -116,12 +116,12 @@ ilModifierAndInnards ils = case viewl $ unMany ils of
116116
117117inlinesL :: Inlines -> (Inlines, Inlines)
118118inlinesL ils = case viewl $ unMany ils of
119− (s :< sq) -> (singleton s, Many sq)
119+ (s :< sq) -> (B.singleton s, Many sq)
120120 _ -> (mempty, ils)
121121
122122inlinesR :: Inlines -> (Inlines, Inlines)
123123inlinesR ils = case viewr $ unMany ils of
124− (sq :> s) -> (Many sq, singleton s)
124+ (sq :> s) -> (Many sq, B.singleton s)
125125 _ -> (ils, mempty)
126126
127127combineInlines :: Inlines -> Inlines -> Inlines
src/Text/Pandoc/Readers/Odt/ContentReader.hs+5−6
@@ -1,4 +1,5 @@
11{-# LANGUAGE Arrows #-}
2+{-# LANGUAGE CPP #-}
23{-# LANGUAGE DeriveFoldable #-}
34{-# LANGUAGE GeneralizedNewtypeDeriving #-}
45{-# LANGUAGE PatternGuards #-}
@@ -33,7 +34,7 @@ import Data.List (find)
3334import qualified Data.Map as M
3435import qualified Data.Text as T
3536import Data.Maybe
36−import Data.Semigroup (First(..), Option(..))
37+import Data.Monoid (Alt (..))
3738
3839import Text.TeXMath (readMathML, writeTeX)
3940import qualified Text.Pandoc.XML.Light as XML
@@ -505,13 +506,11 @@ type InlineMatcher = ElementMatcher Inlines
505506
506507type BlockMatcher = ElementMatcher Blocks
507508
508−
509−newtype FirstMatch a = FirstMatch (Option (First a))
510− deriving (Foldable, Monoid, Semigroup)
509+newtype FirstMatch a = FirstMatch (Alt Maybe a)
510+ deriving (Foldable, Monoid, Semigroup)
511511
512512firstMatch :: a -> FirstMatch a
513−firstMatch = FirstMatch . Option . Just . First
514−
513+firstMatch = FirstMatch . Alt . Just
515514
516515--
517516matchingElement :: (Monoid e)
src/Text/Pandoc/Writers/OpenDocument.hs+47−51
@@ -1,4 +1,5 @@
11{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE LambdaCase #-}
23{-# LANGUAGE OverloadedStrings #-}
34{-# LANGUAGE PatternGuards #-}
45{-# LANGUAGE ViewPatterns #-}
@@ -372,36 +373,32 @@ blocksToOpenDocument o b = vcat <$> mapM (blockToOpenDocument o) b
372373
373374-- | Convert a Pandoc block element to OpenDocument.
374375blockToOpenDocument :: PandocMonad m => WriterOptions -> Block -> OD m (Doc Text)
375−blockToOpenDocument o bs
376− | Plain b <- bs = if null b
377− then return empty
378− else inParagraphTags =<< inlinesToOpenDocument o b
379− | Para [Image attr c (s,T.stripPrefix "fig:" -> Just t)] <- bs
380− = figure attr c s t
381− | Para b <- bs = if null b &&
382− not (isEnabled Ext_empty_paragraphs o)
383− then return empty
384− else inParagraphTags =<< inlinesToOpenDocument o b
385− | LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
386− | Div attr xs <- bs = mkDiv attr xs
387− | Header i (ident,_,_) b
388− <- bs = setFirstPara >> (inHeaderTags i ident
389− =<< inlinesToOpenDocument o b)
390− | BlockQuote b <- bs = setFirstPara >> mkBlockQuote b
391− | DefinitionList b <- bs = setFirstPara >> defList b
392− | BulletList b <- bs = setFirstPara >> bulletListToOpenDocument o b
393− | OrderedList a b <- bs = setFirstPara >> orderedList a b
394− | CodeBlock _ s <- bs = setFirstPara >> preformatted s
395− | Table a bc s th tb tf <- bs = setFirstPara >> table (Ann.toTable a bc s th tb tf)
396− | HorizontalRule <- bs = setFirstPara >> return (selfClosingTag "text:p"
397− [ ("text:style-name", "Horizontal_20_Line") ])
398− | RawBlock f s <- bs = if f == Format "opendocument"
399− then return $ text $ T.unpack s
400− else do
401− report $ BlockNotRendered bs
402− return empty
403− | Null <- bs = return empty
404− | otherwise = return empty
376+blockToOpenDocument o = \case
377+ Plain b -> if null b
378+ then return empty
379+ else inParagraphTags =<< inlinesToOpenDocument o b
380+ Para [Image attr c (s,T.stripPrefix "fig:" -> Just t)] -> figure attr c s t
381+ Para b -> if null b &&
382+ not (isEnabled Ext_empty_paragraphs o)
383+ then return empty
384+ else inParagraphTags =<< inlinesToOpenDocument o b
385+ LineBlock b -> blockToOpenDocument o $ linesToPara b
386+ Div attr xs -> mkDiv attr xs
387+ Header i (ident,_,_) b -> do
388+ setFirstPara
389+ inHeaderTags i ident =<< inlinesToOpenDocument o b
390+ BlockQuote b -> setFirstPara >> mkBlockQuote b
391+ DefinitionList b -> setFirstPara >> defList b
392+ BulletList b -> setFirstPara >> bulletListToOpenDocument o b
393+ OrderedList a b -> setFirstPara >> orderedList a b
394+ CodeBlock _ s -> setFirstPara >> preformatted s
395+ Table a bc s th tb tf -> setFirstPara >> table (Ann.toTable a bc s th tb tf)
396+ HorizontalRule -> setFirstPara >> return (selfClosingTag "text:p"
397+ [ ("text:style-name", "Horizontal_20_Line") ])
398+ b@(RawBlock f s) -> if f == Format "opendocument"
399+ then return $ text $ T.unpack s
400+ else empty <$ report (BlockNotRendered b)
401+ Null -> return empty
405402 where
406403 defList b = do setInDefinitionList True
407404 r <- vcat <$> mapM (deflistItemToOpenDocument o) b
@@ -874,27 +871,26 @@ data TextStyle = Italic
874871textStyleAttr :: Map.Map Text Text
875872 -> TextStyle
876873 -> Map.Map Text Text
877−textStyleAttr m s
878− | Italic <- s = Map.insert "fo:font-style" "italic" .
879− Map.insert "style:font-style-asian" "italic" .
880− Map.insert "style:font-style-complex" "italic" $ m
881− | Bold <- s = Map.insert "fo:font-weight" "bold" .
882− Map.insert "style:font-weight-asian" "bold" .
883− Map.insert "style:font-weight-complex" "bold" $ m
884− | Under <- s = Map.insert "style:text-underline-style" "solid" .
885− Map.insert "style:text-underline-width" "auto" .
886− Map.insert "style:text-underline-color" "font-color" $ m
887− | Strike <- s = Map.insert "style:text-line-through-style" "solid" m
888− | Sub <- s = Map.insert "style:text-position" "sub 58%" m
889− | Sup <- s = Map.insert "style:text-position" "super 58%" m
890− | SmallC <- s = Map.insert "fo:font-variant" "small-caps" m
891− | Pre <- s = Map.insert "style:font-name" "Courier New" .
892− Map.insert "style:font-name-asian" "Courier New" .
893− Map.insert "style:font-name-complex" "Courier New" $ m
894− | Language lang <- s
895− = Map.insert "fo:language" (langLanguage lang) .
896− maybe id (Map.insert "fo:country") (langRegion lang) $ m
897− | otherwise = m
874+textStyleAttr m = \case
875+ Italic -> Map.insert "fo:font-style" "italic" .
876+ Map.insert "style:font-style-asian" "italic" .
877+ Map.insert "style:font-style-complex" "italic" $ m
878+ Bold -> Map.insert "fo:font-weight" "bold" .
879+ Map.insert "style:font-weight-asian" "bold" .
880+ Map.insert "style:font-weight-complex" "bold" $ m
881+ Under -> Map.insert "style:text-underline-style" "solid" .
882+ Map.insert "style:text-underline-width" "auto" .
883+ Map.insert "style:text-underline-color" "font-color" $ m
884+ Strike -> Map.insert "style:text-line-through-style" "solid" m
885+ Sub -> Map.insert "style:text-position" "sub 58%" m
886+ Sup -> Map.insert "style:text-position" "super 58%" m
887+ SmallC -> Map.insert "fo:font-variant" "small-caps" m
888+ Pre -> Map.insert "style:font-name" "Courier New" .
889+ Map.insert "style:font-name-asian" "Courier New" .
890+ Map.insert "style:font-name-complex" "Courier New" $ m
891+ Language lang ->
892+ Map.insert "fo:language" (langLanguage lang) .
893+ maybe id (Map.insert "fo:country") (langRegion lang) $ m
898894
899895withLangFromAttr :: PandocMonad m => Attr -> OD m a -> OD m a
900896withLangFromAttr (_,_,kvs) action =