diff options
author | Mauro Bieg <mb21@users.noreply.github.com> | 2019-01-02 20:36:37 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-01-02 11:36:37 -0800 |
commit | f1d83aea12b93b31f5218bed75bd0e9d8d373cb6 (patch) | |
tree | ee6606c10b3790213c553f9fe6b5ea519f1a8dce /src/Text/Pandoc/Shared.hs | |
parent | 9097ec41a9c333f24fec63085806da392f8108d4 (diff) | |
download | pandoc-f1d83aea12b93b31f5218bed75bd0e9d8d373cb6.tar.gz |
Implement task lists (#5139)
Closes #3051
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 9fa083c11..4efdbba61 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -79,6 +79,8 @@ module Text.Pandoc.Shared ( headerShift, stripEmptyParagraphs, isTightList, + taskListItemFromAscii, + taskListItemToAscii, addMetaField, makeMeta, eastAsianLineBreakFilter, @@ -588,6 +590,36 @@ isTightList = all firstIsPlain where firstIsPlain (Plain _ : _) = True firstIsPlain _ = False +-- | Convert a list item containing tasklist syntax (e.g. @[x]@) +-- to using @U+2610 BALLOT BOX@ or @U+2612 BALLOT BOX WITH X@. +taskListItemFromAscii :: Extensions -> [Block] -> [Block] +taskListItemFromAscii = handleTaskListItem fromMd + where + fromMd (Str "[" : Space : Str "]" : Space : is) = (Str "☐") : Space : is + fromMd (Str "[x]" : Space : is) = (Str "☒") : Space : is + fromMd (Str "[X]" : Space : is) = (Str "☒") : Space : is + fromMd is = is + +-- | Convert a list item containing text starting with @U+2610 BALLOT BOX@ +-- or @U+2612 BALLOT BOX WITH X@ to tasklist syntax (e.g. @[x]@). +taskListItemToAscii :: Extensions -> [Block] -> [Block] +taskListItemToAscii = handleTaskListItem toMd + where + toMd (Str "☐" : Space : is) = rawMd "[ ]" : Space : is + toMd (Str "☒" : Space : is) = rawMd "[x]" : Space : is + toMd is = is + rawMd = RawInline (Format "markdown") + +handleTaskListItem :: ([Inline] -> [Inline]) -> Extensions -> [Block] -> [Block] +handleTaskListItem handleInlines exts bls = + if Ext_task_lists `extensionEnabled` exts + then handleItem bls + else bls + where + handleItem (Plain is : bs) = Plain (handleInlines is) : bs + handleItem (Para is : bs) = Para (handleInlines is) : bs + handleItem bs = bs + -- | Set a field of a 'Meta' object. If the field already has a value, -- convert it into a list with the new value appended to the old value(s). addMetaField :: ToMetaValue a |