git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: implemented acronyms, (tm), (r), (c).
f917b46John MacFarlane
src/Text/Pandoc/Readers/Textile.hs+29−6
@@ -43,8 +43,6 @@ Left to be implemented:
43 - Pandoc Meta Information (title, author, date)
43 - Pandoc Meta Information (title, author, date)
44 - footnotes
44 - footnotes
45 - dimension sign
45 - dimension sign
46− - registered, trademark, and copyright symbols
47− - acronyms
48 - uppercase
46 - uppercase
49 - definition lists
47 - definition lists
50 - continued blocks (ex bq..)
48 - continued blocks (ex bq..)
@@ -86,7 +84,7 @@ readTextile state s = (readWith parseTextile) state (s ++ "\n\n")
86
84
87-- | Special chars border strings parsing
85-- | Special chars border strings parsing
88specialChars :: [Char]
86specialChars :: [Char]
89−specialChars = "\\[]<>*#_@~-+^&,.;:!?|\"'%"
87+specialChars = "\\[]<>*#_@~-+^&,.;:!?|\"'%()"
90
88
91-- | Generate a Pandoc ADT from a textile document
89-- | Generate a Pandoc ADT from a textile document
92parseTextile :: GenParser Char ParserState Pandoc
90parseTextile :: GenParser Char ParserState Pandoc
@@ -312,6 +310,7 @@ inlines = manyTill inline newline
312-- | Inline parsers tried in order
310-- | Inline parsers tried in order
313inlineParsers :: [GenParser Char ParserState Inline]
311inlineParsers :: [GenParser Char ParserState Inline]
314inlineParsers = [ autoLink
312inlineParsers = [ autoLink
313+ , mark
315 , str
314 , str
316 , htmlSpan
315 , htmlSpan
317-- , smartPunctuation -- from markdown reader
316-- , smartPunctuation -- from markdown reader
@@ -332,16 +331,40 @@ inlineParsers = [ autoLink
332 , symbol
331 , symbol
333 ]
332 ]
334
333
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+
335-- | Any string
357-- | Any string
336str :: GenParser Char ParserState Inline
358str :: GenParser Char ParserState Inline
337str = do
359str = do
338 xs <- many1 (noneOf (specialChars ++ "\t\n "))
360 xs <- many1 (noneOf (specialChars ++ "\t\n "))
361+ optional $ try $ do
362+ lookAhead (char '(')
363+ notFollowedBy' mark
339− optional $ charsInBalanced '(' ')' -- drop acronym explanation
364+ charsInBalanced '(' ')' -- drop acronym explanation
340− -- e.g. PBS(Public Broadcasting Service)
341 -- parse a following hyphen if followed by a letter
365 -- parse a following hyphen if followed by a letter
342 -- (this prevents unwanted interpretation as starting a strikeout section)
366 -- (this prevents unwanted interpretation as starting a strikeout section)
343 result <- option xs $ try $ do
367 result <- option xs $ try $ do
344− guard $ not . null $ xs
345 char '-'
368 char '-'
346 next <- lookAhead letter
369 next <- lookAhead letter
347 guard $ isLetter (last xs) || isLetter next
370 guard $ isLetter (last xs) || isLetter next
tests/textile-reader.native+7−1
@@ -125,4 +125,10 @@ Pandoc (Meta {docTitle = [Str ""], docAuthors = [[Str ""]], docDate = [Str ""]})
125, BulletList
125, BulletList
126 [ [ 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 ">"] ]
126 [ [ 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 ">"] ]
127 , [ Plain [Str "but",Space,Str "this",Space,HtmlInline "<strong>",Space,Str "will",Space,Str "produce",Space,Str "inline",Space,Str "html",Space,HtmlInline "</strong>"] ] ]
127 , [ 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.
178* but this <strong> will produce inline html </strong>
178* but this <strong> will produce inline html </strong>
179
179
180Can you prove that 2 < 3 ?
180Can 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