From 02b6483b7c4a671a2c4d86ef7f292dbe0b2d4b23 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 13 Feb 2024 08:29:45 -0800 Subject: Typst writer: use `#ref` or `@` for links with `reference-type="ref"`. This attribute is added to LaTeX `\cref`, for example. See #7463. --- src/Text/Pandoc/Writers/Typst.hs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index daa286dbf..9fc58b368 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -275,15 +275,23 @@ inlineToTypst inline = -- Note: this loses prefix then mconcat <$> mapM toCite citations else inlinesToTypst inlines - Link _attrs inlines (src,_tit) -> do - contents <- inlinesToTypst inlines - let dest = case T.uncons src of - Just ('#', ident) -> toLabel ArgumentLabel ident - _ -> doubleQuoted src - return $ "#link" <> parens dest <> - (if inlines == [Str src] - then mempty - else nowrap $ brackets contents) <> endCode + Link (_,_,kvs) inlines (src,_tit) -> do + case lookup "reference-type" kvs of + Just "ref" + | Just ('#', ident) <- T.uncons src + -> if T.all isIdentChar ident + then pure $ literal $ "@" <> ident + else pure $ "#ref" <> parens (toLabel ArgumentLabel ident) + <> endCode + _ -> do + contents <- inlinesToTypst inlines + let dest = case T.uncons src of + Just ('#', ident) -> toLabel ArgumentLabel ident + _ -> doubleQuoted src + pure $ "#link" <> parens dest <> + (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 -- cgit v1.2.3