diff options
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 23 | ||||
| -rw-r--r-- | test/writer.typst | 60 |
2 files changed, 46 insertions, 37 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index 0a598cb37..5847f411e 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -243,8 +243,9 @@ inlineToTypst inline = Code (_,cls,_) code -> return $ case cls of (lang:_) -> "#raw(lang:" <> doubleQuoted lang <> - ", " <> doubleQuoted code <> ")" + ", " <> doubleQuoted code <> ")" <> endCode _ | T.any (=='`') code -> "#raw(" <> doubleQuoted code <> ")" + <> endCode | otherwise -> "`" <> literal code <> "`" RawInline fmt str -> case fmt of @@ -273,6 +274,7 @@ inlineToTypst inline = [] -> pure mempty suff -> brackets <$> inlinesToTypst suff pure $ "#cite" <> parens (toLabel (citationId cite)) <> suppl + <> endCode if isEnabled Ext_citations opts -- Note: this loses prefix then mconcat <$> mapM toCite citations @@ -283,9 +285,9 @@ inlineToTypst inline = Just ('#', ident) -> "<" <> literal ident <> ">" _ -> doubleQuoted src return $ "#link" <> parens dest <> - if inlines == [Str src] - then mempty - else nowrap $ brackets contents + (if inlines == [Str src] + then mempty + else nowrap $ brackets contents) <> endCode Image (_,_,kvs) _inlines (src,_tit) -> do opts <- gets stOptions let mbHeight = lookup "height" kvs @@ -304,17 +306,21 @@ inlineToTypst inline = case realWidth of Just w -> return $ "#box" <> parens ("width: " <> literal w <> ", " <> coreImage) - Nothing -> return $ "#" <> 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 Note blocks -> do contents <- blocksToTypst blocks - return $ "#footnote" <> brackets (chomp contents) + return $ "#footnote" <> brackets (chomp contents) <> endCode textstyle :: PandocMonad m => Doc Text -> [Inline] -> TW m (Doc Text) -textstyle s inlines = (s <>) . brackets <$> inlinesToTypst inlines +textstyle s inlines = + (<> endCode) . (s <>) . brackets <$> inlinesToTypst inlines escapeTypst :: EscapeContext -> Text -> Text escapeTypst context t = @@ -360,3 +366,6 @@ doubleQuoted = doubleQuotes . literal . escape escapeChar '\\' = "\\\\" escapeChar '"' = "\\\"" escapeChar c = T.singleton c + +endCode :: Doc Text +endCode = beforeNonBlank ";" diff --git a/test/writer.typst b/test/writer.typst index b450bb2a3..bd3f62b33 100644 --- a/test/writer.typst +++ b/test/writer.typst @@ -435,13 +435,13 @@ yellow fruit Multiple blocks with italics: -/ #emph[apple]: #block[ +/ #emph[apple];: #block[ red fruit contains seeds, crisp, pleasant to taste ] -/ #emph[orange]: #block[ +/ #emph[orange];: #block[ orange fruit ``` @@ -571,27 +571,27 @@ Hr’s: = Inline Markup <inline-markup> -This is #emph[emphasized], and so #emph[is this]. +This is #emph[emphasized];, and so #emph[is this];. -This is #strong[strong], and so #strong[is this]. +This is #strong[strong];, and so #strong[is this];. -An #emph[#link("/url")[emphasized link]]. +An #emph[#link("/url")[emphasized link];];. -#strong[#emph[This is strong and em.]] +#strong[#emph[This is strong and em.];] -So is #strong[#emph[this]] word. +So is #strong[#emph[this];] word. -#strong[#emph[This is strong and em.]] +#strong[#emph[This is strong and em.];] -So is #strong[#emph[this]] word. +So is #strong[#emph[this];] word. This is code: `>`, `$`, `\`, `\$`, `<html>`. -#strike[This is #emph[strikeout].] +#strike[This is #emph[strikeout];.] -Superscripts: a#super[bc]d a#super[#emph[hello]] a#super[hello~there]. +Superscripts: a#super[bc];d a#super[#emph[hello];] a#super[hello~there];. -Subscripts: H#sub[2]O, H#sub[23]O, H#sub[many~of~them]O. +Subscripts: H#sub[2];O, H#sub[23];O, H#sub[many~of~them];O. These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a\~b c\~d. @@ -609,7 +609,7 @@ a^b c^d, a\~b c\~d. 'He said, "I want to go."' Were you alive in the 70’s? Here is some quoted '`code`' and a -"#link("http://example.com/?foo=1&bar=2")[quoted link]". +"#link("http://example.com/?foo=1&bar=2")[quoted link];". Some dashes: one—two — three—four — five. @@ -701,13 +701,13 @@ Minus: - <links> == Explicit <explicit> -Just a #link("/url/")[URL]. +Just a #link("/url/")[URL];. -#link("/url/")[URL and title]. +#link("/url/")[URL and title];. -#link("/url/")[URL and title]. +#link("/url/")[URL and title];. -#link("/url/")[URL and title]. +#link("/url/")[URL and title];. #link("/url/")[URL and title] @@ -717,21 +717,21 @@ Just a #link("/url/")[URL]. #link("mailto:nobody@nowhere.net")[Email link] -#link("")[Empty]. +#link("")[Empty];. == Reference <reference> -Foo #link("/url/")[bar]. +Foo #link("/url/")[bar];. -With #link("/url/")[embedded \[brackets\]]. +With #link("/url/")[embedded \[brackets\]];. #link("/url/")[b] by itself should be a link. -Indented #link("/url")[once]. +Indented #link("/url")[once];. -Indented #link("/url")[twice]. +Indented #link("/url")[twice];. -Indented #link("/url")[thrice]. +Indented #link("/url")[thrice];. This should \[not\]\[\] be a link. @@ -739,20 +739,20 @@ This should \[not\]\[\] be a link. [not]: /url ``` -Foo #link("/url/")[bar]. +Foo #link("/url/")[bar];. -Foo #link("/url/")[biz]. +Foo #link("/url/")[biz];. == With ampersands <with-ampersands> Here’s a -#link("http://example.com/?foo=1&bar=2")[link with an ampersand in the URL]. +#link("http://example.com/?foo=1&bar=2")[link with an ampersand in the URL];. -Here’s a link with an amersand in the link text: #link("http://att.com/")[AT&T]. +Here’s a link with an amersand in the link text: #link("http://att.com/")[AT&T];. -Here’s an #link("/script?foo=1&bar=2")[inline link]. +Here’s an #link("/script?foo=1&bar=2")[inline link];. -Here’s an #link("/script?foo=1&bar=2")[inline link in pointy braces]. +Here’s an #link("/script?foo=1&bar=2")[inline link in pointy braces];. == Autolinks <autolinks> @@ -780,7 +780,7 @@ 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(width: 150.0pt, image("lalune.jpg"));], caption: [ lalune ] |
