From 60989d0637780787fb337b94af212f1ee9e1ae22 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Mon, 15 Jan 2007 19:52:42 +0000 Subject: Added support for tables in markdown reader and in LaTeX, DocBook, and HTML writers. The syntax is documented in README. Tests have been added to the test suite. git-svn-id: https://pandoc.googlecode.com/svn/trunk@493 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Shared.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Text/Pandoc/Shared.hs') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 624f573de..8ee990827 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -30,6 +30,7 @@ Utility functions and definitions used by the various Pandoc modules. module Text.Pandoc.Shared ( -- * List processing splitBy, + splitByIndices, -- * Text processing gsub, joinWithSep, @@ -133,6 +134,8 @@ data ParserState = ParserState stateDate :: String, -- ^ Date of document stateStrict :: Bool, -- ^ Use strict markdown syntax stateSmart :: Bool, -- ^ Use smart typography + stateColumns :: Int, -- ^ Number of columns in + -- terminal (used for tables) stateHeaderTable :: [HeaderType] -- ^ List of header types used, -- in what order (rst only) } @@ -154,6 +157,7 @@ defaultParserState = stateDate = [], stateStrict = False, stateSmart = False, + stateColumns = 80, stateHeaderTable = [] } -- | Indent string as a block. @@ -292,6 +296,13 @@ splitBy sep lst = rest' = dropWhile (== sep) rest in first:(splitBy sep rest') +-- | Split list into chunks divided at specified indices. +splitByIndices :: [Int] -> [a] -> [[a]] +splitByIndices [] lst = [lst] +splitByIndices (x:xs) lst = + let (first, rest) = splitAt x lst in + first:(splitByIndices (map (\y -> y - x) xs) rest) + -- | Normalize a list of inline elements: remove leading and trailing -- @Space@ elements, and collapse double @Space@s into singles. normalizeSpaces :: [Inline] -> [Inline] -- cgit v1.2.3