Man reader: support UR/UE, MT/ME for links.

Closes #4989.
This commit is contained in:
John MacFarlane 2018-10-20 22:55:03 -07:00
parent 2b7a541dd0
commit 9593b375d7
3 changed files with 36 additions and 4 deletions

View file

@ -497,9 +497,8 @@ parsePara = para . trimInlines <$> parseInlines
parseInlines :: PandocMonad m => ManParser m Inlines parseInlines :: PandocMonad m => ManParser m Inlines
parseInlines = do parseInlines = do
inls <- many1 (lineInl <|> comment) inls <- many1 (lineInl <|> comment <|> parseLink <|> parseEmailLink)
let withspaces = intersperse B.space inls return $ mconcat $ intersperse B.space inls
return $ mconcat withspaces
lineInl :: PandocMonad m => ManParser m Inlines lineInl :: PandocMonad m => ManParser m Inlines
lineInl = do lineInl = do
@ -605,6 +604,26 @@ definitionListItem = try $ do
parseDefinitionList :: PandocMonad m => ManParser m Blocks parseDefinitionList :: PandocMonad m => ManParser m Blocks
parseDefinitionList = definitionList <$> many1 definitionListItem parseDefinitionList = definitionList <$> many1 definitionListItem
parseLink :: PandocMonad m => ManParser m Inlines
parseLink = try $ do
MMacro _ args <- mmacro "UR"
contents <- mconcat <$> many1 (lineInl <|> comment)
mmacro "UE"
let url = case args of
[] -> ""
(x:_) -> linePartsToString x
return $ link url "" contents
parseEmailLink :: PandocMonad m => ManParser m Inlines
parseEmailLink = do
MMacro _ args <- mmacro "MT"
contents <- mconcat <$> many1 (lineInl <|> comment)
mmacro "ME"
let url = case args of
[] -> ""
(x:_) -> "mailto:" ++ linePartsToString x
return $ link url "" contents
parseMacroDef :: PandocMonad m => ManParser m Blocks parseMacroDef :: PandocMonad m => ManParser m Blocks
parseMacroDef = do parseMacroDef = do
MMacro _ args <- mmacro "de" MMacro _ args <- mmacro "de"

View file

@ -197,3 +197,13 @@ Plus: +
.PP .PP
Minus: \- Minus: \-
.PP .PP
.SH Links
.PP
.UR http://\:example.com
some random
site
.UE
.PP
.MT me@example.com
my email address.
.ME

View file

@ -98,4 +98,7 @@ Pandoc (Meta {unMeta = fromList [("date",MetaInlines [Str "Oct",Space,Str "17,",
,Para [Str "Period:",Space,Str "."] ,Para [Str "Period:",Space,Str "."]
,Para [Str "Bang:",Space,Str "!"] ,Para [Str "Bang:",Space,Str "!"]
,Para [Str "Plus:",Space,Str "+"] ,Para [Str "Plus:",Space,Str "+"]
,Para [Str "Minus:",Space,Str "-"]] ,Para [Str "Minus:",Space,Str "-"]
,Header 1 ("",[],[]) [Str "Links"]
,Para [Link ("",[],[]) [Str "some",Space,Str "randomsite"] ("http://example.com","")]
,Para [Link ("",[],[]) [Str "my",Space,Str "email",Space,Str "address."] ("mailto:me@example.com","")]]