diff options
| author | Albert Krewinkel <[email protected]> | 2022-01-21 17:59:14 +0100 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2022-01-29 22:36:22 +0100 |
| commit | fbb9fbf9bb0bf5e52211ffd9b67a2be7c29edce7 (patch) | |
| tree | b110da515f48e0f533a41c193a636084864c34db | |
| parent | 412596c30baec47041ccb3b1823f9beca7c98d76 (diff) | |
Custom writer: preserve order of element attributes
Attribute key-value pairs are marshaled as AttributeList, i.e., as a
userdata type that behaves both like a list and a map. This allows to
preserve the order of key-value pairs.
Closes: #7489
| -rw-r--r-- | src/Text/Pandoc/Writers/Custom.hs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/Custom.hs b/src/Text/Pandoc/Writers/Custom.hs index 70c03a016..52ae33c35 100644 --- a/src/Text/Pandoc/Writers/Custom.hs +++ b/src/Text/Pandoc/Writers/Custom.hs @@ -21,7 +21,6 @@ import Control.Arrow ((***)) import Control.Exception import Control.Monad (when) import Data.List (intersperse) -import qualified Data.Map as M import Data.Maybe (fromMaybe) import qualified Data.Text as T import Data.Text (Text, pack) @@ -32,13 +31,20 @@ import Text.DocTemplates (Context) import Control.Monad.IO.Class (MonadIO) import Text.Pandoc.Definition import Text.Pandoc.Lua (Global (..), runLua, setGlobals) +import Text.Pandoc.Lua.Marshal.Attr (pushAttributeList) import Text.Pandoc.Options import Text.Pandoc.Class (PandocMonad) import Text.Pandoc.Templates (renderTemplate) import Text.Pandoc.Writers.Shared -attrToMap :: Attr -> M.Map T.Text T.Text -attrToMap (id',classes,keyvals) = M.fromList +-- | List of key-value pairs that is pushed to Lua as AttributeList +-- userdata. +newtype AttributeList = AttributeList [(Text, Text)] +instance Pushable AttributeList where + push (AttributeList kvs) = pushAttributeList kvs + +attrToMap :: Attr -> AttributeList +attrToMap (id',classes,keyvals) = AttributeList $ ("id", id') : ("class", T.unwords classes) : keyvals |
