{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Use lambda-case" #-}
module MdToHTML where
import Control.Applicative hiding (many, some)
import Control.Monad
import Data.Char
import Data.List
import Data.Ord (comparing)
import qualified Data.Text as T
import Data.Void
import Debug.Trace
import Text.Megaparsec
import Text.Megaparsec.Char
import Text.Printf
type Parser = Parsec Void T.Text
type HeaderLevel = Int
newtype URL = URL {getUrl :: String} deriving (Eq)
newtype ImgPath = ImgPath {getPath :: String} deriving (Eq)
data MdToken
= Document [MdToken]
| Header HeaderLevel MdToken
| Para MdToken
| Line [MdToken]
| SingleNewline -- A single newline is rendered as a space.
| Linebreak
| HorizontalRule
| Blockquote [MdToken]
| UnordList [MdToken]
| OrdList [MdToken]
| Code MdToken
| Codeblock String
| Link MdToken URL
| Image MdToken URL
| Figure MdToken URL
| Bold MdToken
| Italic MdToken
| Strikethrough MdToken
| Unit String
deriving (Eq)
-- Deriving Show for MdToken
instance Show MdToken where
show (Document tokens) = concatMap show tokens
show (Header level token) = "
" ++ show token ++ "
\n" show (Line tokens) = concatMap show tokens show Linebreak = "" ++ concatMap show tokens ++ "" show (UnordList tokens) = "
" ++ show code ++ "
"
show (Codeblock code) = show code
show (Link txt url) = "" ++ show txt ++ ""
show (Image txt url) = "