diff options
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 37 | ||||
| -rw-r--r-- | test/writer.typst | 4 |
2 files changed, 11 insertions, 30 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 diff --git a/test/writer.typst b/test/writer.typst index 3367ee602..6fcf3abe5 100644 --- a/test/writer.typst +++ b/test/writer.typst @@ -784,14 +784,14 @@ or here: <http://example.com/> <images> From "Voyage dans la Lune" by Georges Melies (1902): -#figure([#box(width: 150.0pt, image("lalune.jpg"));], +#figure([#box(image("lalune.jpg"))], caption: [ lalune ], kind: auto ) -Here is a movie #box(width: 20.0pt, image("movie.jpg")) icon. +Here is a movie #box(image("movie.jpg")) icon. #horizontalrule |
