aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-12-03 22:30:08 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-03 23:10:52 -0800
commit36d4aa4a0998f35d4b7a9deab92a1f661d50dd9a (patch)
tree0d462ebc970e31b1a26ee2e1eb4cc70355419506
parent55e43c49916e55c4fec9a6783590b9574a183bf9 (diff)
downloadpandoc-36d4aa4a0998f35d4b7a9deab92a1f661d50dd9a.tar.gz
Textile reader: modified str to handle acronyms, hyphens.
* A single hyphen between two word characters is no longer a potential strikeout-starter. * Acronym explanations are dropped.
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index 276f188c5..52eebd07f 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -70,7 +70,8 @@ import Text.Pandoc.Readers.HTML ( htmlTag, htmlEndTag, -- find code blocks
rawHtmlBlock, rawHtmlInline )
import Text.Pandoc.Readers.Markdown (smartPunctuation)
import Text.ParserCombinators.Parsec
-import Data.Char ( digitToInt )
+import Data.Char ( digitToInt, isLetter )
+import Control.Monad ( guard )
-- | Parse a Textile text and return a Pandoc document.
readTextile :: ParserState -- ^ Parser state, including options for parser
@@ -312,7 +313,19 @@ inlineParsers = [ autoLink
-- | Any string
str :: GenParser Char ParserState Inline
-str = many1 (noneOf (specialChars ++ "\t\n ")) >>= return . Str
+str = do
+ xs <- many1 (noneOf (specialChars ++ "\t\n "))
+ optional $ charsInBalanced '(' ')' -- drop acronym explanation
+ -- e.g. PBS(Public Broadcasting Service)
+ -- parse a following hyphen if followed by a letter
+ -- (this prevents unwanted interpretation as starting a strikeout section)
+ result <- option xs $ try $ do
+ guard $ not . null $ xs
+ char '-'
+ next <- lookAhead letter
+ guard $ isLetter (last xs) || isLetter next
+ return $ xs ++ "-"
+ return $ Str result
-- | Textile allows HTML span infos, we discard them
htmlSpan :: GenParser Char ParserState Inline
@@ -384,4 +397,4 @@ simpleInline :: GenParser Char ParserState t -- ^ surrounding parser
-> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
simpleInline border construct = surrounded border (inlineWithAttribute) >>=
return . construct . normalizeSpaces
- where inlineWithAttribute = (try $ optional attributes) >> inline \ No newline at end of file
+ where inlineWithAttribute = (try $ optional attributes) >> inline