started work on markdown parser
This commit is contained in:
parent
59c6ab4209
commit
2e9860d147
1 changed files with 37 additions and 0 deletions
|
@ -1,4 +1,41 @@
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
|
||||||
module Markdown where
|
module Markdown where
|
||||||
|
|
||||||
|
import Data.Functor (void)
|
||||||
|
import Data.Text (Text, pack)
|
||||||
|
import Text.Parsec
|
||||||
|
|
||||||
-- https://spec.commonmark.org/0.31.2/
|
-- https://spec.commonmark.org/0.31.2/
|
||||||
-- https://hackage.haskell.org/package/parsec
|
-- https://hackage.haskell.org/package/parsec
|
||||||
|
|
||||||
|
linebreak ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m ()
|
||||||
|
-- 2 newlines due to mark
|
||||||
|
linebreak = void (newline *> newline)
|
||||||
|
|
||||||
|
emptyParse ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m String
|
||||||
|
emptyParse = "" <$ notFollowedBy anyChar
|
||||||
|
|
||||||
|
line ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m Text
|
||||||
|
line = fmap pack $ many $ notFollowedBy linebreak *> anyChar
|
||||||
|
|
||||||
|
lines ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m [Text]
|
||||||
|
lines = line `sepBy` linebreak
|
||||||
|
|
||||||
|
heading ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m (Int, Text)
|
||||||
|
heading = do
|
||||||
|
level <- fmap length $ many1 $ char '#'
|
||||||
|
text <- line
|
||||||
|
pure (level, text)
|
||||||
|
|
||||||
|
-- TODO: blockquote, single backticks, triple backticks, links, arb HTML
|
||||||
|
|
Loading…
Reference in a new issue