@@ -1,6 +1,7 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2−{-# LANGUAGE RecordWildCards #-}
2+{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE RecordWildCards #-}
5 Module : Text.Pandoc.Readers.Org.Blocks
6 Module : Text.Pandoc.Readers.Org.Blocks
6 Copyright : Copyright (C) 2014-2021 Albert Krewinkel
7 Copyright : Copyright (C) 2014-2021 Albert Krewinkel
@@ -850,16 +851,52 @@ definitionListItem parseIndentedMarker = try $ do
850 definitionMarker =
851 definitionMarker =
851 spaceChar *> string "::" <* (spaceChar <|> lookAhead newline)
852 spaceChar *> string "::" <* (spaceChar <|> lookAhead newline)
854+-- | Checkbox for tasks.
860+-- | Parses a checkbox in a plain list.
861+checkbox :: PandocMonad m
862+ => OrgParser m Checkbox
864+ guardEnabled Ext_task_lists
865+ try (char '[' *> status <* char ']') <?> "checkbox"
868+ [ UncheckedBox <$ char ' '
869+ , CheckedBox <$ char 'X'
870+ , SemicheckedBox <$ char '-'
873+checkboxToInlines :: Checkbox -> Inline
874+checkboxToInlines = B.Str . \case
876+ SemicheckedBox -> "☐"
853-- | parse raw text for one list item
879-- | parse raw text for one list item
854listItem :: PandocMonad m
880listItem :: PandocMonad m
855 => OrgParser m Int
881 => OrgParser m Int
856 -> OrgParser m (F Blocks)
882 -> OrgParser m (F Blocks)
857listItem parseIndentedMarker = try . withContext ListItemState $ do
883listItem parseIndentedMarker = try . withContext ListItemState $ do
858 markerLength <- try parseIndentedMarker
884 markerLength <- try parseIndentedMarker
885+ box <- optionMaybe checkbox
859 firstLine <- anyLineNewline
886 firstLine <- anyLineNewline
860 blank <- option "" ("\n" <$ blankline)
887 blank <- option "" ("\n" <$ blankline)
861 rest <- T.concat <$> many (listContinuation markerLength)
888 rest <- T.concat <$> many (listContinuation markerLength)
862− parseFromString blocks $ firstLine <> blank <> rest
889+ contents <- parseFromString blocks $ firstLine <> blank <> rest
890+ return (maybe id (prependInlines . checkboxToInlines) box <$> contents)
892+-- | Prepend inlines to blocks, adding them to the first paragraph or
893+-- creating a new Plain element if necessary.
894+prependInlines :: Inline -> Blocks -> Blocks
895+prependInlines inlns = B.fromList . prepend . B.toList
897+ prepend (Plain is : bs) = Plain (inlns : Space : is) : bs
898+ prepend (Para is : bs) = Para (inlns : Space : is) : bs
899+ prepend bs = Plain [inlns, Space] : bs
864-- continuation of a list item - indented and separated by blankline or endline.
901-- continuation of a list item - indented and separated by blankline or endline.
865-- Note: nested lists are parsed as continuations.
902-- Note: nested lists are parsed as continuations.