aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-10-02 21:51:34 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2016-10-02 21:51:34 +0200
commit46d8b42da5d42b981bc56c49416cec15abaf2d09 (patch)
treead6c91bd77cca875f47fbb369256e994d9f59dd7 /src
parenta99d81dce3fc53d177e505d54170197ecd3f6c1c (diff)
downloadpandoc-46d8b42da5d42b981bc56c49416cec15abaf2d09.tar.gz
AsciiDoc writer: avoid unnecessary use of "unconstrained" emphasis.
In AsciiDoc, you must use a special form of emphasis (double `__`) for intraword emphasis. Pandoc was previously using this more than necessary. Closes #3068.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/AsciiDoc.hs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs
index 4ac6aa093..0dfbd705e 100644
--- a/src/Text/Pandoc/Writers/AsciiDoc.hs
+++ b/src/Text/Pandoc/Writers/AsciiDoc.hs
@@ -51,6 +51,7 @@ import Control.Monad.State
import qualified Data.Map as M
import Data.Aeson (Value(String), fromJSON, toJSON, Result(..))
import qualified Data.Text as T
+import Data.Char (isSpace, isPunctuation)
data WriterState = WriterState { defListMarker :: String
, orderedListLevel :: Int
@@ -321,6 +322,8 @@ blockListToAsciiDoc :: WriterOptions -- ^ Options
-> State WriterState Doc
blockListToAsciiDoc opts blocks = cat `fmap` mapM (blockToAsciiDoc opts) blocks
+data SpacyLocation = End | Start
+
-- | Convert list of Pandoc inline elements to asciidoc.
inlineListToAsciiDoc :: WriterOptions -> [Inline] -> State WriterState Doc
inlineListToAsciiDoc opts lst = do
@@ -331,14 +334,14 @@ inlineListToAsciiDoc opts lst = do
return result
where go [] = return empty
go (y:x:xs)
- | not (isSpacy y) = do
- y' <- if isSpacy x
+ | not (isSpacy End y) = do
+ y' <- if isSpacy Start x
then inlineToAsciiDoc opts y
else withIntraword $ inlineToAsciiDoc opts y
x' <- withIntraword $ inlineToAsciiDoc opts x
xs' <- go xs
return (y' <> x' <> xs')
- | not (isSpacy x) = do
+ | not (isSpacy Start x) = do
y' <- withIntraword $ inlineToAsciiDoc opts y
xs' <- go (x:xs)
return (y' <> xs')
@@ -346,10 +349,17 @@ inlineListToAsciiDoc opts lst = do
x' <- inlineToAsciiDoc opts x
xs' <- go xs
return (x' <> xs')
- isSpacy Space = True
- isSpacy LineBreak = True
- isSpacy SoftBreak = True
- isSpacy _ = False
+ isSpacy :: SpacyLocation -> Inline -> Bool
+ isSpacy _ Space = True
+ isSpacy _ LineBreak = True
+ isSpacy _ SoftBreak = True
+ -- Note that \W characters count as spacy in AsciiDoc
+ -- for purposes of determining interword:
+ isSpacy End (Str xs) = case reverse xs of
+ c:_ -> isPunctuation c || isSpace c
+ _ -> False
+ isSpacy Start (Str (c:_)) = isPunctuation c || isSpace c
+ isSpacy _ _ = False
setIntraword :: Bool -> State WriterState ()
setIntraword b = modify $ \st -> st{ intraword = b }