summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs37
1 files changed, 9 insertions, 28 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
index 007e0881e..ce2f2d8f0 100644
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -17,8 +17,7 @@ module Text.Pandoc.Writers.Typst (
writeTypst
) where
import Text.Pandoc.Definition
-import Text.Pandoc.Class ( PandocMonad, fetchItem )
-import Text.Pandoc.ImageSize (imageSize, sizeInPoints)
+import Text.Pandoc.Class ( PandocMonad)
import Text.Pandoc.Options ( WriterOptions(..), WrapOption(..), isEnabled )
import Data.Text (Text)
import Data.List (intercalate)
@@ -32,7 +31,6 @@ import Text.Pandoc.Writers.Math (convertMath)
import qualified Text.TeXMath as TM
import Text.DocLayout
import Text.DocTemplates (renderTemplate)
-import Control.Monad.Except (catchError)
import Text.Pandoc.Extensions (Extension(..))
import Text.Collate.Lang (Lang(..), parseLang)
import Data.Char (isAlphaNum)
@@ -307,32 +305,15 @@ inlineToTypst inline =
then mempty
else nowrap $ brackets contents) <> endCode
Image (_,_,kvs) _inlines (src,_tit) -> do
- opts <- gets stOptions
- let mbHeight = lookup "height" kvs
- let mdWidth = lookup "width" kvs
let src' = T.pack $ unEscapeString $ T.unpack src -- #9389
- let coreImage = "image" <> parens (doubleQuoted src')
- -- see #9104; we need a box or the image is treated as block-level:
- case (mdWidth, mbHeight) of
- (Nothing, Nothing) -> do
- realWidth <- catchError
- (do (bs, _mt) <- fetchItem src
- case imageSize opts bs of
- Right x -> pure $ Just $ T.pack $
- show (fst (sizeInPoints x)) <> "pt"
- Left _ -> pure Nothing)
- (\_ -> pure Nothing)
- case realWidth of
- Just w -> return $ "#box" <>
- parens ("width: " <> literal w <> ", " <> coreImage)
- <> endCode
- Nothing -> return $ "#" <> coreImage <> endCode
- (Just w, _) -> return $ "#box" <>
- parens ("width: " <> literal w <> ", " <> coreImage)
- <> endCode
- (_, Just h) -> return $ "#box" <>
- parens ("height: " <> literal h <> ", " <> coreImage)
- <> endCode
+ let toDimAttr k =
+ case lookup k kvs of
+ Just v -> ", " <> literal k <> ": " <> literal v
+ Nothing -> mempty
+ let dimAttrs = mconcat $ map toDimAttr ["height", "width"]
+ pure $ "#box" <> -- see #9104; need box or image is treated as block-level
+ parens ("image" <>
+ parens (doubleQuoted src' <> dimAttrs))
Note blocks -> do
contents <- blocksToTypst blocks
return $ "#footnote" <> brackets (chomp contents) <> endCode