git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1344 from mpickering/master
2b364b3John MacFarlane
src/Text/Pandoc/Readers/HTML.hs+4−13
@@ -50,7 +50,6 @@ import Data.Char ( isDigit )
50import Control.Monad ( liftM, guard, when, mzero )
50import Control.Monad ( liftM, guard, when, mzero )
51import Control.Applicative ( (<$>), (<$), (<*) )
51import Control.Applicative ( (<$>), (<$), (<*) )
52import Data.Monoid
52import Data.Monoid
53−import Data.Sequence (ViewL(..), ViewR(..), viewr, viewl)
54
53
55isSpace :: Char -> Bool
54isSpace :: Char -> Bool
56isSpace ' ' = True
55isSpace ' ' = True
@@ -369,9 +368,9 @@ pQ = do
369 then InSingleQuote
368 then InSingleQuote
370 else InDoubleQuote
369 else InDoubleQuote
371 let constructor = case quoteType of
370 let constructor = case quoteType of
372− SingleQuote -> B.singleQuoted
371+ SingleQuote -> B.singleQuoted
373 DoubleQuote -> B.doubleQuoted
372 DoubleQuote -> B.doubleQuoted
374− withQuoteContext innerQuoteContext $
373+ withQuoteContext innerQuoteContext $
375 pInlinesInTags "q" constructor
374 pInlinesInTags "q" constructor
376
375
377pEmph :: TagParser Inlines
376pEmph :: TagParser Inlines
@@ -406,7 +405,7 @@ pLink = try $ do
406 let url = fromAttrib "href" tag
405 let url = fromAttrib "href" tag
407 let title = fromAttrib "title" tag
406 let title = fromAttrib "title" tag
408 lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
407 lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
409− return $ B.link (escapeURI url) title lab
408+ return $ B.link (escapeURI url) title lab
410
409
411pImage :: TagParser Inlines
410pImage :: TagParser Inlines
412pImage = do
411pImage = do
@@ -439,15 +438,7 @@ pRawHtmlInline = do
439
438
440pInlinesInTags :: String -> (Inlines -> Inlines)
439pInlinesInTags :: String -> (Inlines -> Inlines)
441 -> TagParser Inlines
440 -> TagParser Inlines
442−pInlinesInTags tagtype f = do
441+pInlinesInTags tagtype f = extractSpaces f <$> pInTags tagtype inline
443− contents <- B.unMany <$> pInTags tagtype inline
444− let left = case viewl contents of
445− (Space :< _) -> B.space
446− _ -> mempty
447− let right = case viewr contents of
448− (_ :> Space) -> B.space
449− _ -> mempty
450− return (left <> f (trimInlines . B.Many $ contents) <> right)
451
442
452pInTags :: (Monoid a) => String -> TagParser a
443pInTags :: (Monoid a) => String -> TagParser a
453 -> TagParser a
444 -> TagParser a
src/Text/Pandoc/Shared.hs+16
@@ -53,6 +53,7 @@ module Text.Pandoc.Shared (
53 -- * Pandoc block and inline list processing
53 -- * Pandoc block and inline list processing
54 orderedListMarkers,
54 orderedListMarkers,
55 normalizeSpaces,
55 normalizeSpaces,
56+ extractSpaces,
56 normalize,
57 normalize,
57 stringify,
58 stringify,
58 compactify,
59 compactify,
@@ -113,6 +114,7 @@ import qualified Data.ByteString as BS
113import qualified Data.ByteString.Char8 as B8
114import qualified Data.ByteString.Char8 as B8
114import Text.Pandoc.Compat.Monoid
115import Text.Pandoc.Compat.Monoid
115import Data.ByteString.Base64 (decodeLenient)
116import Data.ByteString.Base64 (decodeLenient)
117+import Data.Sequence (ViewR(..), ViewL(..), viewl, viewr)
116
118
117#ifdef EMBED_DATA_FILES
119#ifdef EMBED_DATA_FILES
118import Text.Pandoc.Data (dataFiles)
120import Text.Pandoc.Data (dataFiles)
@@ -331,6 +333,20 @@ isSpaceOrEmpty Space = True
331isSpaceOrEmpty (Str "") = True
333isSpaceOrEmpty (Str "") = True
332isSpaceOrEmpty _ = False
334isSpaceOrEmpty _ = False
333
335
336+-- | Extract the leading and trailing spaces from inside an inline element
337+-- and place them outside the element.
338+
339+extractSpaces :: (Inlines -> Inlines) -> Inlines -> Inlines
340+extractSpaces f is =
341+ let contents = B.unMany is
342+ left = case viewl contents of
343+ (Space :< _) -> B.space
344+ _ -> mempty
345+ right = case viewr contents of
346+ (_ :> Space) -> B.space
347+ _ -> mempty in
348+ (left <> f (B.trimInlines . B.Many $ contents) <> right)
349+
334-- | Normalize @Pandoc@ document, consolidating doubled 'Space's,
350-- | Normalize @Pandoc@ document, consolidating doubled 'Space's,
335-- combining adjacent 'Str's and 'Emph's, remove 'Null's and
351-- combining adjacent 'Str's and 'Emph's, remove 'Null's and
336-- empty elements, etc.
352-- empty elements, etc.