summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-07 15:21:01 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-12-07 15:21:01 +0100
commit7ce622475c948af3498a287e9de6124c95f0f3ff (patch)
tree7eb9c9a44260abe5c84f9f0b77f0d4a2a83f1e3c /src
parent65c0e527f83b200956eea1b31321f2a28e7cd548 (diff)
HTML reader: Understand `style=width:` as well as `width` in `col`.
Closes #3286.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/HTML.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index 0e7a33fe9..db3295e59 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -69,6 +69,7 @@ import Text.Pandoc.CSS (foldOrElse, pickStyleAttrProps)
import Data.Monoid ((<>))
import Text.Parsec.Error
import qualified Data.Set as Set
+import Debug.Trace (traceShowId)
-- | Convert HTML-formatted string to 'Pandoc' document.
readHtml :: ReaderOptions -- ^ Reader options
@@ -422,7 +423,6 @@ pTable = try $ do
TagOpen _ _ <- pSatisfy (~== TagOpen "table" [])
skipMany pBlank
caption <- option mempty $ pInTags "caption" inline <* skipMany pBlank
- -- TODO actually read these and take width information from them
widths' <- (mconcat <$> many1 pColgroup) <|> many pCol
let pTh = option [] $ pInTags "tr" (pCell "th")
pTr = try $ skipMany pBlank >> pInTags "tr" (pCell "td" <|> pCell "th")
@@ -450,7 +450,7 @@ pTable = try $ do
| otherwise -> r
let rows = map addEmpties rows''
let aligns = replicate cols AlignDefault
- let widths = if null widths'
+ let widths = if null (traceShowId widths')
then if isSimple
then replicate cols 0
else replicate cols (1.0 / fromIntegral cols)
@@ -464,6 +464,11 @@ pCol = try $ do
optional $ pSatisfy (~== TagClose "col")
skipMany pBlank
return $ case lookup "width" attribs of
+ Nothing -> case lookup "style" attribs of
+ Just ('w':'i':'d':'t':'h':':':xs) | '%' `elem` xs ->
+ fromMaybe 0.0 $ safeRead ('0':'.':filter
+ (`notElem` " \t\r\n%'\";") xs)
+ _ -> 0.0
Just x | not (null x) && last x == '%' ->
fromMaybe 0.0 $ safeRead ('0':'.':init x)
_ -> 0.0