git.iko.soy/typeable/pandoc
on master help sign in
More smart quote bug fixes:

+ LaTeX writer now handles consecutive quotes properly: for example, ``\,`hello'\,'' + LaTeX reader now parses '\,' as empty Str + normalizeSpaces function in Shared now removes empty Str elements + Modified tests accordingly git-svn-id: https://pandoc.googlecode.com/svn/trunk@506 788f1e2b-df1e-0410-8736-df70ead52e1b

commit96919a6ac5c21a8b46fbc347a4d815f0c9c89b98 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateWed 24 Jan 2007, 08:14 (20 years ago) parente6cc2aa
4 files changed+22−6
src/Text/Pandoc/Readers/LaTeX.hs+6−1 src/Text/Pandoc/Shared.hs+3−1 src/Text/Pandoc/Writers/LaTeX.hs+11−2 tests/writer.latex+2−2
src/Text/Pandoc/Readers/LaTeX.hs+6−1
@@ -381,7 +381,8 @@ comment = try (do
381381-- inline
382382--
383383
384−inline = choice [ strong, emph, ref, lab, code, linebreak, math, ellipses,
384+inline = choice [ strong, emph, ref, lab, code, linebreak, spacer,
385+ math, ellipses,
385386 emDash, enDash, hyphen, quoted, apostrophe,
386387 accentedChar, specialChar, specialInline, escapedChar,
387388 unescapedChar, str, endline, whitespace ] <?> "inline"
@@ -579,6 +580,10 @@ linebreak = try (do
579580 string "\\\\"
580581 return LineBreak)
581582
583+spacer = try $ do
584+ string "\\,"
585+ return (Str "")
586+
582587str = do
583588 result <- many1 (noneOf specialChars)
584589 return (Str result)
src/Text/Pandoc/Shared.hs+3−1
@@ -306,12 +306,14 @@ splitByIndices (x:xs) lst =
306306 first:(splitByIndices (map (\y -> y - x) xs) rest)
307307
308308-- | Normalize a list of inline elements: remove leading and trailing
309−-- @Space@ elements, and collapse double @Space@s into singles.
309+-- @Space@ elements, collapse double @Space@s into singles, and
310+-- remove empty Str elements.
310311normalizeSpaces :: [Inline] -> [Inline]
311312normalizeSpaces [] = []
312313normalizeSpaces list =
313314 let removeDoubles [] = []
314315 removeDoubles (Space:Space:rest) = removeDoubles (Space:rest)
316+ removeDoubles ((Str ""):rest) = removeDoubles rest
315317 removeDoubles (x:rest) = x:(removeDoubles rest) in
316318 let removeLeading [] = []
317319 removeLeading lst = if ((head lst) == Space)
src/Text/Pandoc/Writers/LaTeX.hs+11−2
@@ -166,6 +166,11 @@ inlineListToLaTeX :: [Block] -- ^ List of note blocks to use in resolving note
166166inlineListToLaTeX notes lst =
167167 concatMap (inlineToLaTeX notes) lst
168168
169+isQuoted :: Inline -> Bool
170+isQuoted (Quoted _ _) = True
171+isQuoted Apostrophe = True
172+isQuoted _ = False
173+
169174-- | Convert inline element to LaTeX
170175inlineToLaTeX :: [Block] -- ^ List of note blocks to use in resolving note refs
171176 -> Inline -- ^ Inline to convert
@@ -178,9 +183,13 @@ inlineToLaTeX notes (Code str) = "\\verb" ++ [chr] ++ stuffing ++ [chr]
178183 where stuffing = str
179184 chr = ((enumFromTo '!' '~') \\ stuffing) !! 0
180185inlineToLaTeX notes (Quoted SingleQuote lst) =
181− "`" ++ inlineListToLaTeX notes lst ++ "'"
186+ let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
187+ s2 = if (not (null lst)) && (isQuoted (last lst)) then "\\," else "" in
188+ "`" ++ s1 ++ inlineListToLaTeX notes lst ++ s2 ++ "'"
182189inlineToLaTeX notes (Quoted DoubleQuote lst) =
183− "``" ++ inlineListToLaTeX notes lst ++ "''"
190+ let s1 = if (not (null lst)) && (isQuoted (head lst)) then "\\," else ""
191+ s2 = if (not (null lst)) && (isQuoted (last lst)) then "\\," else "" in
192+ "``" ++ s1 ++ inlineListToLaTeX notes lst ++ s2 ++ "''"
184193inlineToLaTeX notes Apostrophe = "'"
185194inlineToLaTeX notes EmDash = "---"
186195inlineToLaTeX notes EnDash = "--"
tests/writer.latex+2−2
@@ -377,13 +377,13 @@ This is code: \verb!>!, \verb!$!, \verb!\!, \verb!\$!, \verb!<html>!.
377377
378378\section{Smart quotes, ellipses, dashes}
379379
380−``Hello,'' said the spider. ```Shelob' is my name.''
380+``Hello,'' said the spider. ``\,`Shelob' is my name.''
381381
382382`A', `B', and `C' are letters.
383383
384384`Oak,' `elm,' and `beech' are names of trees. So is `pine.'
385385
386−`He said, ``I want to go.''' Were you alive in the 70's?
386+`He said, ``I want to go.''\,' Were you alive in the 70's?
387387
388388Here is some quoted `\verb!code!' and a ``\href{http://example.com/?foo=1&bar=2}{quoted link}''.
389389