Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monadic blockRender? #46

Closed
mrkgnao opened this issue Mar 4, 2018 · 3 comments · May be fixed by #117
Closed

Monadic blockRender? #46

mrkgnao opened this issue Mar 4, 2018 · 3 comments · May be fixed by #117

Comments

@mrkgnao
Copy link

mrkgnao commented Mar 4, 2018

I'd like to render LaTeX diagrams into images that are then inserted into the output. I have a function of the following form:

-- | Render some LaTeX content to an image whose filename is the 
-- hash of the content. Return the path to the image.
renderToFile :: Text -> IO FilePath
renderToFile latex = do
   ...
   pure savePath

I think the interface I would like is to interpret code-blocks with some particular infostring (e.g. render-latex) as LaTeX to be rendered into a PNG. If blockRenderM existed, I could just do

renderLatexExt :: Extension
renderLatexExt = blockRenderM $ \case
  CodeBlock (Just "render-latex") content 
    -> (\uri -> Image undefined uri Nothing) <$> renderToFile content
  x -> pure x

or something.

@mrkkrp
Copy link
Member

mrkkrp commented Jul 8, 2024

I have exposed enough of the internal machinery in #116, so it should be possible to write arbitrary custom renders.

@mrkkrp mrkkrp closed this as completed Jul 8, 2024
@emekoi
Copy link

emekoi commented Jul 8, 2024

I actually implemented #116 in a local fork of mmark to try to write a monadic renderer and I don't think it's sufficient since extensions and renderers are currently pure (they are basically records of Endos) and specialized to produce HtmlT Identity () so you can't change the underlying monad. Supporting monadic extensions and renderers amounts to replacing Endo a with Kleisli m a a so you get some type like MMarkT m and MMark = MMarkT Identity.

@mrkkrp
Copy link
Member

mrkkrp commented Jul 9, 2024

@emekoi Could you open a PR for that?

emekoi added a commit to emekoi/mmark that referenced this issue Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants