aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-04-14 21:39:05 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-04-14 21:39:05 -0700
commit5c03275a632767f300be371c6c15fcb2f905e897 (patch)
tree57d6d14086df4e51c613f0ea37871af1d3ea0782 /src/Text
parent7d7bc2cb79278dc1420a6bb883b0cd8318845c42 (diff)
downloadpandoc-5c03275a632767f300be371c6c15fcb2f905e897.tar.gz
Haddock reader improvements.
- Correctly handle ghci sessions. - Fixed spacing issues. - Simplified code.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Haddock/Parse.y16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Haddock/Parse.y b/src/Text/Pandoc/Readers/Haddock/Parse.y
index e801a15c0..9c2bbc8a9 100644
--- a/src/Text/Pandoc/Readers/Haddock/Parse.y
+++ b/src/Text/Pandoc/Readers/Haddock/Parse.y
@@ -12,6 +12,7 @@ module Text.Pandoc.Readers.Haddock.Parse (parseString, parseParas) where
import Text.Pandoc.Readers.Haddock.Lex
import Text.Pandoc.Builder
+import Text.Pandoc.Shared (trim, trimr)
import Data.Generics (everywhere, mkT)
import Data.Char (isSpace)
import Data.Maybe (fromMaybe)
@@ -141,13 +142,12 @@ monospace = everywhere (mkT go)
-- A hyperlink consists of a URL and an optional label. The label is separated
-- from the url by one or more whitespace characters.
makeHyperlink :: String -> Inlines
-makeHyperlink input = case break isSpace $ strip input of
+makeHyperlink input = case break isSpace $ trim input of
(url, "") -> link url url (str url)
- (url, lb) -> link url url (str label)
- where label = dropWhile isSpace lb
+ (url, lb) -> link url url (trimInlines $ text lb)
makeProperty :: String -> Blocks
-makeProperty s = case strip s of
+makeProperty s = case trim s of
'p':'r':'o':'p':'>':xs ->
codeBlockWith ([], ["property"], []) (dropWhile isSpace xs)
xs ->
@@ -156,12 +156,12 @@ makeProperty s = case strip s of
-- | Create an 'Example', stripping superfluous characters as appropriate
makeExample :: String -> String -> [String] -> Blocks
makeExample prompt expression result =
- para $ codeWith ([], ["haskell","expr"], []) (strip expression)
+ para $ codeWith ([], ["haskell","expr"], []) (trim expression)
<> linebreak
<> (mconcat $ intersperse linebreak $ map coder result')
where
-- 1. drop trailing whitespace from the prompt, remember the prefix
- (prefix, _) = span isSpace prompt
+ prefix = takeWhile isSpace prompt
-- 2. drop, if possible, the exact same sequence of whitespace
-- characters from each result line
@@ -175,8 +175,4 @@ makeExample prompt expression result =
substituteBlankLine "<BLANKLINE>" = ""
substituteBlankLine line = line
coder = codeWith ([], ["result"], [])
-
--- | Remove all leading and trailing whitespace
-strip :: String -> String
-strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse
}