diff options
| author | John MacFarlane <[email protected]> | 2024-02-13 08:29:45 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-02-13 19:32:12 -0800 |
| commit | 02b6483b7c4a671a2c4d86ef7f292dbe0b2d4b23 (patch) | |
| tree | 7158441ef9de930a5893b26209a2e4ea25fa1b8c | |
| parent | 2d83b7ca6f85c8dc6c472f6b00fc51b8e0e400a9 (diff) | |
Typst writer: use `#ref` or `@` for links with `reference-type="ref"`.
This attribute is added to LaTeX `\cref`, for example.
See #7463.
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 26 |
1 files 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 |
