git.iko.soy/typeable/pandoc
on master help sign in
Modified example refs so they can occur before or after target.

The refs are now replaced by numbers at the final stage, using processWith.

commitafe18e53f12da5299f274810cd3424ac211179f6 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 12 Jul 2010, 23:05 (16 years ago) parent0181e66
2 files changed+17−7
README+2−2 src/Text/Pandoc/Readers/Markdown.hs+15−5
README+2−2
@@ -710,7 +710,7 @@ where the last stopped. So, for example:
710710
711711 (@) My third example will be numbered (3).
712712
713−Numbered examples can be labeled and referred to later in the
713+Numbered examples can be labeled and referred to elsewhere in the
714714document:
715715
716716 (@good) This is a good example.
@@ -718,7 +718,7 @@ document:
718718 As (@good) illustrates, ...
719719
720720The label can be any string of alphanumeric characters, underscores,
721−or hyphens. The example must occur before the reference.
721+or hyphens.
722722
723723Definition lists
724724----------------
src/Text/Pandoc/Readers/Markdown.hs+15−5
@@ -185,7 +185,18 @@ parseMarkdown = do
185185 -- now parse it for real...
186186 (title, author, date) <- option ([],[],[]) titleBlock
187187 blocks <- parseBlocks
188− return $ Pandoc (Meta title author date) $ filter (/= Null) blocks
188+ let doc = Pandoc (Meta title author date) $ filter (/= Null) blocks
189+ -- if there are labeled examples, change references into numbers
190+ examples <- liftM stateExamples getState
191+ let handleExampleRef :: Inline -> Inline
192+ handleExampleRef z@(Str ('@':xs)) =
193+ case M.lookup xs examples of
194+ Just n -> Str (show n)
195+ Nothing -> z
196+ handleExampleRef z = z
197+ if M.null examples
198+ then return doc
199+ else return $ processWith handleExampleRef doc
189200
190201--
191202-- initial pass for references and notes
@@ -928,10 +939,9 @@ exampleRef :: GenParser Char ParserState Inline
928939exampleRef = try $ do
929940 char '@'
930941 lab <- many1 (alphaNum <|> oneOf "-_")
931− examples <- liftM stateExamples getState
932− case M.lookup lab examples of
933− Just num -> return (Str $ show num)
934− Nothing -> pzero
942+ -- We just return a Str. These are replaced with numbers
943+ -- later. See the end of parseMarkdown.
944+ return $ Str $ '@' : lab
935945
936946symbol :: GenParser Char ParserState Inline
937947symbol = do