summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-04-05 12:56:51 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2023-04-05 12:57:25 -0700
commit826b8912ad8c7915432df548f030a095899e6078 (patch)
tree68dceb32a706d960da92a2e5d656cc32ad8e7a28
parent0353e11e27c08d211cea13bbad1ad968845dc29e (diff)
Typst writer: use `<..>` for labels, create internal links.
Internal links to labels are now supported.
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs7
-rw-r--r--test/writer.typst62
2 files changed, 36 insertions, 33 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
index 208d90c7c..b290506a8 100644
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -276,7 +276,10 @@ inlineToTypst inline =
else inlinesToTypst inlines
Link _attrs inlines (src,_tit) -> do
contents <- inlinesToTypst inlines
- return $ "#link" <> parens (doubleQuoted src) <>
+ let dest = case T.uncons src of
+ Just ('#', ident) -> "<" <> literal ident <> ">"
+ _ -> doubleQuoted src
+ return $ "#link" <> parens dest <>
if render Nothing contents == src
then mempty
else nowrap $ brackets contents
@@ -325,7 +328,7 @@ toLabel :: Text -> Doc Text
toLabel ident =
if T.null ident
then mempty
- else "#label" <> parens (doubleQuotes (literal ident))
+ else "<" <> literal ident <> ">"
doubleQuoted :: Text -> Doc Text
doubleQuoted = doubleQuotes . literal . escape
diff --git a/test/writer.typst b/test/writer.typst
index 1ae1a2e62..37a17128b 100644
--- a/test/writer.typst
+++ b/test/writer.typst
@@ -109,31 +109,31 @@ markdown test suite.
#horizontalrule
= Headers
-#label("headers")
+<headers>
== Level 2 with an #link("/url")[embedded link]
-#label("level-2-with-an-embedded-link")
+<level-2-with-an-embedded-link>
=== Level 3 with #emph[emphasis]
-#label("level-3-with-emphasis")
+<level-3-with-emphasis>
==== Level 4
-#label("level-4")
+<level-4>
===== Level 5
-#label("level-5")
+<level-5>
= Level 1
-#label("level-1")
+<level-1>
== Level 2 with #emph[emphasis]
-#label("level-2-with-emphasis")
+<level-2-with-emphasis>
=== Level 3
-#label("level-3")
+<level-3>
with no blank line
== Level 2
-#label("level-2")
+<level-2>
with no blank line
#horizontalrule
= Paragraphs
-#label("paragraphs")
+<paragraphs>
Here’s a regular paragraph.
In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item.
@@ -148,7 +148,7 @@ here.
#horizontalrule
= Block Quotes
-#label("block-quotes")
+<block-quotes>
E-mail style:
#blockquote[
@@ -187,7 +187,7 @@ And a following paragraph.
#horizontalrule
= Code Blocks
-#label("code-blocks")
+<code-blocks>
Code:
```
@@ -211,9 +211,9 @@ These should not be escaped: \$ \\ \> \[ \{
#horizontalrule
= Lists
-#label("lists")
+<lists>
== Unordered
-#label("unordered")
+<unordered>
Asterisks tight:
- asterisk 1
@@ -257,7 +257,7 @@ Minuses loose:
- Minus 3
== Ordered
-#label("ordered")
+<ordered>
Tight:
+ First
@@ -297,7 +297,7 @@ Multiple paragraphs:
+ Item 3.
== Nested
-#label("nested")
+<nested>
- Tab
- Tab
- Tab
@@ -324,7 +324,7 @@ Same thing but with paragraphs:
+ Third
== Tabs and spaces
-#label("tabs-and-spaces")
+<tabs-and-spaces>
- this is a list item indented with tabs
- this is a list item indented with spaces
@@ -334,7 +334,7 @@ Same thing but with paragraphs:
- this is an example list item indented with spaces
== Fancy list markers
-#label("fancy-list-markers")
+<fancy-list-markers>
#block[
#set enum(numbering: "(1)", start: 2)
+ begins with 2
@@ -389,7 +389,7 @@ B. Williams
#horizontalrule
= Definition Lists
-#label("definition-lists")
+<definition-lists>
Tight using spaces:
/ apple: #block[
@@ -494,7 +494,7 @@ orange fruit
]
= HTML Blocks
-#label("html-blocks")
+<html-blocks>
Simple block on one line:
foo
@@ -551,7 +551,7 @@ Hr’s:
#horizontalrule
= Inline Markup
-#label("inline-markup")
+<inline-markup>
This is #emph[emphasized], and so #emph[is this].
This is #strong[strong], and so #strong[is this].
@@ -580,7 +580,7 @@ a^b c^d, a~b c~d.
#horizontalrule
= Smart quotes, ellipses, dashes
-#label("smart-quotes-ellipses-dashes")
+<smart-quotes-ellipses-dashes>
"Hello," said the spider. "'Shelob' is my name."
'A', 'B', and 'C' are letters.
@@ -601,7 +601,7 @@ Ellipses…and…and….
#horizontalrule
= LaTeX
-#label("latex")
+<latex>
-
- $2 plus 2 eq 4$
- $x in y$
@@ -625,7 +625,7 @@ Here’s a LaTeX table:
#horizontalrule
= Special Characters
-#label("special-characters")
+<special-characters>
Here is some unicode:
- I hat: Î
@@ -679,9 +679,9 @@ Minus: -
#horizontalrule
= Links
-#label("links")
+<links>
== Explicit
-#label("explicit")
+<explicit>
Just a #link("/url/")[URL].
#link("/url/")[URL and title].
@@ -701,7 +701,7 @@ Just a #link("/url/")[URL].
#link("")[Empty].
== Reference
-#label("reference")
+<reference>
Foo #link("/url/")[bar].
With #link("/url/")[embedded \[brackets\]].
@@ -725,7 +725,7 @@ Foo #link("/url/")[bar].
Foo #link("/url/")[biz].
== With ampersands
-#label("with-ampersands")
+<with-ampersands>
Here’s a
#link("http://example.com/?foo=1&bar=2")[link with an ampersand in the URL].
@@ -736,7 +736,7 @@ 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].
== Autolinks
-#label("autolinks")
+<autolinks>
With an ampersand:
#link("http://example.com/?foo=1&bar=2")[http://example.com/?foo\=1&bar\=2]
@@ -759,7 +759,7 @@ or here: <http://example.com/>
#horizontalrule
= Images
-#label("images")
+<images>
From "Voyage dans la Lune" by Georges Melies (1902):
#figure([#image("lalune.jpg")],
@@ -773,7 +773,7 @@ Here is a movie #image("movie.jpg") icon.
#horizontalrule
= Footnotes
-#label("footnotes")
+<footnotes>
Here is a footnote reference,#super[1] and another.#super[2] This should
#emph[not] be a footnote reference, because it contains a space.\[^my note\]
Here is an inline note.#super[3]