pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

Update Lua MediaBag interface

Open jgm opened this issue 4 years ago • 4 comments

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?

jgm avatar May 24 '21 16:05 jgm

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?

tarleb avatar May 24 '21 19:05 tarleb

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.

jgm avatar May 24 '21 20:05 jgm

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:

  1. Make pandoc.mediabag.list and pandoc.mediabag.items take an additional parameter that controls whether MediaItems are returned instead of the current ad-hoc values. The functions pandoc.mediabag.insert and pandoc.mediabag.delete could check whether they are used with a MediaItem and behave accordingly.
  2. Alternatively, we could add functions pandoc.get_mediabag() (or pandoc.mediabag.get(). Then we'd be completely free to define the behavior of the new MediaBag Lua type. A typical workflow would then be
    local 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.

tarleb avatar Jun 11 '22 17:06 tarleb

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.

jgm avatar Jun 11 '22 18:06 jgm