Open lsmor opened 2 years ago
first: if there is an image reference but the image is not in the filesytem then the writer fails completely, instead of producing a broken link to the image
This could be addressed by handling the error raised by fetchItem. Would that be a simpler approach than adding a new extension?
This could be addressed by handling the error raised by fetchItem. Would that be a simpler approach than adding a new extension?
Well, the error is simply Left (PandocResourceNotFound "path/to/image.png")
. You can handle that... but the goal is to produce and ipynb
in which images aren't attachments but regular markdown image links, I don't think handle it helps. Moreover, you still have the problem of not being able to use runPure
if using the pandoc library.
I am thinking about a nasty filter which converts images to links with a !
in front. Let me check if that works.
I turned out, that a simple filter can be used. Shame on me! I am closing this as no changes needed.
imageToLink :: Pandoc.Block -> Pandoc.Block
imageToLink (Pandoc.Para (Pandoc.Image attrs inl target:is)) = Pandoc.Para $ Pandoc.Str "!":Pandoc.Link attrs inl target:is
imageToLink i = i
You can handle that... but the goal is to produce and ipynb in which images aren't attachments but regular markdown image links, I don't think handle it helps.
Why not? We could handle the error by just including a regular image link with that path, and issuing a warning.
you still have the problem of not being able to use runPure if using the pandoc library.
fetchItem can be used with runPure. It won't do any actual IO, but it will still look in the ersatz file system, and it will raise an error if nothing else -- which can be trapped.
Let's keep this open.
Maybe I am a little bit lost, are you proposing to actually change the code so writeIpynb
handles such an error? I am happy to contribute to that (Notice that my actual problem all images must be links can be solved with a simple filter)
Comming back to writeIpynb
, I guess addAttachment
can be modified to handle that error and not modify the Image
part. I am not so sure how to actually handle the error though. Is there any example within the code base I can look at? (I am not that familiarize with pandoc
but I know enough Haskell to follow along the types)
Describe your proposed improvement and the problem it solves.
By default,
pandoc
will create attachments for image links when writingipynb
as stated by the documentation. The waypandoc
creates those, is via addAttachment function in theIpynb
writer. Such a function depends on fetchItem which as far as I can tell is meant to read the rawByteString
from file system.This has two problems:
pandoc
library, thenPandoc.runPure
can't simply work, becausefetchItem
can't do anyIO
to grab the raw bytes of the image. This is shown in the example below, in whichrunPure
fails butrunIO
doesn'tI think this change could by adressed by changing function extractCells so instead of calling
addAttachment
it checks first if the extension is enable. If it is, then do not modify theInline
, else modify it. This will create a regularmarkdown
imagen link instead of an attachmentI think I can implement this change if you confirm this is the way yo go.
Describe alternatives you've considered.
I read the documentation looking for other options to achive this or manipulating the raw
Text
produced bywriteIpynb
(I am working with pandoc the library)