diff options
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 22 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 2 | ||||
| -rw-r--r-- | test/command/10781.md | 8 | ||||
| -rw-r--r-- | test/command/3958.md | 2 |
4 files changed, 28 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 03d258545..04a2ec801 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -343,6 +343,12 @@ inlineCommands = M.unions , biblatexInlineCommands tok , rest ] where + disableLigatures p = do + oldLigatures <- sLigatures <$> getState + updateState (\s -> s{ sLigatures = False }) + res <- p + updateState (\s -> s{ sLigatures = oldLigatures }) + pure res rest = M.fromList [ ("emph", extractSpaces emph <$> tok) , ("textit", extractSpaces emph <$> tok) @@ -352,7 +358,7 @@ inlineCommands = M.unions , ("textmd", extractSpaces (spanWith ("",["medium"],[])) <$> tok) , ("textrm", extractSpaces (spanWith ("",["roman"],[])) <$> tok) , ("textup", extractSpaces (spanWith ("",["upright"],[])) <$> tok) - , ("texttt", formatCode nullAttr <$> tok) + , ("texttt", formatCode nullAttr <$> disableLigatures tok) , ("alert", skipopts >> spanWith ("",["alert"],[]) <$> tok) -- beamer , ("textsuperscript", extractSpaces superscript <$> tok) , ("textsubscript", extractSpaces subscript <$> tok) @@ -634,6 +640,7 @@ inline = do do eatOneToken report $ ParsingUnescaped t pos return $ str t + ligatures <- sLigatures <$> getState case toktype of Comment -> mempty <$ eatOneToken Spaces -> space <$ eatOneToken @@ -641,14 +648,19 @@ inline = do Word -> str t <$ eatOneToken Symbol -> case t of - "-" -> eatOneToken *> + "-" | ligatures + -> eatOneToken *> option (str "-") (symbol '-' *> option (str "–") (str "—" <$ symbol '-')) "'" -> eatOneToken *> - option (str "’") (str "”" <$ symbol '\'') + option (str "’") (str "”" <$ (guard ligatures *> symbol '\'')) "~" -> str "\160" <$ eatOneToken - "`" -> doubleQuote <|> singleQuote <|> symbolAsString - "\"" -> doubleQuote <|> singleQuote <|> symbolAsString + "`" | ligatures + -> doubleQuote <|> singleQuote <|> (str "‘" <$ symbol '`') + | otherwise + -> str "‘" <$ symbol '`' + "\"" | ligatures + -> doubleQuote <|> singleQuote <|> symbolAsString "“" -> doubleQuote <|> symbolAsString "‘" -> singleQuote <|> symbolAsString "$" -> dollarsMath <|> unescapedSymbolAsString diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index 3c7577523..62c858282 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -173,6 +173,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions , sFileContents :: M.Map Text Text , sEnableWithRaw :: Bool , sRawTokens :: IntMap.IntMap [Tok] + , sLigatures :: Bool } deriving Show @@ -201,6 +202,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def , sFileContents = M.empty , sEnableWithRaw = True , sRawTokens = IntMap.empty + , sLigatures = True } instance PandocMonad m => HasQuoteContext LaTeXState m where diff --git a/test/command/10781.md b/test/command/10781.md new file mode 100644 index 000000000..71860afd2 --- /dev/null +++ b/test/command/10781.md @@ -0,0 +1,8 @@ +``` +% pandoc -f latex -t markdown --wrap=preserve +This is \texttt{--flag} with dashes. +This is the same --flag without a code. +^D +This is `--flag` with dashes. +This is the same --flag without a code. +``` diff --git a/test/command/3958.md b/test/command/3958.md index eccf632c4..67f550f0b 100644 --- a/test/command/3958.md +++ b/test/command/3958.md @@ -9,7 +9,7 @@ % pandoc -f latex -t native \texttt{``hi''} ^D -[ Para [ Code ( "" , [] , [] ) "\8220hi\8221" ] ] +[ Para [ Code ( "" , [] , [] ) "\8216\8216hi\8217\8217" ] ] ``` ``` |
