git.iko.soy/typeable/pandoc
on master help sign in
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.

commit46d8b42da5d42b981bc56c49416cec15abaf2d09 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 2 Oct 2016, 21:51 (10 years ago) parenta99d81d
2 files changed+21−11
src/Text/Pandoc/Writers/AsciiDoc.hs+17−7 tests/writer.asciidoc+4−4
src/Text/Pandoc/Writers/AsciiDoc.hs+17−7
@@ -51,6 +51,7 @@ import Control.Monad.State
5151import qualified Data.Map as M
5252import Data.Aeson (Value(String), fromJSON, toJSON, Result(..))
5353import qualified Data.Text as T
54+import Data.Char (isSpace, isPunctuation)
5455
5556data WriterState = WriterState { defListMarker :: String
5657 , orderedListLevel :: Int
@@ -321,6 +322,8 @@ blockListToAsciiDoc :: WriterOptions -- ^ Options
321322 -> State WriterState Doc
322323blockListToAsciiDoc opts blocks = cat `fmap` mapM (blockToAsciiDoc opts) blocks
323324
325+data SpacyLocation = End | Start
326+
324327-- | Convert list of Pandoc inline elements to asciidoc.
325328inlineListToAsciiDoc :: WriterOptions -> [Inline] -> State WriterState Doc
326329inlineListToAsciiDoc opts lst = do
@@ -331,14 +334,14 @@ inlineListToAsciiDoc opts lst = do
331334 return result
332335 where go [] = return empty
333336 go (y:x:xs)
334− | not (isSpacy y) = do
335− y' <- if isSpacy x
337+ | not (isSpacy End y) = do
338+ y' <- if isSpacy Start x
336339 then inlineToAsciiDoc opts y
337340 else withIntraword $ inlineToAsciiDoc opts y
338341 x' <- withIntraword $ inlineToAsciiDoc opts x
339342 xs' <- go xs
340343 return (y' <> x' <> xs')
341− | not (isSpacy x) = do
344+ | not (isSpacy Start x) = do
342345 y' <- withIntraword $ inlineToAsciiDoc opts y
343346 xs' <- go (x:xs)
344347 return (y' <> xs')
@@ -346,10 +349,17 @@ inlineListToAsciiDoc opts lst = do
346349 x' <- inlineToAsciiDoc opts x
347350 xs' <- go xs
348351 return (x' <> xs')
349− isSpacy Space = True
350− isSpacy LineBreak = True
351− isSpacy SoftBreak = True
352− isSpacy _ = False
352+ isSpacy :: SpacyLocation -> Inline -> Bool
353+ isSpacy _ Space = True
354+ isSpacy _ LineBreak = True
355+ isSpacy _ SoftBreak = True
356+ -- Note that \W characters count as spacy in AsciiDoc
357+ -- for purposes of determining interword:
358+ isSpacy End (Str xs) = case reverse xs of
359+ c:_ -> isPunctuation c || isSpace c
360+ _ -> False
361+ isSpacy Start (Str (c:_)) = isPunctuation c || isSpace c
362+ isSpacy _ _ = False
353363
354364setIntraword :: Bool -> State WriterState ()
355365setIntraword b = modify $ \st -> st{ intraword = b }
tests/writer.asciidoc+4−4
@@ -435,11 +435,11 @@ Hr’s:
435435Inline Markup
436436-------------
437437
438−This is __emphasized__, and so __is this__.
438+This is _emphasized_, and so _is this_.
439439
440−This is **strong**, and so **is this**.
440+This is *strong*, and so *is this*.
441441
442−An __link:/url[emphasized link]__.
442+An _link:/url[emphasized link]_.
443443
444444*_This is strong and em._*
445445
@@ -451,7 +451,7 @@ So is *_this_* word.
451451
452452This is code: `>`, `$`, `\`, `\$`, `<html>`.
453453
454−[line-through]*This is __strikeout__.*
454+[line-through]*This is _strikeout_.*
455455
456456Superscripts: a^bc^d a^_hello_^ a^hello there^.
457457