Treat '\ ' in (extended) markdown as nonbreaking space.

Print nonbreaking space appropriately in each writer (e.g. ~ in LaTeX).


git-svn-id: https://pandoc.googlecode.com/svn/trunk@1297 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2008-07-11 01:24:15 +00:00
parent 275f9dc94c
commit 8ed710bc9d
16 changed files with 47 additions and 37 deletions

3
README
View file

@ -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
---------------------------

View file

@ -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

View file

@ -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

View file

@ -116,6 +116,7 @@ stringToLaTeX = escapeStringUsing latexEscapes
, ('|', "\\textbar{}")
, ('<', "\\textless{}")
, ('>', "\\textgreater{}")
, ('\160', "~")
]
-- | Puts contents into LaTeX command.

View file

@ -123,6 +123,7 @@ stringToTexinfo = escapeStringUsing texinfoEscapes
, ('}', "@}")
, ('@', "@@")
, (',', "@comma{}") -- only needed in argument lists
, ('\160', "@ ")
]
-- | Puts contents into Texinfo command.

View file

@ -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"]

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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\.

View file

@ -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.

View file

@ -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"]

View file

@ -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.

View file

@ -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}

View file

@ -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.