aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-16 06:14:37 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-16 06:14:37 +0000
commit19bad8253d14b2f9f9919ddf547ce90f9b92d8b3 (patch)
tree67f8c935705dbd13026b9076e50a4b33e2f81205
parentfe66a90a2a88c66b1d518a932f29d9225e31ab8f (diff)
downloadpandoc-19bad8253d14b2f9f9919ddf547ce90f9b92d8b3.tar.gz
Improvements to smart-quote regexs. Now we can better handle
cases where latex commands or HTML entity references appear after quotes. git-svn-id: https://pandoc.googlecode.com/svn/trunk@202 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--TODO2
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs25
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs6
3 files changed, 21 insertions, 12 deletions
diff --git a/TODO b/TODO
index ee710a070..5264b8a67 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
# TODO
-* Fix bug in latex reader? "... gets converted the wrong way.
-
* Use XHTML library for HTML writer?
* Revisions for building with windows under cygwin:
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 "(\"|&quot;|'')" "&rdquo;" . -- rest are right quotes
- gsub "([[:space:]])(\"|&quot;)" "\\1&ldquo;" . -- never right quo after space
- gsub "(\"|&quot;|``)('|`|&lsquo;)([^[:punct:][:space:]])" "&ldquo;&lsquo;\\3" . -- "'word left
- gsub "(\"|&quot;|``)([^[:punct:][:space:]])" "&ldquo;\\2" -- "word left
+ gsub "(\"|&quot;)" "&rdquo;" . -- rest are right quotes
+ gsub "(\"|&quot;)(&r[sd]quo;)" "&rdquo;\\2" . -- never left quo before right quo
+ gsub "(&l[sd]quo;)(\"|&quot;)" "\\2&ldquo;" . -- never right quo after left quo
+ gsub "([ \t])(\"|&quot;)" "\\1&ldquo;" . -- never right quo after space
+ gsub "(\"|&quot;)([^,.;:!?^) \t-])" "&ldquo;\\2" . -- "word left
+ gsub "(\"|&quot;)('|`|&lsquo;)" "&rdquo;&rsquo;" . -- right if it got through last filter
+ gsub "(\"|&quot;)('|`|&lsquo;)([^,.;:!?^) \t-])" "&ldquo;&lsquo;\\3" . -- "'word left
+ gsub "``" "&ldquo;" .
+ gsub "''" "&rdquo;"
escapeSingleQuotes =
gsub "'" "&rsquo;" . -- otherwise right
- gsub "([[:space:]])'" "\\1&lsquo;" . -- never right quo after space
+ gsub "'(&r[sd]quo;)" "&rsquo;\\1" . -- never left quo before right quo
+ gsub "(&l[sd]quo;)'" "\\1&lsquo;" . -- never right quo after left quo
+ gsub "([ \t])'" "\\1&lsquo;" . -- never right quo after space
gsub "`" "&lsquo;" . -- ` is left
- gsub "([^[:punct:][:space:]])'" "\\1&rsquo;" . -- word' right
+ gsub "([^,.;:!?^) \t-])'" "\\1&rsquo;" . -- word' right
+ gsub "^('|`)([^,.;:!?^) \t-])" "&lsquo;\\2" . -- 'word left
gsub "('|`)(\"|&quot;|&ldquo;|``)" "&lsquo;&ldquo;" . -- '"word left
- gsub "^('|`)([^[:punct:][:space:]])" "&lsquo;\\2" . -- 'word left
- gsub "([^[:punct:][:space:]])'(s|S)" "\\1&rsquo;\\2" . -- possessive
- gsub "([[:space:]])'([^[:punct:][:space:]])" "\\1&lsquo;\\2" . -- 'word left
+ gsub "([^,.;:!?^) \t-])'(s|S)" "\\1&rsquo;\\2" . -- possessive
+ gsub "([[:space:]])'([^,.;:!?^) \t-])" "\\1&lsquo;\\2" . -- 'word left
gsub "'([0-9][0-9](s|S))" "&rsquo;\\1" -- '80s - decade abbrevs.
escapeDashes = gsub " ?-- ?" "&mdash;" .
gsub " ?--- ?" "&mdash;" .
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