git.iko.soy/typeable/pandoc
on master help sign in
Added eastAsianLineBreakFilter to Shared.

This used to live in the Markdown reader.

commit774075c3e22ab2ad35e2306a5b98e30da512b310 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 30 May 2017, 10:22 (9 years ago) parent5ec384e
2 files changed+13−11
src/Text/Pandoc/Readers/Markdown.hs+1−11 src/Text/Pandoc/Shared.hs+12
src/Text/Pandoc/Readers/Markdown.hs+1−11
@@ -55,11 +55,9 @@ import qualified Text.Pandoc.Builder as B
5555import Text.Pandoc.Class (PandocMonad, report)
5656import Text.Pandoc.Definition
5757import Text.Pandoc.Emoji (emojis)
58−import Text.Pandoc.Generic (bottomUp)
5958import Text.Pandoc.Logging
6059import Text.Pandoc.Options
6160import Text.Pandoc.Parsing hiding (tableWith)
62−import Text.Pandoc.Pretty (charWidth)
6361import Text.Pandoc.Readers.HTML (htmlInBalanced, htmlTag, isBlockTag,
6462 isCommentTag, isInlineTag, isTextTag)
6563import Text.Pandoc.Readers.LaTeX (rawLaTeXBlock, rawLaTeXInline)
@@ -375,15 +373,7 @@ parseMarkdown = do
375373 return $ Pandoc meta bs) st
376374 reportLogMessages
377375 (do guardEnabled Ext_east_asian_line_breaks
378− return $ bottomUp softBreakFilter doc) <|> return doc
379−
380−softBreakFilter :: [Inline] -> [Inline]
381−softBreakFilter (x:SoftBreak:y:zs) =
382− case (stringify x, stringify y) of
383− (xs@(_:_), (c:_))
384− | charWidth (last xs) == 2 && charWidth c == 2 -> x:y:zs
385− _ -> x:SoftBreak:y:zs
386−softBreakFilter xs = xs
376+ return $ eastAsianLineBreakFilter doc) <|> return doc
387377
388378referenceKey :: PandocMonad m => MarkdownParser m (F Blocks)
389379referenceKey = try $ do
src/Text/Pandoc/Shared.hs+12
@@ -70,6 +70,7 @@ module Text.Pandoc.Shared (
7070 isTightList,
7171 addMetaField,
7272 makeMeta,
73+ eastAsianLineBreakFilter,
7374 -- * TagSoup HTML handling
7475 renderTags',
7576 -- * File handling
@@ -120,6 +121,7 @@ import qualified Control.Monad.State as S
120121import qualified Control.Exception as E
121122import Control.Monad (msum, unless, MonadPlus(..))
122123import Text.Pandoc.Pretty (charWidth)
124+import Text.Pandoc.Generic (bottomUp)
123125import Text.Pandoc.Compat.Time
124126import Data.Time.Clock.POSIX
125127import System.IO.Error
@@ -578,6 +580,16 @@ makeMeta title authors date =
578580 $ addMetaField "date" (B.fromList date)
579581 $ nullMeta
580582
583+-- | Remove soft breaks between East Asian characters.
584+eastAsianLineBreakFilter :: Pandoc -> Pandoc
585+eastAsianLineBreakFilter = bottomUp go
586+ where go (x:SoftBreak:y:zs) =
587+ case (stringify x, stringify y) of
588+ (xs@(_:_), (c:_))
589+ | charWidth (last xs) == 2 && charWidth c == 2 -> x:y:zs
590+ _ -> x:SoftBreak:y:zs
591+ go xs = xs
592+
581593--
582594-- TagSoup HTML handling
583595--