diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-09-20 11:55:59 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-09-20 11:55:59 -0700 |
| commit | 26d077fa21014327ebc4ce3166f1cb8494478b6a (patch) | |
| tree | ede67e3b9fdff60ee7ee683fe83f4b973596b693 /src | |
| parent | e57953b9f04cd05607eb1b75fd9fb194d48feb0a (diff) | |
T.P.Shared: add addPandocAttributes function.
[API change]
This is meant to simplify addition of attributes to Pandoc
elements; for elements that don't have a slot for attributes,
an enclosing Div or Span is added to hold the attributes.
Ideally this would live in pandoc-types, but for now we
reuse some code from commonmark-pandoc.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Shared.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 125701a83..92269ddec 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -38,6 +38,7 @@ module Text.Pandoc.Shared ( -- * Date/time normalizeDate, -- * Pandoc block and inline list processing + addPandocAttributes, orderedListMarkers, extractSpaces, removeFormatting, @@ -113,6 +114,9 @@ import Text.Pandoc.Extensions (Extensions, Extension(..), extensionEnabled) import Text.Pandoc.Generic (bottomUp) import Text.DocLayout (charWidth) import Text.Pandoc.Walk +-- for addPandocAttributes: +import Commonmark.Pandoc (Cm(..)) +import Commonmark (HasAttributes(..)) -- -- List processing @@ -288,6 +292,14 @@ normalizeDate' s = fmap (formatTime defaultTimeLocale "%F") -- Pandoc block and inline list processing -- +-- | Add key-value attributes to a pandoc element. If the element +-- does not have a slot for attributes, create an enclosing Span +-- (for Inlines) or Div (for Blocks). Note that both 'Cm () Inlines' +-- and 'Cm () Blocks' are instances of 'HasAttributes'. +addPandocAttributes + :: forall b . HasAttributes (Cm () b) => [(T.Text, T.Text)] -> b -> b +addPandocAttributes kvs bs = unCm . addAttributes kvs $ (Cm bs :: Cm () b) + -- | Generate infinite lazy list of markers for an ordered list, -- depending on list attributes. orderedListMarkers :: (Int, ListNumberStyle, ListNumberDelim) -> [T.Text] |
