From 372cd1d3b19b94ce7a8a72349a5fb6d735025878 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 27 May 2024 19:37:52 -0700 Subject: [PATCH] Typst reader: handle inline bodies ending in a parbreak. E.g. `#strong[ test ]`. Here we simply skip the final parbreak. Treat this as a soft break, which will give results similar to the typst app. --- src/Text/Pandoc/Readers/Typst.hs | 3 ++- test/command/9807.md | 13 +++++++++++++ test/typst-reader.native | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/command/9807.md diff --git a/src/Text/Pandoc/Readers/Typst.hs b/src/Text/Pandoc/Readers/Typst.hs index c2e1983ac..128c919c4 100644 --- a/src/Text/Pandoc/Readers/Typst.hs +++ b/src/Text/Pandoc/Readers/Typst.hs @@ -539,7 +539,8 @@ pWithContents pa cs = try $ do pInlines :: PandocMonad m => P m B.Inlines pInlines = - collapseAdjacentCites . mconcat <$> many pInline + mappend <$> (collapseAdjacentCites . mconcat <$> many pInline) + <*> ((B.softbreak <$ pParBreak) <|> pure mempty) collapseAdjacentCites :: B.Inlines -> B.Inlines collapseAdjacentCites = B.fromList . foldr go [] . B.toList diff --git a/test/command/9807.md b/test/command/9807.md new file mode 100644 index 000000000..e5663fac5 --- /dev/null +++ b/test/command/9807.md @@ -0,0 +1,13 @@ +``` +% pandoc -f typst -t native +#let foo = [ + bar baz +] +*#foo* +^D +[ Para + [ Strong + [ SoftBreak , Str "bar" , Space , Str "baz" , SoftBreak ] + ] +] +``` diff --git a/test/typst-reader.native b/test/typst-reader.native index 74a0ad8de..7644ee0ff 100644 --- a/test/typst-reader.native +++ b/test/typst-reader.native @@ -203,7 +203,8 @@ Pandoc [ Underline [ Link ( "" , [] , [] ) - [ Strong + [ SoftBreak + , Strong [ Str "Typst" , Space , Str "Math" @@ -212,6 +213,7 @@ Pandoc , Space , Str "Undergrads" ] + , SoftBreak ] ( "https://github.com/johanvx/typst-undergradmath" , ""