@@ -21,7 +21,7 @@ module Text.Pandoc.Writers.Markdown (writeMarkdown, writePlain) where
2121import Prelude
2222import Control.Monad.Reader
2323import Control.Monad.State.Strict
24−import Data.Char (isSpace, isAlphaNum)
24+import Data.Char (isAlphaNum)
2525import Data.Default
2626import Data.List (find, intersperse, sortBy, transpose)
2727import qualified Data.Map as M
@@ -346,13 +346,13 @@ linkAttributes opts attr =
346346 else empty
347347
348348-- | Ordered list start parser for use in Para below.
349−olMarker :: Parser Text ParserState Char
349+olMarker :: Parser Text ParserState ()
350350olMarker = do (start, style', delim) <- anyOrderedListMarker
351351 if delim == Period &&
352352 (style' == UpperAlpha || (style' == UpperRoman &&
353353 start `elem` [1, 5, 10, 50, 100, 500, 1000]))
354− then spaceChar >> spaceChar
355− else spaceChar
354+ then mzero -- it needs 2 spaces anyway
355+ else eof
356356
357357-- | True if string begins with an ordered list marker
358358beginsWithOrderedListMarker :: Text -> Bool
@@ -419,34 +419,32 @@ blockToMarkdown' opts (Div attrs ils) = do
419419 where (id',classes',kvs') = attrs
420420 attrs' = (id',classes',("markdown","1"):kvs')
421421blockToMarkdown' opts (Plain inlines) = do
422− contents <- inlineListToMarkdown opts inlines
423422 -- escape if para starts with ordered list marker
424423 isPlain <- asks envPlain
425− let colwidth = if writerWrapText opts == WrapAuto
426− then Just $ writerColumns opts
427− else Nothing
428− let rendered = render colwidth contents
429424 let escapeMarker = T.concatMap $ \x -> if x `elemText` ".()"
430425 then T.pack ['\\', x]
431426 else T.singleton x
432− let spaceOrNothing = (not isPlain &&) . maybe True (isSpace . fst) . T.uncons
433− let contents' =
434− case T.uncons rendered of
435− Just ('%', _)
436− | isEnabled Ext_pandoc_title_block opts &&
437− isEnabled Ext_all_symbols_escapable opts -> "\\" <> contents
438− Just ('+', s) | spaceOrNothing s -> "\\" <> contents
439− Just ('*', s) | spaceOrNothing s -> "\\" <> contents
440− Just ('-', s) | spaceOrNothing s -> "\\" <> contents
441− Just ('|', _) | (isEnabled Ext_line_blocks opts ||
442− isEnabled Ext_pipe_tables opts)
443− && isEnabled Ext_all_symbols_escapable opts
444− -> "\\" <> contents
445− _ | not isPlain && beginsWithOrderedListMarker rendered
446− && isEnabled Ext_all_symbols_escapable opts
447− -> literal $ escapeMarker rendered
448− | otherwise -> contents
449− return $ contents' <> cr
427+ let startsWithSpace (Space:_) = True
428+ startsWithSpace (SoftBreak:_) = True
429+ startsWithSpace _ = False
430+ let inlines' =
431+ if isPlain
432+ then inlines
433+ else case inlines of
434+ (Str t:ys)
435+ | not isPlain
436+ , (null ys || startsWithSpace ys)
437+ , beginsWithOrderedListMarker t
438+ -> RawInline (Format "markdown") (escapeMarker t):ys
439+ (Str t:_)
440+ | not isPlain
441+ , t == "+" || t == "-" ||
442+ (t == "%" && isEnabled Ext_pandoc_title_block opts &&
443+ isEnabled Ext_all_symbols_escapable opts)
444+ -> RawInline (Format "markdown") "\\" : inlines
445+ _ -> inlines
446+ contents <- inlineListToMarkdown opts inlines'
447+ return $ contents <> cr
450448-- title beginning with fig: indicates figure
451449blockToMarkdown' opts (Para [Image attr alt (src,tgt@(T.stripPrefix "fig:" -> Just tit))])
452450 | isEnabled Ext_raw_html opts &&