Implemented +/-smart in rst writer.
Moved unsmartify to Writers.Shared.
This commit is contained in:
parent
1feddee6d6
commit
8418c1a7d7
3 changed files with 29 additions and 15 deletions
|
@ -1136,15 +1136,3 @@ makeMathPlainer = walk go
|
|||
go (Emph xs) = Span nullAttr xs
|
||||
go x = x
|
||||
|
||||
unsmartify :: WriterOptions -> String -> String
|
||||
unsmartify opts ('\8217':xs) = '\'' : unsmartify opts xs
|
||||
unsmartify opts ('\8230':xs) = "..." ++ unsmartify opts xs
|
||||
unsmartify opts ('\8211':xs)
|
||||
| isEnabled Ext_old_dashes opts = '-' : unsmartify opts xs
|
||||
| otherwise = "--" ++ unsmartify opts xs
|
||||
unsmartify opts ('\8212':xs)
|
||||
| isEnabled Ext_old_dashes opts = "--" ++ unsmartify opts xs
|
||||
| otherwise = "---" ++ unsmartify opts xs
|
||||
unsmartify opts (x:xs) = x : unsmartify opts xs
|
||||
unsmartify _ [] = []
|
||||
|
||||
|
|
|
@ -432,14 +432,25 @@ inlineToRST (Subscript lst) = do
|
|||
inlineToRST (SmallCaps lst) = inlineListToRST lst
|
||||
inlineToRST (Quoted SingleQuote lst) = do
|
||||
contents <- inlineListToRST lst
|
||||
return $ "‘" <> contents <> "’"
|
||||
opts <- gets stOptions
|
||||
if isEnabled Ext_smart opts
|
||||
then return $ "'" <> contents <> "'"
|
||||
else return $ "‘" <> contents <> "’"
|
||||
inlineToRST (Quoted DoubleQuote lst) = do
|
||||
contents <- inlineListToRST lst
|
||||
return $ "“" <> contents <> "”"
|
||||
opts <- gets stOptions
|
||||
if isEnabled Ext_smart opts
|
||||
then return $ "\"" <> contents <> "\""
|
||||
else return $ "“" <> contents <> "”"
|
||||
inlineToRST (Cite _ lst) =
|
||||
inlineListToRST lst
|
||||
inlineToRST (Code _ str) = return $ "``" <> text str <> "``"
|
||||
inlineToRST (Str str) = return $ text $ escapeString str
|
||||
inlineToRST (Str str) = do
|
||||
opts <- gets stOptions
|
||||
let str' = if isEnabled Ext_smart opts
|
||||
then unsmartify opts str
|
||||
else str
|
||||
return $ text $ escapeString str'
|
||||
inlineToRST (Math t str) = do
|
||||
modify $ \st -> st{ stHasMath = True }
|
||||
return $ if t == InlineMath
|
||||
|
|
|
@ -35,10 +35,12 @@ module Text.Pandoc.Writers.Shared (
|
|||
, defField
|
||||
, tagWithAttrs
|
||||
, fixDisplayMath
|
||||
, unsmartify
|
||||
)
|
||||
where
|
||||
import Text.Pandoc.Definition
|
||||
import Text.Pandoc.Pretty
|
||||
import Text.Pandoc.Options
|
||||
import Text.Pandoc.XML (escapeStringForXML)
|
||||
import Control.Monad (liftM)
|
||||
import Text.Pandoc.Options (WriterOptions(..))
|
||||
|
@ -167,3 +169,16 @@ fixDisplayMath (Para lst)
|
|||
groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
|
||||
not (isDisplayMath x || isDisplayMath y)) lst
|
||||
fixDisplayMath x = x
|
||||
|
||||
unsmartify :: WriterOptions -> String -> String
|
||||
unsmartify opts ('\8217':xs) = '\'' : unsmartify opts xs
|
||||
unsmartify opts ('\8230':xs) = "..." ++ unsmartify opts xs
|
||||
unsmartify opts ('\8211':xs)
|
||||
| isEnabled Ext_old_dashes opts = '-' : unsmartify opts xs
|
||||
| otherwise = "--" ++ unsmartify opts xs
|
||||
unsmartify opts ('\8212':xs)
|
||||
| isEnabled Ext_old_dashes opts = "--" ++ unsmartify opts xs
|
||||
| otherwise = "---" ++ unsmartify opts xs
|
||||
unsmartify opts (x:xs) = x : unsmartify opts xs
|
||||
unsmartify _ [] = []
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue