git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: implemented acronyms, (tm), (r), (c).
commitf917b46500377df2c5b33b9c9a7827e00650a29f authorJohn MacFarlane <jgm@berkeley.edu> dateTue 7 Dec 2010, 18:28 (16 years ago) parent6ef8a36
3 files changed+48−7
src/Text/Pandoc/Readers/Textile.hs+29−6 tests/textile-reader.native+7−1 tests/textile-reader.textile+12
src/Text/Pandoc/Readers/Textile.hs+29−6
@@ -43,8 +43,6 @@ Left to be implemented:
4343 - Pandoc Meta Information (title, author, date)
4444 - footnotes
4545 - dimension sign
46− - registered, trademark, and copyright symbols
47− - acronyms
4846 - uppercase
4947 - definition lists
5048 - continued blocks (ex bq..)
@@ -86,7 +84,7 @@ readTextile state s = (readWith parseTextile) state (s ++ "\n\n")
8684
8785-- | Special chars border strings parsing
8886specialChars :: [Char]
89−specialChars = "\\[]<>*#_@~-+^&,.;:!?|\"'%"
87+specialChars = "\\[]<>*#_@~-+^&,.;:!?|\"'%()"
9088
9189-- | Generate a Pandoc ADT from a textile document
9290parseTextile :: GenParser Char ParserState Pandoc
@@ -312,6 +310,7 @@ inlines = manyTill inline newline
312310-- | Inline parsers tried in order
313311inlineParsers :: [GenParser Char ParserState Inline]
314312inlineParsers = [ autoLink
313+ , mark
315314 , str
316315 , htmlSpan
317316-- , smartPunctuation -- from markdown reader
@@ -332,16 +331,40 @@ inlineParsers = [ autoLink
332331 , symbol
333332 ]
334333
334+-- | Trademark, registered, copyright
335+mark :: GenParser Char st Inline
336+mark = try $ char '(' >> (try tm <|> try reg <|> copy)
337+
338+reg :: GenParser Char st Inline
339+reg = do
340+ oneOf "Rr"
341+ char ')'
342+ return $ Str "\174"
343+
344+tm :: GenParser Char st Inline
345+tm = do
346+ oneOf "Tt"
347+ oneOf "Mm"
348+ char ')'
349+ return $ Str "\8482"
350+
351+copy :: GenParser Char st Inline
352+copy = do
353+ oneOf "Cc"
354+ char ')'
355+ return $ Str "\169"
356+
335357-- | Any string
336358str :: GenParser Char ParserState Inline
337359str = do
338360 xs <- many1 (noneOf (specialChars ++ "\t\n "))
339− optional $ charsInBalanced '(' ')' -- drop acronym explanation
340− -- e.g. PBS(Public Broadcasting Service)
361+ optional $ try $ do
362+ lookAhead (char '(')
363+ notFollowedBy' mark
364+ charsInBalanced '(' ')' -- drop acronym explanation
341365 -- parse a following hyphen if followed by a letter
342366 -- (this prevents unwanted interpretation as starting a strikeout section)
343367 result <- option xs $ try $ do
344− guard $ not . null $ xs
345368 char '-'
346369 next <- lookAhead letter
347370 guard $ isLetter (last xs) || isLetter next
tests/textile-reader.native+7−1
@@ -125,4 +125,10 @@ Pandoc (Meta {docTitle = [Str ""], docAuthors = [[Str ""]], docDate = [Str ""]})
125125, BulletList
126126 [ [ Plain [Str "this",Space,Str "<",Str "div",Str ">",Space,Str "won",Str "'",Str "t",Space,Str "produce",Space,Str "raw",Space,Str "html",Space,Str "blocks",Space,Str "<",Str "/div",Str ">"] ]
127127 , [ Plain [Str "but",Space,Str "this",Space,HtmlInline "<strong>",Space,Str "will",Space,Str "produce",Space,Str "inline",Space,Str "html",Space,HtmlInline "</strong>"] ] ]
128−, Para [Str "Can",Space,Str "you",Space,Str "prove",Space,Str "that",Space,Str "2",Space,Str "<",Space,Str "3",Space,Str "?"] ]
128+, Para [Str "Can",Space,Str "you",Space,Str "prove",Space,Str "that",Space,Str "2",Space,Str "<",Space,Str "3",Space,Str "?"]
129+, Header 1 [Str "Acronyms",Space,Str "and",Space,Str "marks"]
130+, Para [Str "PBS"]
131+, Para [Str "Hi",Str "\8482"]
132+, Para [Str "Hi",Space,Str "\8482"]
133+, Para [Str "\174",Space,Str "Hi",Str "\174"]
134+, Para [Str "Hi",Str "\169",Str "2008",Space,Str "\169",Space,Str "2008"] ]
tests/textile-reader.textile+12
@@ -178,3 +178,15 @@ Html blocks can be <div>inlined</div> as well.
178178* but this <strong> will produce inline html </strong>
179179
180180Can you prove that 2 < 3 ?
181+
182+h1. Acronyms and marks
183+
184+PBS(Public Broadcasting System)
185+
186+Hi(tm)
187+
188+Hi (TM)
189+
190+(r) Hi(r)
191+
192+Hi(c)2008 (C) 2008