aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README3
-rw-r--r--Text/Pandoc/Readers/Markdown.hs5
-rw-r--r--Text/Pandoc/Writers/ConTeXt.hs29
-rw-r--r--Text/Pandoc/Writers/LaTeX.hs1
-rw-r--r--Text/Pandoc/Writers/Texinfo.hs1
-rw-r--r--tests/testsuite.native4
-rw-r--r--tests/writer.context4
-rw-r--r--tests/writer.docbook5
-rw-r--r--tests/writer.html4
-rw-r--r--tests/writer.latex4
-rw-r--r--tests/writer.man4
-rw-r--r--tests/writer.markdown4
-rw-r--r--tests/writer.native4
-rw-r--r--tests/writer.rst4
-rw-r--r--tests/writer.rtf4
-rw-r--r--tests/writer.texinfo4
16 files changed, 47 insertions, 37 deletions
diff --git a/README b/README
index 43a8deff9..43ecaeb6a 100644
--- a/README
+++ b/README
@@ -435,6 +435,9 @@ which allows only the following characters to be backslash-escaped:
\`*_{}[]()>#+-.!
+A backslash-escaped space is parsed as a nonbreaking space. It will
+appear in TeX output as '~' and in HTML and XML as '\ ' or '\ '.
+
Subscripts and superscripts
---------------------------
diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs
index 7c4a778fe..c9fbbe2d9 100644
--- a/Text/Pandoc/Readers/Markdown.hs
+++ b/Text/Pandoc/Readers/Markdown.hs
@@ -733,7 +733,10 @@ escapedChar = do
result <- option '\\' $ if stateStrict state
then oneOf "\\`*_{}[]()>#+-.!~"
else satisfy (not . isAlphaNum)
- return $ Str [result]
+ let result' = if result == ' '
+ then '\160' -- '\ ' is a nonbreaking space
+ else result
+ return $ Str [result']
ltSign = do
st <- getState
diff --git a/Text/Pandoc/Writers/ConTeXt.hs b/Text/Pandoc/Writers/ConTeXt.hs
index 1695d70e7..35314758a 100644
--- a/Text/Pandoc/Writers/ConTeXt.hs
+++ b/Text/Pandoc/Writers/ConTeXt.hs
@@ -102,20 +102,21 @@ contextHeader options (Meta title authors date) = do
escapeCharForConTeXt :: Char -> String
escapeCharForConTeXt ch =
case ch of
- '{' -> "\\letteropenbrace{}"
- '}' -> "\\letterclosebrace{}"
- '\\' -> "\\letterbackslash{}"
- '$' -> "\\$"
- '|' -> "\\letterbar{}"
- '^' -> "\\letterhat{}"
- '%' -> "\\%"
- '~' -> "\\lettertilde{}"
- '&' -> "\\&"
- '#' -> "\\#"
- '<' -> "\\letterless{}"
- '>' -> "\\lettermore{}"
- '_' -> "\\letterunderscore{}"
- x -> [x]
+ '{' -> "\\letteropenbrace{}"
+ '}' -> "\\letterclosebrace{}"
+ '\\' -> "\\letterbackslash{}"
+ '$' -> "\\$"
+ '|' -> "\\letterbar{}"
+ '^' -> "\\letterhat{}"
+ '%' -> "\\%"
+ '~' -> "\\lettertilde{}"
+ '&' -> "\\&"
+ '#' -> "\\#"
+ '<' -> "\\letterless{}"
+ '>' -> "\\lettermore{}"
+ '_' -> "\\letterunderscore{}"
+ '\160' -> "~"
+ x -> [x]
-- | Escape string for ConTeXt
stringToConTeXt :: String -> String
diff --git a/Text/Pandoc/Writers/LaTeX.hs b/Text/Pandoc/Writers/LaTeX.hs
index a2e6eec2c..686e98cf4 100644
--- a/Text/Pandoc/Writers/LaTeX.hs
+++ b/Text/Pandoc/Writers/LaTeX.hs
@@ -116,6 +116,7 @@ stringToLaTeX = escapeStringUsing latexEscapes
, ('|', "\\textbar{}")
, ('<', "\\textless{}")
, ('>', "\\textgreater{}")
+ , ('\160', "~")
]
-- | Puts contents into LaTeX command.
diff --git a/Text/Pandoc/Writers/Texinfo.hs b/Text/Pandoc/Writers/Texinfo.hs
index ac8778274..513fae847 100644
--- a/Text/Pandoc/Writers/Texinfo.hs
+++ b/Text/Pandoc/Writers/Texinfo.hs
@@ -123,6 +123,7 @@ stringToTexinfo = escapeStringUsing texinfoEscapes
, ('}', "@}")
, ('@', "@@")
, (',', "@comma{}") -- only needed in argument lists
+ , ('\160', "@ ")
]
-- | Puts contents into Texinfo command.
diff --git a/tests/testsuite.native b/tests/testsuite.native
index 34d51df5d..d3c4835ed 100644
--- a/tests/testsuite.native
+++ b/tests/testsuite.native
@@ -265,8 +265,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
, Para [Str "So",Space,Str "is",Space,Strong [Emph [Str "this"]],Space,Str "word",Str "."]
, Para [Str "This",Space,Str "is",Space,Str "code:",Space,Code ">",Str ",",Space,Code "$",Str ",",Space,Code "\\",Str ",",Space,Code "\\$",Str ",",Space,Code "<html>",Str "."]
, Para [Strikeout [Str "This",Space,Str "is",Space,Emph [Str "strikeout"],Str "."]]
-, Para [Str "Superscripts:",Space,Str "a",Superscript [Str "bc"],Str "d",Space,Str "a",Superscript [Emph [Str "hello"]],Space,Str "a",Superscript [Str "hello",Str " ",Str "there"],Str "."]
-, Para [Str "Subscripts:",Space,Str "H",Subscript [Str "2"],Str "O,",Space,Str "H",Subscript [Str "23"],Str "O,",Space,Str "H",Subscript [Str "many",Str " ",Str "of",Str " ",Str "them"],Str "O",Str "."]
+, Para [Str "Superscripts:",Space,Str "a",Superscript [Str "bc"],Str "d",Space,Str "a",Superscript [Emph [Str "hello"]],Space,Str "a",Superscript [Str "hello",Str "\160",Str "there"],Str "."]
+, Para [Str "Subscripts:",Space,Str "H",Subscript [Str "2"],Str "O,",Space,Str "H",Subscript [Str "23"],Str "O,",Space,Str "H",Subscript [Str "many",Str "\160",Str "of",Str "\160",Str "them"],Str "O",Str "."]
, Para [Str "These",Space,Str "should",Space,Str "not",Space,Str "be",Space,Str "superscripts",Space,Str "or",Space,Str "subscripts,",Space,Str "because",Space,Str "of",Space,Str "the",Space,Str "unescaped",Space,Str "spaces:",Space,Str "a",Str "^",Str "b",Space,Str "c",Str "^",Str "d,",Space,Str "a",Str "~",Str "b",Space,Str "c",Str "~",Str "d",Str "."]
, HorizontalRule
, Header 1 [Str "Smart",Space,Str "quotes,",Space,Str "ellipses,",Space,Str "dashes"]
diff --git a/tests/writer.context b/tests/writer.context
index 47298d340..7c9678636 100644
--- a/tests/writer.context
+++ b/tests/writer.context
@@ -590,9 +590,9 @@ This is code: \type{>}, \type{$}, \type{\}, \type{\$},
\overstrikes{This is {\em strikeout}.}
-Superscripts: a\high{bc}d a\high{{\em hello}} a\high{hello there}.
+Superscripts: a\high{bc}d a\high{{\em hello}} a\high{hello~there}.
-Subscripts: H\low{2}O, H\low{23}O, H\low{many of them}O.
+Subscripts: H\low{2}O, H\low{23}O, H\low{many~of~them}O.
These should not be superscripts or subscripts, because of the
unescaped spaces: a\letterhat{}b c\letterhat{}d, a\lettertilde{}b
diff --git a/tests/writer.docbook b/tests/writer.docbook
index d4a48cb8b..ad774f685 100644
--- a/tests/writer.docbook
+++ b/tests/writer.docbook
@@ -795,11 +795,12 @@ These should not be escaped: \$ \\ \&gt; \[ \{
<para>
Superscripts: a<superscript>bc</superscript>d
a<superscript><emphasis>hello</emphasis></superscript>
- a<superscript>hello there</superscript>.
+ a<superscript>hello&nbsp;there</superscript>.
</para>
<para>
Subscripts: H<subscript>2</subscript>O,
- H<subscript>23</subscript>O, H<subscript>many of them</subscript>O.
+ H<subscript>23</subscript>O,
+ H<subscript>many&nbsp;of&nbsp;them</subscript>O.
</para>
<para>
These should not be superscripts or subscripts, because of the
diff --git a/tests/writer.html b/tests/writer.html
index 3ed9884ad..49bf3a691 100644
--- a/tests/writer.html
+++ b/tests/writer.html
@@ -678,7 +678,7 @@ Blah
>hello</em
></sup
> a<sup
- >hello there</sup
+ >hello&#160;there</sup
>.</p
><p
>Subscripts: H<sub
@@ -686,7 +686,7 @@ Blah
>O, H<sub
>23</sub
>O, H<sub
- >many of them</sub
+ >many&#160;of&#160;them</sub
>O.</p
><p
>These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.</p
diff --git a/tests/writer.latex b/tests/writer.latex
index 0da95f679..053daaeed 100644
--- a/tests/writer.latex
+++ b/tests/writer.latex
@@ -527,10 +527,10 @@ This is code: \verb!>!, \verb!$!, \verb!\!, \verb!\$!,
\sout{This is \emph{strikeout}.}
Superscripts: a\textsuperscript{bc}d
-a\textsuperscript{\emph{hello}} a\textsuperscript{hello there}.
+a\textsuperscript{\emph{hello}} a\textsuperscript{hello~there}.
Subscripts: H\textsubscr{2}O, H\textsubscr{23}O,
-H\textsubscr{many of them}O.
+H\textsubscr{many~of~them}O.
These should not be superscripts or subscripts, because of the
unescaped spaces: a\^{}b c\^{}d, a\ensuremath{\sim}b
diff --git a/tests/writer.man b/tests/writer.man
index 1e429a2a6..010d6c33d 100644
--- a/tests/writer.man
+++ b/tests/writer.man
@@ -516,9 +516,9 @@ This is code: \f[B]>\f[], \f[B]$\f[], \f[B]\\\f[], \f[B]\\$\f[],
.PP
[STRIKEOUT:This is \f[I]strikeout\f[]\.]
.PP
-Superscripts: a^bc^d a^\f[I]hello\f[]^ a^hello there^\.
+Superscripts: a^bc^d a^\f[I]hello\f[]^ a^hello\ there^\.
.PP
-Subscripts: H~2~O, H~23~O, H~many of them~O\.
+Subscripts: H~2~O, H~23~O, H~many\ of\ them~O\.
.PP
These should not be superscripts or subscripts, because of the
unescaped spaces: a^b c^d, a~b c~d\.
diff --git a/tests/writer.markdown b/tests/writer.markdown
index feab4e03c..387a2df38 100644
--- a/tests/writer.markdown
+++ b/tests/writer.markdown
@@ -457,9 +457,9 @@ This is code: `>`, `$`, `\`, `\$`, `<html>`.
~~This is *strikeout*.~~
-Superscripts: a^bc^d a^*hello*^ a^hello\ there^.
+Superscripts: a^bc^d a^*hello*^ a^hello&nbsp;there^.
-Subscripts: H~2~O, H~23~O, H~many\ of\ them~O.
+Subscripts: H~2~O, H~23~O, H~many&nbsp;of&nbsp;them~O.
These should not be superscripts or subscripts, because of the
unescaped spaces: a\^b c\^d, a\~b c\~d.
diff --git a/tests/writer.native b/tests/writer.native
index 34d51df5d..d3c4835ed 100644
--- a/tests/writer.native
+++ b/tests/writer.native
@@ -265,8 +265,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
, Para [Str "So",Space,Str "is",Space,Strong [Emph [Str "this"]],Space,Str "word",Str "."]
, Para [Str "This",Space,Str "is",Space,Str "code:",Space,Code ">",Str ",",Space,Code "$",Str ",",Space,Code "\\",Str ",",Space,Code "\\$",Str ",",Space,Code "<html>",Str "."]
, Para [Strikeout [Str "This",Space,Str "is",Space,Emph [Str "strikeout"],Str "."]]
-, Para [Str "Superscripts:",Space,Str "a",Superscript [Str "bc"],Str "d",Space,Str "a",Superscript [Emph [Str "hello"]],Space,Str "a",Superscript [Str "hello",Str " ",Str "there"],Str "."]
-, Para [Str "Subscripts:",Space,Str "H",Subscript [Str "2"],Str "O,",Space,Str "H",Subscript [Str "23"],Str "O,",Space,Str "H",Subscript [Str "many",Str " ",Str "of",Str " ",Str "them"],Str "O",Str "."]
+, Para [Str "Superscripts:",Space,Str "a",Superscript [Str "bc"],Str "d",Space,Str "a",Superscript [Emph [Str "hello"]],Space,Str "a",Superscript [Str "hello",Str "\160",Str "there"],Str "."]
+, Para [Str "Subscripts:",Space,Str "H",Subscript [Str "2"],Str "O,",Space,Str "H",Subscript [Str "23"],Str "O,",Space,Str "H",Subscript [Str "many",Str "\160",Str "of",Str "\160",Str "them"],Str "O",Str "."]
, Para [Str "These",Space,Str "should",Space,Str "not",Space,Str "be",Space,Str "superscripts",Space,Str "or",Space,Str "subscripts,",Space,Str "because",Space,Str "of",Space,Str "the",Space,Str "unescaped",Space,Str "spaces:",Space,Str "a",Str "^",Str "b",Space,Str "c",Str "^",Str "d,",Space,Str "a",Str "~",Str "b",Space,Str "c",Str "~",Str "d",Str "."]
, HorizontalRule
, Header 1 [Str "Smart",Space,Str "quotes,",Space,Str "ellipses,",Space,Str "dashes"]
diff --git a/tests/writer.rst b/tests/writer.rst
index 3478b66ed..5a97a1e8b 100644
--- a/tests/writer.rst
+++ b/tests/writer.rst
@@ -585,10 +585,10 @@ This is code: ``>``, ``$``, ``\``, ``\$``, ``<html>``.
[STRIKEOUT:This is *strikeout*.]
Superscripts: a\ :sup:`bc`\ d a\ :sup:`*hello*`\
-a\ :sup:`hello there`\ .
+a\ :sup:`hello there`\ .
Subscripts: H\ :sub:`2`\ O, H\ :sub:`23`\ O,
-H\ :sub:`many of them`\ O.
+H\ :sub:`many of them`\ O.
These should not be superscripts or subscripts, because of the
unescaped spaces: a^b c^d, a~b c~d.
diff --git a/tests/writer.rtf b/tests/writer.rtf
index 1e6f9082a..40f5a06dc 100644
--- a/tests/writer.rtf
+++ b/tests/writer.rtf
@@ -222,8 +222,8 @@ emphasized link
{\pard \ql \f0 \sa180 \li0 \fi0 So is {\b {\i this}} word.\par}
{\pard \ql \f0 \sa180 \li0 \fi0 This is code: {\f1 >}, {\f1 $}, {\f1 \\}, {\f1 \\$}, {\f1 <html>}.\par}
{\pard \ql \f0 \sa180 \li0 \fi0 {\strike This is {\i strikeout}.}\par}
-{\pard \ql \f0 \sa180 \li0 \fi0 Superscripts: a{\super bc}d a{\super {\i hello}} a{\super hello there}.\par}
-{\pard \ql \f0 \sa180 \li0 \fi0 Subscripts: H{\sub 2}O, H{\sub 23}O, H{\sub many of them}O.\par}
+{\pard \ql \f0 \sa180 \li0 \fi0 Superscripts: a{\super bc}d a{\super {\i hello}} a{\super hello\u160?there}.\par}
+{\pard \ql \f0 \sa180 \li0 \fi0 Subscripts: H{\sub 2}O, H{\sub 23}O, H{\sub many\u160?of\u160?them}O.\par}
{\pard \ql \f0 \sa180 \li0 \fi0 These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.\par}
{\pard \qc \f0 \sa180 \li0 \fi0 \emdash\emdash\emdash\emdash\emdash\par}
{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Smart quotes, ellipses, dashes\par}
diff --git a/tests/writer.texinfo b/tests/writer.texinfo
index 75ed31ddc..bb2ced1ba 100644
--- a/tests/writer.texinfo
+++ b/tests/writer.texinfo
@@ -663,9 +663,9 @@ This is code: @code{>}@comma{} @code{$}@comma{} @code{\}@comma{} @code{\$}@comma
@textstrikeout{This is @emph{strikeout}.}
-Superscripts: a@textsuperscript{bc}d a@textsuperscript{@emph{hello}} a@textsuperscript{hello there}.
+Superscripts: a@textsuperscript{bc}d a@textsuperscript{@emph{hello}} a@textsuperscript{hello@ there}.
-Subscripts: H@textsubscript{2}O@comma{} H@textsubscript{23}O@comma{} H@textsubscript{many of them}O.
+Subscripts: H@textsubscript{2}O@comma{} H@textsubscript{23}O@comma{} H@textsubscript{many@ of@ them}O.
These should not be superscripts or subscripts@comma{} because of the unescaped spaces: a^b c^d@comma{} a~b c~d.