git.iko.soy/typeable/pandoc
on master help sign in
Revert "HTML reader: simplify col width parsing"

This reverts commit f76fe2ab56606528d4710cc6c40bceb5788c3906.

commit80b4b3fe82a19a4ea1e76fc4a81c9c88676c7ce0 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 22 May 2021, 22:03 (5 years ago) parentf76fe2a
1 file changed+13−9
src/Text/Pandoc/Readers/HTML/Table.hs+13−9
src/Text/Pandoc/Readers/HTML/Table.hs+13−9
@@ -1,5 +1,6 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE ViewPatterns #-}
34{- |
45 Module : Text.Pandoc.Readers.HTML.Table
56 Copyright : © 2006-2021 John MacFarlane,
@@ -41,15 +42,18 @@ pCol = try $ do
4142 skipMany pBlank
4243 optional $ pSatisfy (matchTagClose "col")
4344 skipMany pBlank
44− let toColWidth = maybe ColWidthDefault (ColWidth . (/100.0)) . safeRead
45− return $ fromMaybe ColWidthDefault $
46− (case lookup "width" attribs >>= T.unsnoc of
47− Just (xs, '%') -> Just (toColWidth xs)
48− _ -> Nothing) <|>
49− (case lookup "style" attribs >>= T.stripPrefix "width" of
50− Just xs | T.any (== '%') xs -> Just . toColWidth $
51− T.filter (`notElem` (" \t\r\n%'\";" :: [Char])) xs
52− _ -> Nothing)
45+ let width = case lookup "width" attribs of
46+ Nothing -> case lookup "style" attribs of
47+ Just (T.stripPrefix "width:" -> Just xs) | T.any (== '%') xs ->
48+ fromMaybe 0.0 $ safeRead (T.filter
49+ (`notElem` (" \t\r\n%'\";" :: [Char])) xs)
50+ _ -> 0.0
51+ Just (T.unsnoc -> Just (xs, '%')) ->
52+ fromMaybe 0.0 $ safeRead xs
53+ _ -> 0.0
54+ if width > 0.0
55+ then return $ ColWidth $ width / 100.0
56+ else return ColWidthDefault
5357
5458pColgroup :: PandocMonad m => TagParser m [ColWidth]
5559pColgroup = try $ do