@@ -169,21 +169,24 @@ pictToRST (label, (attr, src, _, mbtarget)) = do
169169
170170-- | Escape special characters for RST.
171171escapeString :: WriterOptions -> String -> String
172−escapeString _ [] = []
173−escapeString opts (c:cs) =
174− case c of
175− _ | c `elem` ['\\','`','*','_','|'] -> '\\':c:escapeString opts cs
176− '\'' | isEnabled Ext_smart opts -> '\\':'\'':escapeString opts cs
177− '"' | isEnabled Ext_smart opts -> '\\':'"':escapeString opts cs
178− '-' | isEnabled Ext_smart opts ->
179− case cs of
180− '-':_ -> '\\':'-':escapeString opts cs
181− _ -> '-':escapeString opts cs
182− '.' | isEnabled Ext_smart opts ->
183− case cs of
184− '.':'.':rest -> '\\':'.':'.':'.':escapeString opts rest
185− _ -> '.':escapeString opts cs
186− _ -> c : escapeString opts cs
172+escapeString = escapeString' True
173+ where
174+ escapeString' _ _ [] = []
175+ escapeString' firstChar opts (c:cs) =
176+ case c of
177+ _ | c `elem` ['\\','`','*','_','|'] &&
178+ (firstChar || null cs) -> '\\':c:escapeString' False opts cs
179+ '\'' | isEnabled Ext_smart opts -> '\\':'\'':escapeString' False opts cs
180+ '"' | isEnabled Ext_smart opts -> '\\':'"':escapeString' False opts cs
181+ '-' | isEnabled Ext_smart opts ->
182+ case cs of
183+ '-':_ -> '\\':'-':escapeString' False opts cs
184+ _ -> '-':escapeString' False opts cs
185+ '.' | isEnabled Ext_smart opts ->
186+ case cs of
187+ '.':'.':rest -> '\\':'.':'.':'.':escapeString' False opts rest
188+ _ -> '.':escapeString' False opts cs
189+ _ -> c : escapeString' False opts cs
187190
188191titleToRST :: PandocMonad m => [Inline] -> [Inline] -> RST m Doc
189192titleToRST [] _ = return empty