diff options
author | Mauro Bieg <mb21@users.noreply.github.com> | 2019-05-27 19:53:19 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-05-27 13:53:19 -0400 |
commit | d07ed83d705df491bba7b295bd5e80629d971685 (patch) | |
tree | 3964c08ea82627577df4b3c843f19e6a0d7ca977 /src/Text/Pandoc/Shared.hs | |
parent | f807f5b3833e841d9e6b831acbe50f3be8e42881 (diff) | |
download | pandoc-d07ed83d705df491bba7b295bd5e80629d971685.tar.gz |
consolidate simple-table detection (#5524)
add `onlySimpleTableCells` to `Text.Pandoc.Shared`
[API change]
This fixes an inconsistency in the HTML reader, which did not treat tables with `<p>` inside cells as simple.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 8aaa362cd..2fb9cbac3 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -59,6 +59,7 @@ module Text.Pandoc.Shared ( isHeaderBlock, headerShift, stripEmptyParagraphs, + onlySimpleTableCells, isTightList, taskListItemFromAscii, taskListItemToAscii, @@ -108,6 +109,7 @@ import Data.List (find, intercalate, intersperse, stripPrefix, sortBy) import Data.Ord (comparing) import qualified Data.Map as M import Data.Maybe (mapMaybe) +import Data.Monoid (Any (..)) import Data.Sequence (ViewL (..), ViewR (..), viewl, viewr) import qualified Data.Set as Set import qualified Data.Text as T @@ -571,6 +573,19 @@ stripEmptyParagraphs = walk go isEmptyParagraph (Para []) = True isEmptyParagraph _ = False +-- | Detect if table rows contain only cells consisting of a single +-- paragraph that has no @LineBreak@. +onlySimpleTableCells :: [[TableCell]] -> Bool +onlySimpleTableCells = all isSimpleCell . concat + where + isSimpleCell [Plain ils] = not (hasLineBreak ils) + isSimpleCell [Para ils ] = not (hasLineBreak ils) + isSimpleCell [] = True + isSimpleCell _ = False + hasLineBreak = getAny . query isLineBreak + isLineBreak LineBreak = Any True + isLineBreak _ = Any False + -- | Detect if a list is tight. isTightList :: [[Block]] -> Bool isTightList = all firstIsPlain |