git.iko.soy/typeable/pandoc
on master help sign in
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

commit8ed710bc9d771a25e73be2582b379485a3e240dc authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 11 Jul 2008, 01:24 (18 years ago) parent275f9dc
16 files changed+47−37
README+3 Text/Pandoc/Readers/Markdown.hs+4−1 Text/Pandoc/Writers/ConTeXt.hs+15−14 Text/Pandoc/Writers/LaTeX.hs+1 Text/Pandoc/Writers/Texinfo.hs+1 tests/testsuite.native+2−2 tests/writer.context+2−2 tests/writer.docbook+3−2 tests/writer.html+2−2 tests/writer.latex+2−2 tests/writer.man+2−2 tests/writer.markdown+2−2 tests/writer.native+2−2 tests/writer.rst+2−2 tests/writer.rtf+2−2 tests/writer.texinfo+2−2
README+3
@@ -435,6 +435,9 @@ which allows only the following characters to be backslash-escaped:
435435
436436 \`*_{}[]()>#+-.!
437437
438+A backslash-escaped space is parsed as a nonbreaking space. It will
439+appear in TeX output as '~' and in HTML and XML as '\&#160;' or '\&nbsp;'.
440+
438441Subscripts and superscripts
439442---------------------------
440443
Text/Pandoc/Readers/Markdown.hs+4−1
@@ -733,7 +733,10 @@ escapedChar = do
733733 result <- option '\\' $ if stateStrict state
734734 then oneOf "\\`*_{}[]()>#+-.!~"
735735 else satisfy (not . isAlphaNum)
736− return $ Str [result]
736+ let result' = if result == ' '
737+ then '\160' -- '\ ' is a nonbreaking space
738+ else result
739+ return $ Str [result']
737740
738741ltSign = do
739742 st <- getState
Text/Pandoc/Writers/ConTeXt.hs+15−14
@@ -102,20 +102,21 @@ contextHeader options (Meta title authors date) = do
102102escapeCharForConTeXt :: Char -> String
103103escapeCharForConTeXt ch =
104104 case ch of
105− '{' -> "\\letteropenbrace{}"
106− '}' -> "\\letterclosebrace{}"
107− '\\' -> "\\letterbackslash{}"
108− '$' -> "\\$"
109− '|' -> "\\letterbar{}"
110− '^' -> "\\letterhat{}"
111− '%' -> "\\%"
112− '~' -> "\\lettertilde{}"
113− '&' -> "\\&"
114− '#' -> "\\#"
115− '<' -> "\\letterless{}"
116− '>' -> "\\lettermore{}"
117− '_' -> "\\letterunderscore{}"
118− x -> [x]
105+ '{' -> "\\letteropenbrace{}"
106+ '}' -> "\\letterclosebrace{}"
107+ '\\' -> "\\letterbackslash{}"
108+ '$' -> "\\$"
109+ '|' -> "\\letterbar{}"
110+ '^' -> "\\letterhat{}"
111+ '%' -> "\\%"
112+ '~' -> "\\lettertilde{}"
113+ '&' -> "\\&"
114+ '#' -> "\\#"
115+ '<' -> "\\letterless{}"
116+ '>' -> "\\lettermore{}"
117+ '_' -> "\\letterunderscore{}"
118+ '\160' -> "~"
119+ x -> [x]
119120
120121-- | Escape string for ConTeXt
121122stringToConTeXt :: String -> String
Text/Pandoc/Writers/LaTeX.hs+1
@@ -116,6 +116,7 @@ stringToLaTeX = escapeStringUsing latexEscapes
116116 , ('|', "\\textbar{}")
117117 , ('<', "\\textless{}")
118118 , ('>', "\\textgreater{}")
119+ , ('\160', "~")
119120 ]
120121
121122-- | Puts contents into LaTeX command.
Text/Pandoc/Writers/Texinfo.hs+1
@@ -123,6 +123,7 @@ stringToTexinfo = escapeStringUsing texinfoEscapes
123123 , ('}', "@}")
124124 , ('@', "@@")
125125 , (',', "@comma{}") -- only needed in argument lists
126+ , ('\160', "@ ")
126127 ]
127128
128129-- | Puts contents into Texinfo command.
tests/testsuite.native+2−2
@@ -265,8 +265,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
265265, Para [Str "So",Space,Str "is",Space,Strong [Emph [Str "this"]],Space,Str "word",Str "."]
266266, 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 "."]
267267, Para [Strikeout [Str "This",Space,Str "is",Space,Emph [Str "strikeout"],Str "."]]
268−, 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 "."]
269−, 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 "."]
268+, 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 "."]
269+, 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 "."]
270270, 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 "."]
271271, HorizontalRule
272272, Header 1 [Str "Smart",Space,Str "quotes,",Space,Str "ellipses,",Space,Str "dashes"]
tests/writer.context+2−2
@@ -590,9 +590,9 @@ This is code: \type{>}, \type{$}, \type{\}, \type{\$},
590590
591591\overstrikes{This is {\em strikeout}.}
592592
593−Superscripts: a\high{bc}d a\high{{\em hello}} a\high{hello there}.
593+Superscripts: a\high{bc}d a\high{{\em hello}} a\high{hello~there}.
594594
595−Subscripts: H\low{2}O, H\low{23}O, H\low{many of them}O.
595+Subscripts: H\low{2}O, H\low{23}O, H\low{many~of~them}O.
596596
597597These should not be superscripts or subscripts, because of the
598598unescaped spaces: a\letterhat{}b c\letterhat{}d, a\lettertilde{}b
tests/writer.docbook+3−2
@@ -795,11 +795,12 @@ These should not be escaped: \$ \\ \&gt; \[ \{
795795 <para>
796796 Superscripts: a<superscript>bc</superscript>d
797797 a<superscript><emphasis>hello</emphasis></superscript>
798− a<superscript>hello there</superscript>.
798+ a<superscript>hello&nbsp;there</superscript>.
799799 </para>
800800 <para>
801801 Subscripts: H<subscript>2</subscript>O,
802− H<subscript>23</subscript>O, H<subscript>many of them</subscript>O.
802+ H<subscript>23</subscript>O,
803+ H<subscript>many&nbsp;of&nbsp;them</subscript>O.
803804 </para>
804805 <para>
805806 These should not be superscripts or subscripts, because of the
tests/writer.html+2−2
@@ -678,7 +678,7 @@ Blah
678678 >hello</em
679679 ></sup
680680 > a<sup
681− >hello there</sup
681+ >hello&#160;there</sup
682682 >.</p
683683 ><p
684684 >Subscripts: H<sub
@@ -686,7 +686,7 @@ Blah
686686 >O, H<sub
687687 >23</sub
688688 >O, H<sub
689− >many of them</sub
689+ >many&#160;of&#160;them</sub
690690 >O.</p
691691 ><p
692692 >These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.</p
tests/writer.latex+2−2
@@ -527,10 +527,10 @@ This is code: \verb!>!, \verb!$!, \verb!\!, \verb!\$!,
527527\sout{This is \emph{strikeout}.}
528528
529529Superscripts: a\textsuperscript{bc}d
530−a\textsuperscript{\emph{hello}} a\textsuperscript{hello there}.
530+a\textsuperscript{\emph{hello}} a\textsuperscript{hello~there}.
531531
532532Subscripts: H\textsubscr{2}O, H\textsubscr{23}O,
533−H\textsubscr{many of them}O.
533+H\textsubscr{many~of~them}O.
534534
535535These should not be superscripts or subscripts, because of the
536536unescaped spaces: a\^{}b c\^{}d, a\ensuremath{\sim}b
tests/writer.man+2−2
@@ -516,9 +516,9 @@ This is code: \f[B]>\f[], \f[B]$\f[], \f[B]\\\f[], \f[B]\\$\f[],
516516.PP
517517[STRIKEOUT:This is \f[I]strikeout\f[]\.]
518518.PP
519−Superscripts: a^bc^d a^\f[I]hello\f[]^ a^hello there^\.
519+Superscripts: a^bc^d a^\f[I]hello\f[]^ a^hello\ there^\.
520520.PP
521−Subscripts: H~2~O, H~23~O, H~many of them~O\.
521+Subscripts: H~2~O, H~23~O, H~many\ of\ them~O\.
522522.PP
523523These should not be superscripts or subscripts, because of the
524524unescaped spaces: a^b c^d, a~b c~d\.
tests/writer.markdown+2−2
@@ -457,9 +457,9 @@ This is code: `>`, `$`, `\`, `\$`, `<html>`.
457457
458458~~This is *strikeout*.~~
459459
460−Superscripts: a^bc^d a^*hello*^ a^hello\ there^.
460+Superscripts: a^bc^d a^*hello*^ a^hello&nbsp;there^.
461461
462−Subscripts: H~2~O, H~23~O, H~many\ of\ them~O.
462+Subscripts: H~2~O, H~23~O, H~many&nbsp;of&nbsp;them~O.
463463
464464These should not be superscripts or subscripts, because of the
465465unescaped spaces: a\^b c\^d, a\~b c\~d.
tests/writer.native+2−2
@@ -265,8 +265,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
265265, Para [Str "So",Space,Str "is",Space,Strong [Emph [Str "this"]],Space,Str "word",Str "."]
266266, 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 "."]
267267, Para [Strikeout [Str "This",Space,Str "is",Space,Emph [Str "strikeout"],Str "."]]
268−, 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 "."]
269−, 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 "."]
268+, 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 "."]
269+, 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 "."]
270270, 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 "."]
271271, HorizontalRule
272272, Header 1 [Str "Smart",Space,Str "quotes,",Space,Str "ellipses,",Space,Str "dashes"]
tests/writer.rst+2−2
@@ -585,10 +585,10 @@ This is code: ``>``, ``$``, ``\``, ``\$``, ``<html>``.
585585[STRIKEOUT:This is *strikeout*.]
586586
587587Superscripts: a\ :sup:`bc`\ d a\ :sup:`*hello*`\
588−a\ :sup:`hello there`\ .
588+a\ :sup:`hello there`\ .
589589
590590Subscripts: H\ :sub:`2`\ O, H\ :sub:`23`\ O,
591−H\ :sub:`many of them`\ O.
591+H\ :sub:`many of them`\ O.
592592
593593These should not be superscripts or subscripts, because of the
594594unescaped spaces: a^b c^d, a~b c~d.
tests/writer.rtf+2−2
@@ -222,8 +222,8 @@ emphasized link
222222{\pard \ql \f0 \sa180 \li0 \fi0 So is {\b {\i this}} word.\par}
223223{\pard \ql \f0 \sa180 \li0 \fi0 This is code: {\f1 >}, {\f1 $}, {\f1 \\}, {\f1 \\$}, {\f1 <html>}.\par}
224224{\pard \ql \f0 \sa180 \li0 \fi0 {\strike This is {\i strikeout}.}\par}
225−{\pard \ql \f0 \sa180 \li0 \fi0 Superscripts: a{\super bc}d a{\super {\i hello}} a{\super hello there}.\par}
226−{\pard \ql \f0 \sa180 \li0 \fi0 Subscripts: H{\sub 2}O, H{\sub 23}O, H{\sub many of them}O.\par}
225+{\pard \ql \f0 \sa180 \li0 \fi0 Superscripts: a{\super bc}d a{\super {\i hello}} a{\super hello\u160?there}.\par}
226+{\pard \ql \f0 \sa180 \li0 \fi0 Subscripts: H{\sub 2}O, H{\sub 23}O, H{\sub many\u160?of\u160?them}O.\par}
227227{\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}
228228{\pard \qc \f0 \sa180 \li0 \fi0 \emdash\emdash\emdash\emdash\emdash\par}
229229{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Smart quotes, ellipses, dashes\par}
tests/writer.texinfo+2−2
@@ -663,9 +663,9 @@ This is code: @code{>}@comma{} @code{$}@comma{} @code{\}@comma{} @code{\$}@comma
663663
664664@textstrikeout{This is @emph{strikeout}.}
665665
666−Superscripts: a@textsuperscript{bc}d a@textsuperscript{@emph{hello}} a@textsuperscript{hello there}.
666+Superscripts: a@textsuperscript{bc}d a@textsuperscript{@emph{hello}} a@textsuperscript{hello@ there}.
667667
668−Subscripts: H@textsubscript{2}O@comma{} H@textsubscript{23}O@comma{} H@textsubscript{many of them}O.
668+Subscripts: H@textsubscript{2}O@comma{} H@textsubscript{23}O@comma{} H@textsubscript{many@ of@ them}O.
669669
670670These should not be superscripts or subscripts@comma{} because of the unescaped spaces: a^b c^d@comma{} a~b c~d.
671671