summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-25 10:37:49 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-06-25 10:37:49 +0200
commit87e6235fe73fef3fd6bc6e374c9372b2254d2764 (patch)
treee6a1ad1194ae98d17386de2d996989598438f09e /src/Text/Pandoc/Writers/Shared.hs
parent3b3ae54a39ab5df878d29f1f4d333ae36fe335d2 (diff)
Text.Pandoc.Writers.Shared: added getLang.
Diffstat (limited to 'src/Text/Pandoc/Writers/Shared.hs')
-rw-r--r--src/Text/Pandoc/Writers/Shared.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Shared.hs b/src/Text/Pandoc/Writers/Shared.hs
index 2047285eb..6f7c9f75c 100644
--- a/src/Text/Pandoc/Writers/Shared.hs
+++ b/src/Text/Pandoc/Writers/Shared.hs
@@ -29,7 +29,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Shared utility functions for pandoc writers.
-}
module Text.Pandoc.Writers.Shared (
- metaToJSON
+ getLang
+ , metaToJSON
, metaToJSON'
, addVariablesToJSON
, getField
@@ -42,7 +43,7 @@ module Text.Pandoc.Writers.Shared (
, gridTable
)
where
-import Control.Monad (liftM, zipWithM)
+import Control.Monad (liftM, zipWithM, mplus)
import Data.Aeson (FromJSON (..), Result (..), ToJSON (..), Value (Object),
encode, fromJSON)
import qualified Data.HashMap.Strict as H
@@ -57,6 +58,16 @@ import Text.Pandoc.Pretty
import Text.Pandoc.UTF8 (toStringLazy)
import Text.Pandoc.XML (escapeStringForXML)
+-- | Get the contents of the `lang` metadata field or variable.
+getLang :: WriterOptions -> Meta -> Maybe String
+getLang opts meta =
+ lookup "lang" (writerVariables opts)
+ `mplus`
+ case lookupMeta "lang" meta of
+ Just (MetaInlines [Str s]) -> Just s
+ Just (MetaString s) -> Just s
+ _ -> Nothing
+
-- | Create JSON value for template from a 'Meta' and an association list
-- of variables, specified at the command line or in the writer.
-- Variables overwrite metadata fields with the same names.