aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-07-12 23:05:46 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2010-07-12 23:05:46 -0700
commitafe18e53f12da5299f274810cd3424ac211179f6 (patch)
tree9dd9d72744ef63048aa18a02d8c8aac989349ef3
parent0181e66250302516863eaa4e25bb5b4b10807e2b (diff)
downloadpandoc-afe18e53f12da5299f274810cd3424ac211179f6.tar.gz
Modified example refs so they can occur before or after target.
The refs are now replaced by numbers at the final stage, using processWith.
-rw-r--r--README4
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs20
2 files changed, 17 insertions, 7 deletions
diff --git a/README b/README
index 2e2a14e3f..47bf714cd 100644
--- a/README
+++ b/README
@@ -710,7 +710,7 @@ where the last stopped. So, for example:
(@) My third example will be numbered (3).
-Numbered examples can be labeled and referred to later in the
+Numbered examples can be labeled and referred to elsewhere in the
document:
(@good) This is a good example.
@@ -718,7 +718,7 @@ document:
As (@good) illustrates, ...
The label can be any string of alphanumeric characters, underscores,
-or hyphens. The example must occur before the reference.
+or hyphens.
Definition lists
----------------
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 086f85bb4..33fb3d8e6 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -185,7 +185,18 @@ parseMarkdown = do
-- now parse it for real...
(title, author, date) <- option ([],[],[]) titleBlock
blocks <- parseBlocks
- return $ Pandoc (Meta title author date) $ filter (/= Null) blocks
+ let doc = Pandoc (Meta title author date) $ filter (/= Null) blocks
+ -- if there are labeled examples, change references into numbers
+ examples <- liftM stateExamples getState
+ let handleExampleRef :: Inline -> Inline
+ handleExampleRef z@(Str ('@':xs)) =
+ case M.lookup xs examples of
+ Just n -> Str (show n)
+ Nothing -> z
+ handleExampleRef z = z
+ if M.null examples
+ then return doc
+ else return $ processWith handleExampleRef doc
--
-- initial pass for references and notes
@@ -928,10 +939,9 @@ exampleRef :: GenParser Char ParserState Inline
exampleRef = try $ do
char '@'
lab <- many1 (alphaNum <|> oneOf "-_")
- examples <- liftM stateExamples getState
- case M.lookup lab examples of
- Just num -> return (Str $ show num)
- Nothing -> pzero
+ -- We just return a Str. These are replaced with numbers
+ -- later. See the end of parseMarkdown.
+ return $ Str $ '@' : lab
symbol :: GenParser Char ParserState Inline
symbol = do