aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Parsing.hs34
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs3
-rw-r--r--src/pandoc.hs10
3 files changed, 41 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index c2c512033..71da3a730 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -614,6 +614,9 @@ data ParserState = ParserState
stateDate :: [Inline], -- ^ Date of document
stateStrict :: Bool, -- ^ Use strict markdown syntax?
stateSmart :: Bool, -- ^ Use smart typography?
+ stateOldDashes :: Bool, -- ^ Use pandoc <= 1.8.2.1 behavior
+ -- in parsing dashes; -- is em-dash;
+ -- before numeral is en-dash
stateLiterateHaskell :: Bool, -- ^ Treat input as literate haskell
stateColumns :: Int, -- ^ Number of columns in terminal
stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
@@ -642,6 +645,7 @@ defaultParserState =
stateDate = [],
stateStrict = False,
stateSmart = False,
+ stateOldDashes = False,
stateLiterateHaskell = False,
stateColumns = 80,
stateHeaderTable = [],
@@ -788,17 +792,37 @@ ellipses = do
try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
return (Str "\8230")
-dash :: GenParser Char st Inline
-dash = enDash <|> emDash
+dash :: GenParser Char ParserState Inline
+dash = do
+ oldDashes <- stateOldDashes `fmap` getState
+ if oldDashes
+ then emDashOld <|> enDashOld
+ else Str `fmap` (hyphenDash <|> emDash <|> enDash)
-enDash :: GenParser Char st Inline
+-- Two hyphens = en-dash, three = em-dash
+hyphenDash :: GenParser Char st String
+hyphenDash = do
+ try $ string "--"
+ option "\8211" (char '-' >> return "\8212")
+
+emDash :: GenParser Char st String
+emDash = do
+ try (charOrRef "\8212\151")
+ return "\8212"
+
+enDash :: GenParser Char st String
enDash = do
+ try (charOrRef "\8212\151")
+ return "\8211"
+
+enDashOld :: GenParser Char st Inline
+enDashOld = do
try (charOrRef "\8211\150") <|>
try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
return (Str "\8211")
-emDash :: GenParser Char st Inline
-emDash = do
+emDashOld :: GenParser Char st Inline
+emDashOld = do
try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
return (Str "\8212")
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index 4693bd06d..3b5954368 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -68,7 +68,8 @@ import Control.Monad ( guard, liftM )
readTextile :: ParserState -- ^ Parser state, including options for parser
-> String -- ^ String to parse (assuming @'\n'@ line endings)
-> Pandoc
-readTextile state s = (readWith parseTextile) state (s ++ "\n\n")
+readTextile state s =
+ (readWith parseTextile) state{ stateOldDashes = True } (s ++ "\n\n")
--
diff --git a/src/pandoc.hs b/src/pandoc.hs
index fc28c4c3f..3660fc167 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -103,6 +103,7 @@ data Opt = Opt
, optSelfContained :: Bool -- ^ Make HTML accessible offline
, optXeTeX :: Bool -- ^ Format latex for xetex
, optSmart :: Bool -- ^ Use smart typography
+ , optOldDashes :: Bool -- ^ Parse dashes like pandoc <=1.8.2.1
, optHtml5 :: Bool -- ^ Produce HTML5 in HTML
, optHighlight :: Bool -- ^ Highlight source code
, optHighlightStyle :: Style -- ^ Style to use for highlighted code
@@ -149,6 +150,7 @@ defaultOpts = Opt
, optSelfContained = False
, optXeTeX = False
, optSmart = False
+ , optOldDashes = False
, optHtml5 = False
, optHighlight = True
, optHighlightStyle = pygments
@@ -245,6 +247,12 @@ options =
(\opt -> return opt { optSmart = True }))
"" -- "Use smart quotes, dashes, and ellipses"
+ , Option "" ["old-dashes"]
+ (NoArg
+ (\opt -> return opt { optSmart = True
+ , optOldDashes = True }))
+ "" -- "Use smart quotes, dashes, and ellipses"
+
, Option "5" ["html5"]
(NoArg
(\opt -> do
@@ -735,6 +743,7 @@ main = do
, optIncremental = incremental
, optSelfContained = selfContained
, optSmart = smart
+ , optOldDashes = oldDashes
, optHtml5 = html5
, optHighlight = highlight
, optHighlightStyle = highlightStyle
@@ -858,6 +867,7 @@ main = do
stateCitations = map CSL.refId refs,
stateSmart = smart || writerName' `elem`
["latex", "context", "latex+lhs", "beamer"],
+ stateOldDashes = oldDashes,
stateColumns = columns,
stateStrict = strict,
stateIndentedCodeClasses = codeBlockClasses,