fixed mistakes enough for blog to compile
This commit is contained in:
parent
b956f906ec
commit
a2b33de596
2 changed files with 17 additions and 39 deletions
|
|
@ -15,7 +15,7 @@ compileToHTML (Doc elements) = T.concat $ map elementToHTML elements
|
||||||
elementToHTML :: Element -> T.Text
|
elementToHTML :: Element -> T.Text
|
||||||
elementToHTML (Heading (H {level, text})) = T.concat ["<h", tshow level, ">", serializeInlineToHTML text, "</h", tshow level, ">"]
|
elementToHTML (Heading (H {level, text})) = T.concat ["<h", tshow level, ">", serializeInlineToHTML text, "</h", tshow level, ">"]
|
||||||
--
|
--
|
||||||
elementToHTML (Code (C {language = m_language, code})) = T.concat ["<pre class=\"sourceCode ", language, "\"><code class=\"sourceCode ", language, "\">", code, "</code>"]
|
elementToHTML (Code (C {language = m_language, code})) = T.concat ["<pre class=\"sourceCode ", language, "\"><code class=\"sourceCode ", language, "\">", code, "</code>", "</pre>"]
|
||||||
where
|
where
|
||||||
language = fromMaybe "" m_language
|
language = fromMaybe "" m_language
|
||||||
elementToHTML (BlockQuote (Q elems)) = T.concat ["<blockquote>", serializeInlineToHTML elems, "</blockquote>"]
|
elementToHTML (BlockQuote (Q elems)) = T.concat ["<blockquote>", serializeInlineToHTML elems, "</blockquote>"]
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ element =
|
||||||
blankLines :: Parser Element
|
blankLines :: Parser Element
|
||||||
blankLines = do
|
blankLines = do
|
||||||
skipMany1 blankLine
|
skipMany1 blankLine
|
||||||
element -- Parse the next element
|
element <|> fmap (const $ HTML HTMLTag {html_content = ""}) eof -- Parse the next element (or handle eof)
|
||||||
|
|
||||||
blankLine :: Parser ()
|
blankLine :: Parser ()
|
||||||
blankLine = do
|
blankLine = do
|
||||||
|
|
@ -65,7 +65,7 @@ fencedCodeBlock = do
|
||||||
fence <- string "```" <|> string "~~~"
|
fence <- string "```" <|> string "~~~"
|
||||||
lang <- optionMaybe languageInfo
|
lang <- optionMaybe languageInfo
|
||||||
lineEnding
|
lineEnding
|
||||||
codeLines <- manyTill codeLine (try $ string fence >> lineEnding)
|
codeLines <- manyTill codeLine (try $ string fence)
|
||||||
pure $ Code $ C lang (T.pack $ unlines codeLines)
|
pure $ Code $ C lang (T.pack $ unlines codeLines)
|
||||||
|
|
||||||
languageInfo :: Parser Text
|
languageInfo :: Parser Text
|
||||||
|
|
@ -123,9 +123,9 @@ unorderedListItem = do
|
||||||
oneOf "*-+"
|
oneOf "*-+"
|
||||||
char ' ' <|> char '\t'
|
char ' ' <|> char '\t'
|
||||||
content <- manyTill inlineElement (try lineEnding)
|
content <- manyTill inlineElement (try lineEnding)
|
||||||
continuations <- many listContinuation
|
-- continuations <- many listContinuation
|
||||||
children <- many (try indentedList)
|
children <- many (try indentedList)
|
||||||
pure $ LI (content ++ concat continuations) children
|
pure $ LI content children
|
||||||
|
|
||||||
listContinuation :: Parser [InlineText]
|
listContinuation :: Parser [InlineText]
|
||||||
listContinuation = do
|
listContinuation = do
|
||||||
|
|
@ -136,9 +136,11 @@ listContinuation = do
|
||||||
content <- manyTill inlineElement (try lineEnding)
|
content <- manyTill inlineElement (try lineEnding)
|
||||||
pure content
|
pure content
|
||||||
|
|
||||||
|
-- TODO: handle list indentation at all levels
|
||||||
indentedList :: Parser List
|
indentedList :: Parser List
|
||||||
indentedList = do
|
indentedList = do
|
||||||
void $ count 2 (char ' ' <|> char '\t')
|
let n = 1
|
||||||
|
void $ count (4 * n) (char ' ') <|> count n (char '\t')
|
||||||
choice [try indentedUnorderedList, indentedOrderedList]
|
choice [try indentedUnorderedList, indentedOrderedList]
|
||||||
|
|
||||||
indentedUnorderedList :: Parser List
|
indentedUnorderedList :: Parser List
|
||||||
|
|
@ -154,7 +156,7 @@ indentedOrderedList = do
|
||||||
indentedListItem :: Parser () -> Parser ListItem
|
indentedListItem :: Parser () -> Parser ListItem
|
||||||
indentedListItem marker = do
|
indentedListItem marker = do
|
||||||
marker
|
marker
|
||||||
content <- manyTill inlineElement (try lineEnding)
|
content <- manyTill inlineElement (try $ lineEnding <|> eof)
|
||||||
pure $ LI content []
|
pure $ LI content []
|
||||||
|
|
||||||
-- Ordered List Block
|
-- Ordered List Block
|
||||||
|
|
@ -211,16 +213,6 @@ attributeValue =
|
||||||
-- Paragraph Block
|
-- Paragraph Block
|
||||||
paragraphBlock :: Parser Element
|
paragraphBlock :: Parser Element
|
||||||
paragraphBlock = do
|
paragraphBlock = do
|
||||||
-- Make sure we're not starting another block element
|
|
||||||
notFollowedBy (char '#')
|
|
||||||
notFollowedBy (char '>')
|
|
||||||
notFollowedBy (oneOf "*-+" >> (char ' ' <|> char '\t'))
|
|
||||||
notFollowedBy (digit >> char '.')
|
|
||||||
notFollowedBy (string "```" <|> string "~~~")
|
|
||||||
notFollowedBy (count 4 (char ' ' <|> char '\t'))
|
|
||||||
notFollowedBy (count 3 (char '*') <|> count 3 (char '-') <|> count 3 (char '_'))
|
|
||||||
-- notFollowedBy (char '<')
|
|
||||||
|
|
||||||
content <- some inlineElement
|
content <- some inlineElement
|
||||||
lineEnding <|> eof
|
lineEnding <|> eof
|
||||||
pure $ Paragraph $ P content
|
pure $ Paragraph $ P content
|
||||||
|
|
@ -264,7 +256,6 @@ emphasis = emphasisAsterisk <|> emphasisUnderscore
|
||||||
emphasisAsterisk :: Parser InlineText
|
emphasisAsterisk :: Parser InlineText
|
||||||
emphasisAsterisk = do
|
emphasisAsterisk = do
|
||||||
char '*'
|
char '*'
|
||||||
notFollowedBy (char '*')
|
|
||||||
content <- some (notFollowedBy (char '*') >> inlineElementNoAsterisk)
|
content <- some (notFollowedBy (char '*') >> inlineElementNoAsterisk)
|
||||||
char '*'
|
char '*'
|
||||||
pure $ Italic content
|
pure $ Italic content
|
||||||
|
|
@ -272,8 +263,7 @@ emphasisAsterisk = do
|
||||||
emphasisUnderscore :: Parser InlineText
|
emphasisUnderscore :: Parser InlineText
|
||||||
emphasisUnderscore = do
|
emphasisUnderscore = do
|
||||||
char '_'
|
char '_'
|
||||||
notFollowedBy (char '_')
|
content <- some inlineElementNoUnderscore
|
||||||
content <- some (notFollowedBy (char '_') >> inlineElementNoUnderscore)
|
|
||||||
char '_'
|
char '_'
|
||||||
pure $ Italic content
|
pure $ Italic content
|
||||||
|
|
||||||
|
|
@ -399,32 +389,20 @@ plainText :: Parser InlineText
|
||||||
plainText = Text . T.pack <$> some plainTextChar
|
plainText = Text . T.pack <$> some plainTextChar
|
||||||
|
|
||||||
plainTextChar :: Parser Char
|
plainTextChar :: Parser Char
|
||||||
plainTextChar = satisfy $ \c ->
|
plainTextChar = noneOf "\n"
|
||||||
(c `notElem` ("*_`[<\\\n\r" :: String)) && c >= ' '
|
|
||||||
|
|
||||||
plainTextNoAsterisk :: Parser InlineText
|
plainTextNoAsterisk :: Parser InlineText
|
||||||
plainTextNoAsterisk =
|
plainTextNoAsterisk = fmap (Text . T.pack) $ some $ noneOf "*\n"
|
||||||
Text . T.pack
|
|
||||||
<$> some
|
|
||||||
( satisfy $ \c ->
|
|
||||||
(c `notElem` ("*_`[<\\\n\r" :: String)) && c >= ' '
|
|
||||||
)
|
|
||||||
|
|
||||||
plainTextNoUnderscore :: Parser InlineText
|
plainTextNoUnderscore :: Parser InlineText
|
||||||
plainTextNoUnderscore =
|
plainTextNoUnderscore = fmap (Text . T.pack) $ some $ noneOf "_\n"
|
||||||
Text . T.pack
|
|
||||||
<$> some
|
|
||||||
( satisfy $ \c ->
|
|
||||||
not (c `elem` ("_*`[<\\\n\r" :: String)) && c >= ' '
|
|
||||||
)
|
|
||||||
|
|
||||||
plainTextNoBracket :: Parser InlineText
|
plainTextNoBracket :: Parser InlineText
|
||||||
plainTextNoBracket =
|
plainTextNoBracket =
|
||||||
Text . T.pack
|
fmap (Text . T.pack) $
|
||||||
<$> some
|
some $
|
||||||
( satisfy $ \c ->
|
satisfy
|
||||||
not (c `elem` ("]_*`[<\\\n\r" :: String)) && c >= ' '
|
(`notElem` ("[]" :: String))
|
||||||
)
|
|
||||||
|
|
||||||
-- Helper Parsers
|
-- Helper Parsers
|
||||||
lineEnding :: Parser ()
|
lineEnding :: Parser ()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue