aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-07-27 09:19:42 -0600
committerJohn MacFarlane <[email protected]>2023-07-27 09:19:42 -0600
commit340184958545402f687a77c083950c684b2c7e7d (patch)
treeb3f6883f9efd9624fd7678aad1d58c9cca5122f0 /src
parent95140b428bfba339e8806255657a97ec32a33a17 (diff)
SelfContained: Allow units in width and height for svg.
Units are optional but allowed.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/SelfContained.hs19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs
index db2c67bef..a6d893da1 100644
--- a/src/Text/Pandoc/SelfContained.hs
+++ b/src/Text/Pandoc/SelfContained.hs
@@ -23,7 +23,7 @@ import Data.ByteString.Base64 (encodeBase64)
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy as L
import qualified Data.Text as T
-import Data.Char (isAlphaNum, isAscii, isDigit)
+import Data.Char (isAlphaNum, isAscii)
import Data.Digest.Pure.SHA (sha1, showDigest)
import Network.URI (escapeURIString)
import System.FilePath (takeDirectory, takeExtension, (</>))
@@ -213,11 +213,11 @@ combineSvgAttrs svgAttrs imgAttrs =
case (mbViewBox, mbHeight, mbWidth) of
(Nothing, Just h, Just w) -> -- calculate viewBox
combinedAttrs ++ [("viewBox", T.unwords ["0", "0", tshow w, tshow h])]
- (Just (_minx,_miny,width,height), Nothing, Nothing) ->
+ (Just (_minx,_miny,w,h), Nothing, Nothing) ->
combinedAttrs ++
- [ ("width", dropPointZero (tshow width)) |
+ [ ("width", dropPointZero (tshow w)) |
isNothing (lookup "width" combinedAttrs) ] ++
- [ ("height", dropPointZero (tshow height)) |
+ [ ("height", dropPointZero (tshow h)) |
isNothing (lookup "height" combinedAttrs) ]
_ -> combinedAttrs
where
@@ -225,18 +225,9 @@ combineSvgAttrs svgAttrs imgAttrs =
Nothing -> t
Just t' -> t'
combinedAttrs = imgAttrs ++
- [(k,v') | (k,v) <- svgAttrs
- , v' <- fixAttr k v
+ [(k, v) | (k, v) <- svgAttrs
, isNothing (lookup k imgAttrs)
, k `notElem` ["xmlns", "xmlns:xlink", "version"]]
- fixAttr k v =
- if k == "width" || k == "height"
- then if T.all isDigit v
- then [v]
- else case T.stripSuffix "px" v of
- Just v' | T.all isDigit v' -> [v']
- _ -> []
- else [v]
parseViewBox t =
case map (safeRead . addZero) $ T.words t of
[Just llx, Just lly, Just urx, Just ury] -> Just (llx, lly, urx, ury)