aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs25
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs6
2 files changed, 21 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index f0283dd48..1f1258753 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -55,19 +55,26 @@ stringToHtml str = escapePreservingRegex stringToHtmlString (mkRegex "\"|(&[[:al
stringToSmartHtml :: String -> String
stringToSmartHtml =
let escapeDoubleQuotes =
- gsub "(\"|"|'')" "”" . -- rest are right quotes
- gsub "([[:space:]])(\"|")" "\\1“" . -- never right quo after space
- gsub "(\"|"|``)('|`|‘)([^[:punct:][:space:]])" "“‘\\3" . -- "'word left
- gsub "(\"|"|``)([^[:punct:][:space:]])" "“\\2" -- "word left
+ gsub "(\"|")" "”" . -- rest are right quotes
+ gsub "(\"|")(&r[sd]quo;)" "”\\2" . -- never left quo before right quo
+ gsub "(&l[sd]quo;)(\"|")" "\\2“" . -- never right quo after left quo
+ gsub "([ \t])(\"|")" "\\1“" . -- never right quo after space
+ gsub "(\"|")([^,.;:!?^) \t-])" "“\\2" . -- "word left
+ gsub "(\"|")('|`|‘)" "”’" . -- right if it got through last filter
+ gsub "(\"|")('|`|‘)([^,.;:!?^) \t-])" "“‘\\3" . -- "'word left
+ gsub "``" "“" .
+ gsub "''" "”"
escapeSingleQuotes =
gsub "'" "’" . -- otherwise right
- gsub "([[:space:]])'" "\\1‘" . -- never right quo after space
+ gsub "'(&r[sd]quo;)" "’\\1" . -- never left quo before right quo
+ gsub "(&l[sd]quo;)'" "\\1‘" . -- never right quo after left quo
+ gsub "([ \t])'" "\\1‘" . -- never right quo after space
gsub "`" "‘" . -- ` is left
- gsub "([^[:punct:][:space:]])'" "\\1’" . -- word' right
+ gsub "([^,.;:!?^) \t-])'" "\\1’" . -- word' right
+ gsub "^('|`)([^,.;:!?^) \t-])" "‘\\2" . -- 'word left
gsub "('|`)(\"|"|“|``)" "‘“" . -- '"word left
- gsub "^('|`)([^[:punct:][:space:]])" "‘\\2" . -- 'word left
- gsub "([^[:punct:][:space:]])'(s|S)" "\\1’\\2" . -- possessive
- gsub "([[:space:]])'([^[:punct:][:space:]])" "\\1‘\\2" . -- 'word left
+ gsub "([^,.;:!?^) \t-])'(s|S)" "\\1’\\2" . -- possessive
+ gsub "([[:space:]])'([^,.;:!?^) \t-])" "\\1‘\\2" . -- 'word left
gsub "'([0-9][0-9](s|S))" "’\\1" -- '80s - decade abbrevs.
escapeDashes = gsub " ?-- ?" "—" .
gsub " ?--- ?" "—" .
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 13eac31c2..22a96a423 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -63,12 +63,16 @@ escapeLt = gsub "<" "\\\\textless{}"
escapeGt = gsub ">" "\\\\textgreater{}"
escapeDoubleQuotes =
- gsub "\"" "''" . -- rest are right quotes
+ gsub "\"" "''" . -- rest are right quotes .
+ gsub "``\\\\footnote" "''\\\\footnote" . -- except \footnote
+ gsub "\"\\\\" "``\\\\" . -- left quote before latex command
gsub "([[:space:]])\"" "\\1``" . -- never right quote after space
gsub "\"('|`)([^[:punct:][:space:]])" "``{}`\\2" . -- "'word left
gsub "\"([^[:punct:][:space:]])" "``\\1" -- "word left
escapeSingleQuotes =
+ gsub "`\\\\footnote" "'\\\\footnote" . -- except \footnote
+ gsub "'\\\\" "`\\\\" . -- left quote before latex command
gsub "('|`)(\"|``)" "`{}``" . -- '"word left
gsub "([^[:punct:][:space:]])`(s|S)" "\\1'\\2" . -- catch possessives
gsub "^'([^[:punct:][:space:]])" "`\\1" . -- 'word left