Skip to content

Commit

Permalink
Man writer: use UR, MT macros for URLs, emails.
Browse files Browse the repository at this point in the history
Closes #9120.
  • Loading branch information
jgm committed Oct 5, 2023
1 parent e426b3d commit 5a691e8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
16 changes: 10 additions & 6 deletions src/Text/Pandoc/Writers/Man.hs
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,17 @@ inlineToMan _ Space = return space
inlineToMan opts (Link _ txt (src, _))
| not (isURI src) = inlineListToMan opts txt -- skip relative links
| otherwise = do
linktext <- inlineListToMan opts txt
let srcSuffix = fromMaybe src (T.stripPrefix "mailto:" src)
return $ case txt of
[Str s]
| escapeURI s == srcSuffix ->
char '<' <> literal srcSuffix <> char '>'
_ -> linktext <> literal " (" <> literal src <> char ')'
linktext <- case txt of
[Str s] | escapeURI s == srcSuffix -> pure mempty
_ -> inlineListToMan opts txt
let (start, end) = if "mailto:" `T.isPrefixOf` src
then (".MT", ".ME")
else (".UR", ".UE")
return $ cr
$$ (start <+> literal srcSuffix)
$$ linktext
$$ (end <+> "\\c" <> cr) -- \c avoids space after
inlineToMan opts (Image attr alternate (source, tit)) = do
let txt = if null alternate || (alternate == [Str ""]) ||
(alternate == [Str source]) -- to prevent autolinks
Expand Down
8 changes: 6 additions & 2 deletions test/command/8508.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ SEE ALSO
^D
.SH SEE ALSO
.IP \[bu] 2
Milk (https://en.wikipedia.org/wiki/Milk)
.UR https://en.wikipedia.org/wiki/Milk
Milk
.UE \c
.IP \[bu] 2
EBNF (https://en.wikipedia.org/wiki/Extended_Backus–Naur_form)
.UR https://en.wikipedia.org/wiki/Extended_Backus–Naur_form
EBNF
.UE \c
```
36 changes: 28 additions & 8 deletions test/writer.man
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ So is `pine.'
`He said, \[lq]I want to go.\[rq]' Were you alive in the 70\[cq]s?
.PP
Here is some quoted `\f[CR]code\f[R]' and a \[lq]quoted
link (http://example.com/?foo=1&bar=2)\[rq].
link
.UR http://example.com/?foo=1&bar=2
.UE \c
\[rq].
.PP
Some dashes: one\[em]two \[em] three\[em]four \[em] five.
.PP
Expand Down Expand Up @@ -629,26 +632,40 @@ Foo bar.
Foo biz.
.SS With ampersands
Here\[cq]s a link with an ampersand in the
URL (http://example.com/?foo=1&bar=2).
URL
.UR http://example.com/?foo=1&bar=2
.UE \c
.
.PP
Here\[cq]s a link with an amersand in the link text: AT&T (http://att.com/).
Here\[cq]s a link with an amersand in the link text:
.UR http://att.com/
AT&T
.UE \c
.
.PP
Here\[cq]s an inline link.
.PP
Here\[cq]s an inline link in pointy braces.
.SS Autolinks
With an ampersand: <http://example.com/?foo=1&bar=2>
With an ampersand:
.UR http://example.com/?foo=1&bar=2
.UE
.IP \[bu] 2
In a list?
.IP \[bu] 2
<http://example.com/>
.UR http://example.com/
.UE \c
.IP \[bu] 2
It should.
.PP
An e-mail address: <nobody@nowhere.net>
An e-mail address:
.MT nobody@nowhere.net
.ME \c
.RS
.PP
Blockquoted: <http://example.com/>
Blockquoted:
.UR http://example.com/
.UE \c
.RE
.PP
Auto-links should not occur here: \f[CR]<http://example.com/>\f[R]
Expand Down Expand Up @@ -701,7 +718,10 @@ the first line of each block.
.SS [3]
.PP
This is \f[I]easier\f[R] to type.
Inline notes may contain links (http://google.com) and \f[CR]]\f[R] verbatim
Inline notes may contain links
.UR http://google.com
.UE \c
and \f[CR]]\f[R] verbatim
characters, as well as [bracketed text].
.SS [4]
.PP
Expand Down

0 comments on commit 5a691e8

Please sign in to comment.