git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: modified str to handle acronyms, hyphens.
36d4aa4John MacFarlane
src/Text/Pandoc/Readers/Textile.hs+16−3
@@ -70,7 +70,8 @@ import Text.Pandoc.Readers.HTML ( htmlTag, htmlEndTag, -- find code blocks
70 rawHtmlBlock, rawHtmlInline )
70 rawHtmlBlock, rawHtmlInline )
71import Text.Pandoc.Readers.Markdown (smartPunctuation)
71import Text.Pandoc.Readers.Markdown (smartPunctuation)
72import Text.ParserCombinators.Parsec
72import Text.ParserCombinators.Parsec
73−import Data.Char ( digitToInt )
73+import Data.Char ( digitToInt, isLetter )
74+import Control.Monad ( guard )
74
75
75-- | Parse a Textile text and return a Pandoc document.
76-- | Parse a Textile text and return a Pandoc document.
76readTextile :: ParserState -- ^ Parser state, including options for parser
77readTextile :: ParserState -- ^ Parser state, including options for parser
@@ -312,7 +313,19 @@ inlineParsers = [ autoLink
312
313
313-- | Any string
314-- | Any string
314str :: GenParser Char ParserState Inline
315str :: GenParser Char ParserState Inline
316+str = do
315−str = many1 (noneOf (specialChars ++ "\t\n ")) >>= return . Str
317+ xs <- many1 (noneOf (specialChars ++ "\t\n "))
318+ optional $ charsInBalanced '(' ')' -- drop acronym explanation
319+ -- e.g. PBS(Public Broadcasting Service)
320+ -- parse a following hyphen if followed by a letter
321+ -- (this prevents unwanted interpretation as starting a strikeout section)
322+ result <- option xs $ try $ do
323+ guard $ not . null $ xs
324+ char '-'
325+ next <- lookAhead letter
326+ guard $ isLetter (last xs) || isLetter next
327+ return $ xs ++ "-"
328+ return $ Str result
316
329
317-- | Textile allows HTML span infos, we discard them
330-- | Textile allows HTML span infos, we discard them
318htmlSpan :: GenParser Char ParserState Inline
331htmlSpan :: GenParser Char ParserState Inline
@@ -384,4 +397,4 @@ simpleInline :: GenParser Char ParserState t -- ^ surrounding parser
384 -> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
397 -> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
385simpleInline border construct = surrounded border (inlineWithAttribute) >>=
398simpleInline border construct = surrounded border (inlineWithAttribute) >>=
386 return . construct . normalizeSpaces
399 return . construct . normalizeSpaces
387− where inlineWithAttribute = (try $ optional attributes) >> inline
400+ where inlineWithAttribute = (try $ optional attributes) >> inline