@@ -47,7 +47,7 @@ import Text.Pandoc.Builder
4747import Control.Applicative ((<|>), many, optional)
4848import Data.Maybe (fromMaybe, maybeToList)
4949import System.FilePath (replaceExtension, takeExtension, addExtension)
50−import Data.List (intercalate)
50+import Data.List (intercalate, unzip3)
5151import qualified Data.Map as M
5252import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
5353import Text.Pandoc.ImageSize (numUnit, showFl)
@@ -1324,7 +1324,7 @@ complexNatbibCitation mode = try $ do
13241324
13251325-- tables
13261326
1327−parseAligns :: PandocMonad m => LP m [Alignment]
1327+parseAligns :: PandocMonad m => LP m [(String, Alignment, String)]
13281328parseAligns = try $ do
13291329 char '{'
13301330 let maybeBar = skipMany $ sp <|> () <$ char '|' <|> () <$ (char '@' >> braced)
@@ -1334,11 +1334,21 @@ parseAligns = try $ do
13341334 let rAlign = AlignRight <$ char 'r'
13351335 let parAlign = AlignLeft <$ (char 'p' >> braced)
13361336 let alignChar = cAlign <|> lAlign <|> rAlign <|> parAlign
1337− aligns' <- sepEndBy alignChar maybeBar
1337+ let alignPrefix = char '>' >> braced
1338+ let alignSuffix = char '<' >> braced
1339+ let alignSpec = do
1340+ spaces
1341+ pref <- option "" alignPrefix
1342+ spaces
1343+ ch <- alignChar
1344+ spaces
1345+ suff <- option "" alignSuffix
1346+ return (pref, ch, suff)
1347+ aligns' <- sepEndBy alignSpec maybeBar
13381348 spaces
13391349 char '}'
13401350 spaces
1341− return aligns'
1351+ return $ aligns'
13421352
13431353hline :: PandocMonad m => LP m ()
13441354hline = try $ do
@@ -1362,16 +1372,25 @@ lbreak = () <$ try (spaces' *>
13621372amp :: PandocMonad m => LP m ()
13631373amp = () <$ try (spaces' *> char '&' <* spaces')
13641374
1365−parseTableRow :: PandocMonad m => Int -- ^ number of columns
1375+parseTableRow :: PandocMonad m
1376+ => Int -- ^ number of columns
1377+ -> [String] -- ^ prefixes
1378+ -> [String] -- ^ suffixes
13661379 -> LP m [Blocks]
1367−parseTableRow cols = try $ do
1368− let tableCellInline = notFollowedBy (amp <|> lbreak) >> inline
1380+parseTableRow cols prefixes suffixes = try $ do
1381+ let tableCellRaw = many (notFollowedBy
1382+ (amp <|> lbreak <|>
1383+ (() <$ try (string "\\end"))) >> anyChar)
13691384 let minipage = try $ controlSeq "begin" *> string "{minipage}" *>
13701385 env "minipage"
13711386 (skipopts *> spaces' *> optional braced *> spaces' *> blocks)
13721387 let tableCell = minipage <|>
1373− ((plain . trimInlines . mconcat) <$> many tableCellInline)
1374− cells' <- sepBy1 tableCell amp
1388+ ((plain . trimInlines . mconcat) <$> many inline)
1389+ rawcells <- sepBy1 tableCellRaw amp
1390+ guard $ length rawcells == cols
1391+ let rawcells' = zipWith3 (\c p s -> p ++ trim c ++ s)
1392+ rawcells prefixes suffixes
1393+ cells' <- mapM (parseFromString tableCell) rawcells'
13751394 let numcells = length cells'
13761395 guard $ numcells <= cols && numcells >= 1
13771396 guard $ cells' /= [mempty]
@@ -1387,16 +1406,18 @@ simpTable :: PandocMonad m => Bool -> LP m Blocks
13871406simpTable hasWidthParameter = try $ do
13881407 when hasWidthParameter $ () <$ (spaces' >> tok)
13891408 skipopts
1390− aligns <- parseAligns
1409+ (prefixes, aligns, suffixes) <- unzip3 <$> parseAligns
13911410 let cols = length aligns
13921411 optional $ controlSeq "caption" *> skipopts *> setCaption
13931412 optional lbreak
13941413 spaces'
13951414 skipMany hline
13961415 spaces'
1397− header' <- option [] $ try (parseTableRow cols <* lbreak <* many1 hline)
1416+ header' <- option [] $ try (parseTableRow cols prefixes suffixes <*
1417+ lbreak <* many1 hline)
13981418 spaces'
1399− rows <- sepEndBy (parseTableRow cols) (lbreak <* optional (skipMany hline))
1419+ rows <- sepEndBy (parseTableRow cols prefixes suffixes)
1420+ (lbreak <* optional (skipMany hline))
14001421 spaces'
14011422 optional $ controlSeq "caption" *> skipopts *> setCaption
14021423 optional lbreak