1
1
mirror of https://github.com/srid/rib.git synced 2024-11-26 13:50:31 +03:00

Remove renderDoc from type class

This commit is contained in:
Sridhar Ratnakumar 2019-11-26 14:25:45 -05:00
parent 3d24954226
commit 7f9a25e0d6
3 changed files with 5 additions and 16 deletions

View File

@ -72,10 +72,5 @@ class Markup repr where
"path" :! Path b File -> "path" :! Path b File ->
IO (Either (MarkupError repr) (Document repr)) IO (Either (MarkupError repr) (Document repr))
-- | Render the document as Lucid HTML
renderDoc ::
Document repr ->
Either (MarkupError repr) (Html ())
-- | Convert `MarkupError` to string -- | Convert `MarkupError` to string
showMarkupError :: MarkupError repr -> Text showMarkupError :: MarkupError repr -> Text

View File

@ -49,15 +49,13 @@ instance Markup MMark where
content <- readFileText (toFilePath f) content <- readFileText (toFilePath f)
pure $ parseDoc k content pure $ parseDoc k content
renderDoc = Right . MMark.render . _document_val
showMarkupError = toText . M.errorBundlePretty showMarkupError = toText . M.errorBundlePretty
-- | Parse and render the markup directly to HTML -- | Parse and render the markup directly to HTML
renderMarkdown :: Text -> Html () renderMarkdown :: Text -> Html ()
renderMarkdown s = either (error . showMarkupError @MMark) id $ runExcept $ do renderMarkdown s = either (error . showMarkupError @MMark) id $ runExcept $ do
doc <- liftEither $ parseDoc @MMark [relfile|<memory>.md|] s doc <- liftEither $ parseDoc @MMark [relfile|<memory>.md|] s
liftEither $ renderDoc doc pure $ MMark.render $ _document_val doc
-- | Get the first image in the document if one exists -- | Get the first image in the document if one exists
getFirstImg :: MMark -> Maybe URI getFirstImg :: MMark -> Maybe URI

View File

@ -73,20 +73,16 @@ instance Markup Pandoc where
mkDoc k mkDoc k
<$> parse r content <$> parse r content
renderDoc =
fmap toHtmlRaw
. first RibPandocError_PandocError
. liftEither
. render'
. _document_val
showMarkupError = toText @String . show showMarkupError = toText @String . show
-- | Parse and render the markup directly to HTML -- | Parse and render the markup directly to HTML
renderPandoc :: Path Rel File -> Text -> Html () renderPandoc :: Path Rel File -> Text -> Html ()
renderPandoc f s = either (error . showMarkupError @Pandoc) id $ runExcept $ do renderPandoc f s = either (error . showMarkupError @Pandoc) id $ runExcept $ do
doc <- liftEither $ parseDoc @Pandoc f s doc <- liftEither $ parseDoc @Pandoc f s
liftEither $ renderDoc doc liftEither
$ first RibPandocError_PandocError
$ render'
$ _document_val doc
-- | Pure version of `parse` -- | Pure version of `parse`
parsePure :: parsePure ::