git.iko.soy/typeable/pandoc
on master help sign in
In smart mode, use nonbreaking spaces after abbreviations in markdown parser.

Thus, for example, "Mr. Brown" comes out as "Mr.~Brown" in LaTeX, and does not produce a sentence-separating space. Resolves Issue #75. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1298 788f1e2b-df1e-0410-8736-df70ead52e1b

commit824bb2d22e40e035703ccf6ec7fd6bcde51950ce authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 11 Jul 2008, 02:14 (18 years ago) parent8ed710b
13 files changed+39−17
README+5−4 Text/Pandoc/Readers/Markdown.hs+23−2 tests/testsuite.native+1−1 tests/writer.context+1−1 tests/writer.docbook+1−1 tests/writer.html+1−1 tests/writer.latex+1−1 tests/writer.man+1−1 tests/writer.markdown+1−1 tests/writer.native+1−1 tests/writer.rst+1−1 tests/writer.rtf+1−1 tests/writer.texinfo+1−1
README+5−4
@@ -316,10 +316,11 @@ For further documentation, see the `pandoc(1)` man page.
316316`-S` or `--smart`
317317: causes `pandoc` to produce typographically correct output, along the
318318 lines of John Gruber's [Smartypants]. Straight quotes are converted
319− to curly quotes, `---` to dashes, and `...` to ellipses. (Note: This
320− option is only significant when the input format is `markdown`.
321− It is selected automatically when the output format is `latex` or
322− `context`.)
319+ to curly quotes, `---` to dashes, and `...` to ellipses. Nonbreaking
320+ spaces are inserted after certain abbreviations, such as "Mr."
321+ (Note: This option is only significant when the input format is
322+ `markdown`. It is selected automatically when the output format is
323+ `latex` or `context`.)
323324
324325`-m`*[url]* or `--asciimathml`*[=url]*
325326: causes `pandoc` to use Peter Jipsen's [ASCIIMathML] script to display
Text/Pandoc/Readers/Markdown.hs+23−2
@@ -33,7 +33,7 @@ module Text.Pandoc.Readers.Markdown (
3333
3434import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy, findIndex )
3535import Data.Ord ( comparing )
36−import Data.Char ( isAlphaNum )
36+import Data.Char ( isAlphaNum, isAlpha, isLower, isDigit )
3737import Data.Maybe ( fromMaybe )
3838import Text.Pandoc.Definition
3939import Text.Pandoc.Shared
@@ -697,7 +697,8 @@ table = simpleTable <|> multilineTable <?> "table"
697697
698698inline = choice inlineParsers <?> "inline"
699699
700−inlineParsers = [ str
700+inlineParsers = [ abbrev
701+ , str
701702 , smartPunctuation
702703 , whitespace
703704 , endline
@@ -792,6 +793,26 @@ subscript = failIfStrict >> enclosed (char '~') (char '~')
792793 (notFollowedBy' whitespace >> inline) >>= -- may not contain Space
793794 return . Subscript
794795
796+abbrev = failUnlessSmart >>
797+ (assumedAbbrev <|> knownAbbrev) >>= return . Str . (++ ".\160")
798+
799+-- an string of letters followed by a period that does not end a sentence
800+-- is assumed to be an abbreviation. It is assumed that sentences don't
801+-- start with lowercase letters or numerals.
802+assumedAbbrev = try $ do
803+ result <- many1 $ satisfy isAlpha
804+ string ". "
805+ lookAhead $ satisfy (\x -> isLower x || isDigit x)
806+ return result
807+
808+-- these strings are treated as abbreviations even if they are followed
809+-- by a capital letter (such as a name).
810+knownAbbrev = try $ do
811+ result <- oneOfStrings [ "Mr", "Mrs", "Ms", "Capt", "Dr", "Prof", "Gen",
812+ "Gov", "e.g", "i.e", "Sgt", "St", "vol", "vs" ]
813+ string ". "
814+ return result
815+
795816smartPunctuation = failUnlessSmart >>
796817 choice [ quoted, apostrophe, dash, ellipses ]
797818
tests/testsuite.native+1−1
@@ -165,7 +165,7 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
165165 [ [ Plain [Str "Nested",Str "."] ]
166166 ] ] ]
167167, Para [Str "Should",Space,Str "not",Space,Str "be",Space,Str "a",Space,Str "list",Space,Str "item:"]
168−, Para [Str "M",Str ".",Str "A",Str ".",Space,Str "2007"]
168+, Para [Str "M",Str ".",Str "A.\160",Str "2007"]
169169, Para [Str "B",Str ".",Space,Str "Williams"]
170170, HorizontalRule
171171, Header 1 [Str "Definition",Space,Str "Lists"]
tests/writer.context+1−1
@@ -444,7 +444,7 @@ Autonumbering:
444444
445445Should not be a list item:
446446
447−M.A. 2007
447+M.A.~2007
448448
449449B. Williams
450450
tests/writer.docbook+1−1
@@ -606,7 +606,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
606606 Should not be a list item:
607607 </para>
608608 <para>
609− M.A. 2007
609+ M.A.&nbsp;2007
610610 </para>
611611 <para>
612612 B. Williams
tests/writer.html+1−1
@@ -412,7 +412,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
412412 ><p
413413 >Should not be a list item:</p
414414 ><p
415− >M.A. 2007</p
415+ >M.A.&#160;2007</p
416416 ><p
417417 >B. Williams</p
418418 ><hr
tests/writer.latex+1−1
@@ -394,7 +394,7 @@ Autonumbering:
394394\end{enumerate}
395395Should not be a list item:
396396
397−M.A. 2007
397+M.A.~2007
398398
399399B. Williams
400400
tests/writer.man+1−1
@@ -296,7 +296,7 @@ Nested\.
296296.PP
297297Should not be a list item:
298298.PP
299−M\.A\. 2007
299+M\.A\.\ 2007
300300.PP
301301B\. Williams
302302.PP
tests/writer.markdown+1−1
@@ -269,7 +269,7 @@ Autonumbering:
269269
270270Should not be a list item:
271271
272−M.A. 2007
272+M.A.&nbsp;2007
273273
274274B. Williams
275275
tests/writer.native+1−1
@@ -165,7 +165,7 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
165165 [ [ Plain [Str "Nested",Str "."] ]
166166 ] ] ]
167167, Para [Str "Should",Space,Str "not",Space,Str "be",Space,Str "a",Space,Str "list",Space,Str "item:"]
168−, Para [Str "M",Str ".",Str "A",Str ".",Space,Str "2007"]
168+, Para [Str "M",Str ".",Str "A.\160",Str "2007"]
169169, Para [Str "B",Str ".",Space,Str "Williams"]
170170, HorizontalRule
171171, Header 1 [Str "Definition",Space,Str "Lists"]
tests/writer.rst+1−1
@@ -329,7 +329,7 @@ Autonumbering:
329329
330330Should not be a list item:
331331
332−M.A. 2007
332+M.A. 2007
333333
334334B. Williams
335335
tests/writer.rtf+1−1
@@ -148,7 +148,7 @@ These should not be escaped: \\$ \\\\ \\> \\[ \\\{\par}
148148{\pard \ql \f0 \sa0 \li360 \fi-360 2.\tx360\tab More.\par}
149149{\pard \ql \f0 \sa0 \li720 \fi-360 a.\tx360\tab Nested.\sa180\sa180\par}
150150{\pard \ql \f0 \sa180 \li0 \fi0 Should not be a list item:\par}
151−{\pard \ql \f0 \sa180 \li0 \fi0 M.A. 2007\par}
151+{\pard \ql \f0 \sa180 \li0 \fi0 M.A.\u160?2007\par}
152152{\pard \ql \f0 \sa180 \li0 \fi0 B. Williams\par}
153153{\pard \qc \f0 \sa180 \li0 \fi0 \emdash\emdash\emdash\emdash\emdash\par}
154154{\pard \ql \f0 \sa180 \li0 \fi0 \b \fs36 Definition Lists\par}
tests/writer.texinfo+1−1
@@ -506,7 +506,7 @@ Nested.
506506
507507Should not be a list item:
508508
509−M.A. 2007
509+M.A.@ 2007
510510
511511B. Williams
512512