Some bug fixes related to fenced code in markdown

``` as cryptol wasn't supported, and fenced code blocks that weren't
understood were having their internals processed as markdown
This commit is contained in:
Trevor Elliott 2014-05-06 14:29:51 -07:00
parent f1f1991ce0
commit 25f17d0202

View File

@ -8,7 +8,7 @@
--
-- Convert a literate source file into an ordinary source file.
{-# LANGUAGE OverloadedStrings, Safe #-}
{-# LANGUAGE OverloadedStrings, Safe, PatternGuards #-}
module Cryptol.Parser.Unlit
( unLit, PreProc(..), guessPreProc, knownExts
) where
@ -82,7 +82,7 @@ markdown = blanks []
blanks current [] = mk Comment current
blanks current (l : ls)
| isCodeLine l = mk Comment current ++ code [l] ls
| isOpenFence l = mk Comment (l : current) ++ fenced [] ls
| Just op <- isOpenFence l = mk Comment (l : current) ++ fenced op [] ls
| isBlank l = blanks (l : current) ls
| otherwise = comment (l : current) ls
@ -91,13 +91,18 @@ markdown = blanks []
| isCodeLine l = code (l : current) ls
| otherwise = mk Code current ++ comment [] (l : ls)
fenced current [] = mk Code current -- XXX should this be an error?
fenced current (l : ls)
| isCloseFence l = mk Code current ++ comment [l] ls
| otherwise = fenced (l : current) ls
fenced op current [] = mk op current -- XXX should this be an error?
fenced op current (l : ls)
| isCloseFence l = mk op current ++ comment [l] ls
| otherwise = fenced op (l : current) ls
isOpenFence l = "```cryptol" `Text.isPrefixOf` l
isOpenFence l | "```cryptol" == l' = Just Code
| "```" == l' = Just Code
| "```" `Text.isPrefixOf` l' = Just Comment
| otherwise = Nothing
where
l' = Text.dropWhile isSpace l
isCloseFence l = "```" `Text.isPrefixOf` l
isBlank l = Text.all isSpace l
isCodeLine l = "\t" `Text.isPrefixOf` l || " " `Text.isPrefixOf` l