From eced02d70e0a4e8d7dfa4c373a6c4d8a4cc08407 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sat, 5 Nov 2016 21:14:20 +0100
Subject: [PATCH] Markdown reader: Allow reference link labels starting with
 @...

...if citations extension disabled.  Example:  in

    [link text][@a]

    [@a]: url

`link text` isn't hyperlinked because `[@a]` is parsed as a citation.
Previously this happened whether or not the `citations` extension was
enabled. Now it happens only if the `citations` extension is enabled.

Closes #3209.
---
 src/Text/Pandoc/Readers/Markdown.hs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index f020e1bee..6c30fe3c3 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1774,7 +1774,8 @@ referenceLink :: (Attr -> String -> String -> Inlines -> Inlines)
 referenceLink constructor (lab, raw) = do
   sp <- (True <$ lookAhead (char ' ')) <|> return False
   (_,raw') <- option (mempty, "") $
-      lookAhead (try (spnl >> normalCite >> return (mempty, "")))
+      lookAhead (try (guardEnabled Ext_citations >>
+                      spnl >> normalCite >> return (mempty, "")))
       <|>
       try (spnl >> reference)
   when (raw' == "") $ guardEnabled Ext_shortcut_reference_links