Update Lua MediaBag interface
Commit 8511f6fdf6c9fbc2cc926538bca4ae9f554b4ed9 changes the MediaBag type and the lookupMedia return value to a MediaItem. It might be good to update the Lua interface so we have access to the MediaItem in Lua. Currently I've modified this so the interface is just as it was in the past.
@tarleb what do you think?
That'd be nice, I think. It would give a more consistent interface than the current version. I'm not sure, is it better do a big "Lua rewrite" release once the new architecture is done, or is it preferable to introduce those changes more gradually?
I don't know; whatever works best for you is fine with me! Certainly it doesn't block a release to have the current behavior.
I'm was trying to come up with ways to do this in a backwards compatible fashion. These are the two options that I liked best:
- Make
pandoc.mediabag.listandpandoc.mediabag.itemstake an additional parameter that controls whether MediaItems are returned instead of the current ad-hoc values. The functionspandoc.mediabag.insertandpandoc.mediabag.deletecould check whether they are used with a MediaItem and behave accordingly. - Alternatively, we could add functions
pandoc.get_mediabag()(orpandoc.mediabag.get(). Then we'd be completely free to define the behavior of the new MediaBag Lua type. A typical workflow would then belocal mediabag = pandoc.get_mediabag() for item in mediabag:items() do print(item.path, item.mime_type) end mediabag:insert(mediabag.fetch('./image.png'))
Option two seems cleaner, but the idea of maintaining new code in parallel to the current version makes it a bit less attractive.
Option 3, of course, would be to do a breaking change.
Not sure what is best. One possibility would option 2 with a deprecation of the old behavior, with the idea that we wouldn't support the old code indefinitely.