diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2018-04-24 10:49:04 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2018-04-24 10:49:04 -0700 |
commit | a080dde1efb823e6e25e6ba0ead2afeb76012e43 (patch) | |
tree | 6165e39a24544d1387a201790541147e0f7478ab /src/Text/Pandoc/Readers/Haddock.hs | |
parent | a9ae23fa15d769ab9b05f483c8511e96cc684403 (diff) | |
parent | de5ee82ed0e287ada3a5b272d8365a04fe8e9f95 (diff) |
Merge tag 'upstream/2.1.2_dfsg'
Upstream version 2.1.2~dfsg
# gpg: Signature made Tue 24 Apr 2018 10:48:48 AM MST
# gpg: using RSA key 9B917007AE030E36E4FC248B695B7AE4BF066240
# gpg: issuer "spwhitton@spwhitton.name"
# gpg: Good signature from "Sean Whitton <spwhitton@spwhitton.name>" [ultimate]
# Primary key fingerprint: 8DC2 487E 51AB DD90 B5C4 753F 0F56 D055 3B6D 411B
# Subkey fingerprint: 9B91 7007 AE03 0E36 E4FC 248B 695B 7AE4 BF06 6240
Diffstat (limited to 'src/Text/Pandoc/Readers/Haddock.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/Haddock.hs | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/Text/Pandoc/Readers/Haddock.hs b/src/Text/Pandoc/Readers/Haddock.hs index 12953bb72..e98c79ed8 100644 --- a/src/Text/Pandoc/Readers/Haddock.hs +++ b/src/Text/Pandoc/Readers/Haddock.hs @@ -14,33 +14,40 @@ module Text.Pandoc.Readers.Haddock ( readHaddock ) where -import Text.Pandoc.Builder (Blocks, Inlines) -import qualified Text.Pandoc.Builder as B -import Data.Monoid ((<>)) -import Text.Pandoc.Shared (trim, splitBy) +import Control.Monad.Except (throwError) import Data.List (intersperse, stripPrefix) import Data.Maybe (fromMaybe) -import Text.Pandoc.Definition -import Text.Pandoc.Options +import Data.Monoid ((<>)) +import Data.Text (Text, unpack) import Documentation.Haddock.Parser import Documentation.Haddock.Types -import Debug.Trace (trace) - +import Text.Pandoc.Builder (Blocks, Inlines) +import qualified Text.Pandoc.Builder as B +import Text.Pandoc.Class (PandocMonad) +import Text.Pandoc.Definition import Text.Pandoc.Error +import Text.Pandoc.Options +import Text.Pandoc.Shared (crFilter, splitBy, trim) + -- | Parse Haddock markup and return a 'Pandoc' document. -readHaddock :: ReaderOptions -- ^ Reader options - -> String -- ^ String to parse - -> Either PandocError Pandoc -readHaddock opts = +readHaddock :: PandocMonad m + => ReaderOptions + -> Text + -> m Pandoc +readHaddock opts s = case readHaddockEither opts (unpack (crFilter s)) of + Right result -> return result + Left e -> throwError e + +readHaddockEither :: ReaderOptions -- ^ Reader options + -> String -- ^ String to parse + -> Either PandocError Pandoc +readHaddockEither _opts = #if MIN_VERSION_haddock_library(1,2,0) - Right . B.doc . docHToBlocks . trace' . _doc . parseParas + Right . B.doc . docHToBlocks . _doc . parseParas #else - Right . B.doc . docHToBlocks . trace' . parseParas + Right . B.doc . docHToBlocks . parseParas #endif - where trace' x = if readerTrace opts - then trace (show x) x - else x docHToBlocks :: DocH String Identifier -> Blocks docHToBlocks d' = @@ -90,7 +97,7 @@ docHToBlocks d' = isPlain (Plain _) = True isPlain _ = False extractContents (Plain xs) = xs - extractContents _ = [] + extractContents _ = [] docHToInlines :: Bool -> DocH String Identifier -> Inlines docHToInlines isCode d' = @@ -135,7 +142,7 @@ makeExample prompt expression result = <> B.space <> B.codeWith ([], ["haskell","expr"], []) (trim expression) <> B.linebreak - <> (mconcat $ intersperse B.linebreak $ map coder result') + <> mconcat (intersperse B.linebreak $ map coder result') where -- 1. drop trailing whitespace from the prompt, remember the prefix prefix = takeWhile (`elem` " \t") prompt |