diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2018-10-03 17:36:52 -0700 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2018-10-03 17:36:52 -0700 | 
| commit | 58ae017075cc9dbaacce85866b6fc04a02fa1ab4 (patch) | |
| tree | 1c61eecfa1e88d64d1cd40f45574a7a71f6d77ad /src/Text/Pandoc/Writers | |
| parent | d7263a7e5fb1ba53465099c6f1be7a85e05564f8 (diff) | |
| download | pandoc-58ae017075cc9dbaacce85866b6fc04a02fa1ab4.tar.gz | |
OpenDocument writer: make 'Figure' term sensitive to `lang` in metadata.
We use the new translations API.
Diffstat (limited to 'src/Text/Pandoc/Writers')
| -rw-r--r-- | src/Text/Pandoc/Writers/OpenDocument.hs | 25 | 
1 files changed, 16 insertions, 9 deletions
| diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index cd907bbea..e3d7f2e5c 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -39,17 +39,20 @@ import Control.Monad.State.Strict hiding (when)  import Data.Char (chr)  import Data.List (sortBy)  import qualified Data.Map as Map +import Data.Maybe (fromMaybe)  import Data.Ord (comparing)  import qualified Data.Set as Set  import Data.Text (Text)  import Text.Pandoc.BCP47 (Lang (..), parseBCP47) -import Text.Pandoc.Class (PandocMonad, report) +import Text.Pandoc.Class (PandocMonad, report, translateTerm, +                          setTranslations, toLang)  import Text.Pandoc.Definition  import Text.Pandoc.Logging  import Text.Pandoc.Options  import Text.Pandoc.Pretty  import Text.Pandoc.Shared (linesToPara)  import Text.Pandoc.Templates (renderTemplate') +import Text.Pandoc.Translations (Term(Figure))  import Text.Pandoc.Writers.Math  import Text.Pandoc.Writers.Shared  import Text.Pandoc.XML @@ -223,6 +226,9 @@ handleSpaces s  -- | Convert Pandoc document to string in OpenDocument format.  writeOpenDocument :: PandocMonad m => WriterOptions -> Pandoc -> m Text  writeOpenDocument opts (Pandoc meta blocks) = do +  lang <- fromMaybe (Lang "en" "US" "" []) <$> +                toLang (metaValueToString <$> lookupMeta "lang" meta) +  setTranslations lang    let colwidth = if writerWrapText opts == WrapAuto                      then Just $ writerColumns opts                      else Nothing @@ -413,19 +419,20 @@ blockToOpenDocument o bs                                    | otherwise    = do          id' <- gets stImageId          imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image attr caption (source,title)]] -        captionDoc <- numberedFigureCaption id' <$> inlinesToOpenDocument o caption +        captionDoc <- inlinesToOpenDocument o caption >>= numberedFigureCaption id'          return $ imageDoc $$ captionDoc -numberedFigureCaption :: Int -> Doc -> Doc -numberedFigureCaption num caption = -    let t = text "Figure " -        r = num - 1 -        s = inTags False "text:sequence" [ ("text:ref-name", "refIllustration" ++ show r), +numberedFigureCaption :: PandocMonad m => Int -> Doc -> OD m Doc +numberedFigureCaption num caption = do +    figterm <- translateTerm Figure +    let t = text figterm +    let r = num - 1 +    let s = inTags False "text:sequence" [ ("text:ref-name", "refIllustration" ++ show r),                                             ("text:name", "Illustration"),                                             ("text:formula", "ooow:Illustration+1"),                                             ("style:num-format", "1") ] $ text $ show num -        c = text ": " -    in inParagraphTagsWithStyle "FigureCaption" $ hcat [ t, s, c, caption ] +    let c = text ": " +    return $ inParagraphTagsWithStyle "FigureCaption" $ hcat [ t, text " ", s, c, caption ]  colHeadsToOpenDocument :: PandocMonad m                         => WriterOptions -> [String] -> [[Block]] | 
