diff options
Diffstat (limited to 'src/Text/Pandoc')
-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 ']' |