fixed toText issue
This commit is contained in:
parent
b8d76d7663
commit
667477e01d
1 changed files with 15 additions and 5 deletions
|
|
@ -25,12 +25,21 @@ import qualified Text.Megaparsec.Stream as MPS
|
||||||
|
|
||||||
type Parser = ParsecT Void
|
type Parser = ParsecT Void
|
||||||
|
|
||||||
class (Token s ~ Char, Stream s, IsString (Tokens s), Monoid (Tokens s), Eq (Tokens s), Show s) => Characters s
|
class (Token s ~ Char, Stream s, ToText (Tokens s), IsString (Tokens s), Monoid (Tokens s), Eq (Tokens s), Show s) => Characters s
|
||||||
|
|
||||||
|
class ToText t where
|
||||||
|
toText :: t -> Text
|
||||||
|
|
||||||
instance Characters Text
|
instance Characters Text
|
||||||
|
|
||||||
|
instance ToText Text where
|
||||||
|
toText = id
|
||||||
|
|
||||||
instance Characters String
|
instance Characters String
|
||||||
|
|
||||||
|
instance ToText String where
|
||||||
|
toText = T.pack
|
||||||
|
|
||||||
string :: (MP.MonadParsec e s m) => Tokens s -> m (Tokens s)
|
string :: (MP.MonadParsec e s m) => Tokens s -> m (Tokens s)
|
||||||
string = chunk
|
string = chunk
|
||||||
|
|
||||||
|
|
@ -169,7 +178,6 @@ htmlBlock = do
|
||||||
notFollowedBy blockEnding
|
notFollowedBy blockEnding
|
||||||
ending <- tagNameEnd
|
ending <- tagNameEnd
|
||||||
hasEnded <- case ending of
|
hasEnded <- case ending of
|
||||||
'/' -> fail "no opening tag"
|
|
||||||
'>' -> pure True
|
'>' -> pure True
|
||||||
_ -> pure False
|
_ -> pure False
|
||||||
attrs <-
|
attrs <-
|
||||||
|
|
@ -177,11 +185,13 @@ htmlBlock = do
|
||||||
then
|
then
|
||||||
error "TODO: handle attributes"
|
error "TODO: handle attributes"
|
||||||
else pure Nothing
|
else pure Nothing
|
||||||
inside <- many (notFollowedBy (chunk $ "<" <> tagName <> "/>"))
|
-- technically not standard markdown but I don't want to write a full HTML parser in my
|
||||||
pure $ HTML $ HTMLTag $ T.concat ["<", tagName, fromMaybe "" attrs, ">"]
|
inside <- many (notFollowedBy ((chunk $ "</" <> tagName <> ">") <|> chunk "</>") *> anySingle)
|
||||||
|
end <- toText <$> ((chunk $ "</" <> tagName <> ">") <|> chunk "</>")
|
||||||
|
pure $ HTML $ HTMLTag $ T.concat ["<", toText tagName, fromMaybe "" attrs, ">", T.pack inside, if end == "</>" then "" else end]
|
||||||
where
|
where
|
||||||
tagNameEnd :: Parser s m Char
|
tagNameEnd :: Parser s m Char
|
||||||
tagNameEnd = spaceChar <|> char '>' <|> char '/'
|
tagNameEnd = spaceChar <|> char '>'
|
||||||
|
|
||||||
paragraphBlock :: (Logger m, Characters s) => Parser s m Element
|
paragraphBlock :: (Logger m, Characters s) => Parser s m Element
|
||||||
paragraphBlock = Paragraph . P <$> (many inlineText)
|
paragraphBlock = Paragraph . P <$> (many inlineText)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue