Markdown reader: don't parse links or bracketed spans as citations.
Previously pandoc would parse [link to (@a)](url) as a citation; similarly [(@a)]{#ident} This is undesirable. One should be able to use example references in citations, and even if `@a` is not defined as an example reference, `[@a](url)` should be a link containing an author-in-text citation rather than a normal citation followed by literal `(url)`. Closes #7632.
This commit is contained in:
parent
7754b7f2dd
commit
0a93acf91a
2 changed files with 70 additions and 2 deletions
|
@ -327,6 +327,7 @@ referenceKey :: PandocMonad m => MarkdownParser m (F Blocks)
|
|||
referenceKey = try $ do
|
||||
pos <- getPosition
|
||||
skipNonindentSpaces
|
||||
notFollowedBy (void cite)
|
||||
(_,raw) <- reference
|
||||
char ':'
|
||||
skipSpaces >> optional newline >> skipSpaces >> notFollowedBy (char '[')
|
||||
|
@ -1781,8 +1782,8 @@ endline = try $ do
|
|||
-- a reference label for a link
|
||||
reference :: PandocMonad m => MarkdownParser m (F Inlines, Text)
|
||||
reference = do
|
||||
guardDisabled Ext_footnotes <|> notFollowedBy' (string "[^")
|
||||
guardDisabled Ext_citations <|> notFollowedBy' (string "[@")
|
||||
-- guardDisabled Ext_footnotes <|> notFollowedBy' (string "[^")
|
||||
-- guardDisabled Ext_citations <|> notFollowedBy' (string "[@")
|
||||
withRaw $ trimInlinesF <$> inlinesInBalancedBrackets
|
||||
|
||||
parenthesizedChars :: PandocMonad m => MarkdownParser m Text
|
||||
|
@ -2201,6 +2202,7 @@ normalCite = try $ do
|
|||
citations <- citeList
|
||||
spnl
|
||||
char ']'
|
||||
notFollowedBy (oneOf "{([") -- not a link or a bracketed span
|
||||
return citations
|
||||
|
||||
suffix :: PandocMonad m => MarkdownParser m (F Inlines)
|
||||
|
|
66
test/command/7632.md
Normal file
66
test/command/7632.md
Normal file
|
@ -0,0 +1,66 @@
|
|||
```
|
||||
% pandoc -t native
|
||||
(@a) First case
|
||||
|
||||
[link to (@a)](url)
|
||||
^D
|
||||
[ OrderedList
|
||||
( 1 , Example , TwoParens )
|
||||
[ [ Plain [ Str "First" , Space , Str "case" ] ] ]
|
||||
, Para
|
||||
[ Link
|
||||
( "" , [] , [] )
|
||||
[ Str "link" , Space , Str "to" , Space , Str "(1)" ]
|
||||
( "url" , "" )
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -t native
|
||||
[@a]{.class}
|
||||
^D
|
||||
[ Para
|
||||
[ Span
|
||||
( "" , [ "class" ] , [] )
|
||||
[ Cite
|
||||
[ Citation
|
||||
{ citationId = "a"
|
||||
, citationPrefix = []
|
||||
, citationSuffix = []
|
||||
, citationMode = AuthorInText
|
||||
, citationNoteNum = 1
|
||||
, citationHash = 0
|
||||
}
|
||||
]
|
||||
[ Str "@a" ]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -t native
|
||||
[@a](url)
|
||||
^D
|
||||
[ Para
|
||||
[ Link
|
||||
( "" , [] , [] )
|
||||
[ Cite
|
||||
[ Citation
|
||||
{ citationId = "a"
|
||||
, citationPrefix = []
|
||||
, citationSuffix = []
|
||||
, citationMode = AuthorInText
|
||||
, citationNoteNum = 1
|
||||
, citationHash = 0
|
||||
}
|
||||
]
|
||||
[ Str "@a" ]
|
||||
]
|
||||
( "url" , "" )
|
||||
]
|
||||
]
|
||||
|
||||
```
|
Loading…
Reference in a new issue