@@ -29,7 +29,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2929Shared utility functions for pandoc writers.
3030-}
3131module Text.Pandoc.Writers.Shared (
32− metaToJSON
32+ getLang
33+ , metaToJSON
3334 , metaToJSON'
3435 , addVariablesToJSON
3536 , getField
@@ -42,7 +43,7 @@ module Text.Pandoc.Writers.Shared (
4243 , gridTable
4344 )
4445where
45−import Control.Monad (liftM, zipWithM)
46+import Control.Monad (liftM, zipWithM, mplus)
4647import Data.Aeson (FromJSON (..), Result (..), ToJSON (..), Value (Object),
4748 encode, fromJSON)
4849import qualified Data.HashMap.Strict as H
@@ -57,6 +58,16 @@ import Text.Pandoc.Pretty
5758import Text.Pandoc.UTF8 (toStringLazy)
5859import Text.Pandoc.XML (escapeStringForXML)
5960
61+-- | Get the contents of the `lang` metadata field or variable.
62+getLang :: WriterOptions -> Meta -> Maybe String
63+getLang opts meta =
64+ lookup "lang" (writerVariables opts)
65+ `mplus`
66+ case lookupMeta "lang" meta of
67+ Just (MetaInlines [Str s]) -> Just s
68+ Just (MetaString s) -> Just s
69+ _ -> Nothing
70+
6071-- | Create JSON value for template from a 'Meta' and an association list
6172-- of variables, specified at the command line or in the writer.
6273-- Variables overwrite metadata fields with the same names.