diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2006-12-19 07:30:36 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2006-12-19 07:30:36 +0000 |
commit | 3a6296acae34ddb2ea7678ee6d8c727aab4eb087 (patch) | |
tree | a1e35b6d586dbf72ac0314241f1bae1881d51162 /src | |
parent | a8bbd950e526abb69262fb7186ced583885c6ac8 (diff) | |
download | pandoc-3a6296acae34ddb2ea7678ee6d8c727aab4eb087.tar.gz |
Changed footnote syntax to conform to the de facto standard
for markdown footnotes. References are now like this[^1]
rather than like this^(1). There are corresponding changes
in the footnotes themselves. See the updated README for
more details.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@230 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 36 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 6 |
2 files changed, 28 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index cbefa09fe..c47fd771a 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -124,7 +124,7 @@ parseBlocks = do result <- manyTill block eof return result -block = choice [ codeBlock, referenceKey, note, header, hrule, list, blockQuote, rawHtmlBlocks, +block = choice [ codeBlock, note, referenceKey, header, hrule, list, blockQuote, rawHtmlBlocks, rawLaTeXEnvironment, para, plain, blankBlock, nullBlock ] <?> "block" -- @@ -200,19 +200,31 @@ codeBlock = do -- note block -- +rawLine = try (do + notFollowedBy' blankline + contents <- many1 nonEndline + end <- option "" (do + newline + option "" indentSpaces + return "\n") + return (contents ++ end)) + +rawLines = do + lines <- many1 rawLine + return (concat lines) + note = try (do (NoteRef ref) <- noteRef + char ':' skipSpaces - raw <- sepBy (many (choice [nonEndline, - (try (do {endline; notFollowedBy (char noteStart); return '\n'})) - ])) (try (do {newline; char noteStart; option ' ' (char ' ')})) - newline - blanklines - -- parse the extracted block, which may contain various block elements: + skipEndline + raw <- sepBy rawLines (try (do {blankline; indentSpaces})) + option "" blanklines + -- parse the extracted text, which may contain various block elements: state <- getState let parsed = case runParser parseBlocks (state {stateParserContext = BlockQuoteState}) "block" ((joinWithSep "\n" raw) ++ "\n\n") of Left err -> error $ "Raw block:\n" ++ show raw ++ "\nError:\n" ++ show err - Right result -> result + Right result -> result return (Note ref parsed)) -- @@ -398,8 +410,8 @@ text = choice [ math, strong, emph, code2, code1, str, linebreak, tabchar, inline = choice [ rawLaTeXInline, escapedChar, special, hyphens, text, ltSign, symbol ] <?> "inline" -special = choice [ link, referenceLink, rawHtmlInline, autoLink, - image, noteRef ] <?> "link, inline html, note, or image" +special = choice [ noteRef, link, referenceLink, rawHtmlInline, autoLink, + image ] <?> "link, inline html, note, or image" escapedChar = escaped anyChar @@ -505,6 +517,7 @@ endline = -- a reference label for a link reference = do char labelStart + notFollowedBy (char noteStart) label <- manyTill inline (char labelEnd) return (normalizeSpaces label) @@ -575,7 +588,8 @@ image = return (Image label src)) noteRef = try (do + char labelStart char noteStart - ref <- between (char '(') (char ')') (many1 (noneOf " \t\n)")) + ref <- manyTill (noneOf " \t\n") (char labelEnd) return (NoteRef ref)) diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index e7c167eb3..18a904fac 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -76,8 +76,8 @@ blockToMarkdown tabStop (Note ref lst) = else let first = head lns rest = tail lns in - text ("^(" ++ (escapeString ref) ++ ") ") <> (text first) $$ (vcat $ - map (\line -> (text "^ ") <> (text line)) rest) <> (text "\n") + text ("[^" ++ (escapeString ref) ++ "]: ") <> (text first) $$ (vcat $ + map (\line -> (text " ") <> (text line)) rest) <> (text "\n") blockToMarkdown tabStop (Key txt (Src src tit)) = text " " <> char '[' <> inlineListToMarkdown txt <> char ']' <> text ": " <> text src <> (if tit /= "" then (text (" \"" ++ (escapeLinkTitle tit) ++ "\"")) else empty) @@ -145,4 +145,4 @@ inlineToMarkdown (Image alternate (Ref [])) = inlineToMarkdown (Image alternate (Ref ref)) = char '!' <> char '[' <> inlineListToMarkdown alternate <> char ']' <> char '[' <> inlineListToMarkdown ref <> char ']' -inlineToMarkdown (NoteRef ref) = char '^' <> char '(' <> text (escapeString ref) <> char ')' +inlineToMarkdown (NoteRef ref) = text "[^" <> text (escapeString ref) <> char ']' |