@@ -35,12 +35,12 @@ Implemented and parsed:
3535 - blockquote
3636 - Inlines : strong, emph, cite, code, deleted, superscript,
3737 subscript, links
38+ - footnotes
3839
3940Implemented but discarded:
4041 - HTML-specific and CSS-specific attributes
4142
4243Left to be implemented:
43− - footnotes
4444 - dimension sign
4545 - all caps
4646 - definition lists
@@ -64,7 +64,7 @@ import Text.Pandoc.Readers.HTML ( htmlTag, htmlEndTag, -- find code blocks
6464-- import Text.Pandoc.Readers.Markdown (smartPunctuation)
6565import Text.ParserCombinators.Parsec
6666import Data.Char ( digitToInt, isLetter )
67−import Control.Monad ( guard )
67+import Control.Monad ( guard, liftM )
6868
6969-- | Parse a Textile text and return a Pandoc document.
7070readTextile :: ParserState -- ^ Parser state, including options for parser
@@ -87,8 +87,35 @@ parseTextile = do
8787 -- textile allows raw HTML and does smart punctuation by default
8888 updateState (\state -> state { stateParseRaw = True, stateSmart = True })
8989 many blankline
90− blocks <- parseBlocks
91− return $ Pandoc (Meta [Str ""] [[Str ""]] [Str ""]) blocks -- FIXME
90+ startPos <- getPosition
91+ -- go through once just to get list of reference keys and notes
92+ -- docMinusKeys is the raw document with blanks where the keys/notes were...
93+ let firstPassParser = noteBlock <|> lineClump
94+ manyTill firstPassParser eof >>= setInput . concat
95+ setPosition startPos
96+ st' <- getState
97+ let reversedNotes = stateNotes st'
98+ updateState $ \s -> s { stateNotes = reverse reversedNotes }
99+ -- now parse it for real...
100+ blocks <- parseBlocks
101+ return $ Pandoc (Meta [] [] []) blocks -- FIXME
102+
103+noteMarker :: GenParser Char ParserState [Char]
104+noteMarker = skipMany spaceChar >> string "fn" >> manyTill digit (char '.')
105+
106+noteBlock :: GenParser Char ParserState [Char]
107+noteBlock = try $ do
108+ startPos <- getPosition
109+ ref <- noteMarker
110+ optional blankline
111+ contents <- liftM unlines $ many1Till anyLine (blanklines <|> noteBlock)
112+ endPos <- getPosition
113+ let newnote = (ref, contents ++ "\n")
114+ st <- getState
115+ let oldnotes = stateNotes st
116+ updateState $ \s -> s { stateNotes = newnote : oldnotes }
117+ -- return blanks so line count isn't affected
118+ return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
92119
93120-- | Parse document blocks
94121parseBlocks :: GenParser Char ParserState [Block]
@@ -306,6 +333,7 @@ inlines = manyTill inline newline
306333inlineParsers :: [GenParser Char ParserState Inline]
307334inlineParsers = [ autoLink
308335 , mark
336+ , note
309337 , str
310338 , htmlSpan
311339 , whitespace
@@ -349,6 +377,17 @@ copy = do
349377 char ')'
350378 return $ Str "\169"
351379
380+note :: GenParser Char ParserState Inline
381+note = try $ do
382+ char '['
383+ ref <- many1 digit
384+ char ']'
385+ state <- getState
386+ let notes = stateNotes state
387+ case lookup ref notes of
388+ Nothing -> fail "note not found"
389+ Just raw -> liftM Note $ parseFromString parseBlocks raw
390+
352391-- | Any string
353392str :: GenParser Char ParserState Inline
354393str = do