Skip to content

Lua filters: allow using SimpleTable instead of Table #6575

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

Merged
merged 1 commit into from
Sep 20, 2020

Conversation

tarleb
Copy link
Collaborator

@tarleb tarleb commented Jul 29, 2020

Old filters using tables now require minimal changes and can use

if PANDOC_VERSION > {2,10,1} then
  pandoc.Table = function(c,a,w,h,r)
    return pandoc.utils.from_simple_table(pandoc.SimpleTable(c,a,w,h,r))
  end
end

and

function Table (tbl)
  smpl_tbl = pandoc.utils.to_simple_table(tbl)
  return pandoc.utils.from_simple_table(smpl_tbl)
end

to work with the current pandoc version.

@tarleb tarleb requested a review from jgm July 29, 2020 16:35
@tarleb tarleb marked this pull request as draft July 29, 2020 16:35
@tarleb
Copy link
Collaborator Author

tarleb commented Jul 29, 2020

A new block type SimpleTable would be introduced, effectively behaving like old Table blocks (except for the tag).

This is a draft, as I couldn't fully convince myself that this is the best way forward. It requires some unfortunate special-casing, but otherwise seems to work quite well.

@tarleb tarleb force-pushed the lua-simple-table branch from d3eeaf4 to 11017c7 Compare July 29, 2020 19:35
@jgm
Copy link
Owner

jgm commented Aug 11, 2020

A simpler approach might be not to add SimpleTable as a faux block element, but instead add a function that treats the element as a simple table. That is:

function Table(el)
  local el2 = to_simple_table(el)
  -- do stuff with el2
  return from_simple_table(el)
end

or maybe this could be encapsulated in one function

   with_simple_table(el, function(el2) ... end)

@tarleb
Copy link
Collaborator Author

tarleb commented Aug 12, 2020

If I understand correctly, then this would make SimpleTable a standalone type which does not inherit from type Block. We'd be moving the unmarshaling code for SimpleTable into a separate function, which is then exposed to Lua. That does seem cleaner.

@tarleb tarleb force-pushed the lua-simple-table branch 2 times, most recently from 36e0edf to 11df774 Compare August 12, 2020 10:21
@tarleb tarleb marked this pull request as ready for review August 12, 2020 10:22
@jgm
Copy link
Owner

jgm commented Sep 20, 2020

I'm sorry, I sort of lost track of this. Do you want to rebase so we can see if the tests pass?

@tarleb tarleb force-pushed the lua-simple-table branch 2 times, most recently from 0028c0f to b039379 Compare September 20, 2020 07:02
@tarleb
Copy link
Collaborator Author

tarleb commented Sep 20, 2020

Rebased, squashed, and updated the commit message.

@tarleb
Copy link
Collaborator Author

tarleb commented Sep 20, 2020

Cabal-based tests fail because

  1. there's a problem with text-conversions, which require us to add constraints: base16-bytestring < 1 to cabal.project and
  2. pandoc-citeproc hasn't been updated yet to allow pandoc-types-1.22.

Stack-based tests succeed.

@jgm
Copy link
Owner

jgm commented Sep 20, 2020

What's the problem with text-conversions?
And where do we depend on that library?

@jgm
Copy link
Owner

jgm commented Sep 20, 2020

I've pushed a commit that uses the dev version of pandoc-citeproc.

@tarleb
Copy link
Collaborator Author

tarleb commented Sep 20, 2020

Thanks!

What's the problem with text-conversions?

IIUC, then there has been a new release of base16-bytestring which breaks text-conversions, as that package does not set an upper bound for base16-bytestring. Relevant discussion.

And where do we depend on that library?

It is a dependency of doctemplates. It seems that we also use it in function addVariablesToContext in module Text.Pandoc.Writers.Shared.

A new type `SimpleTable` is made available to Lua filters. It is
similar to the `Table` type in pandoc versions before 2.10;
conversion functions from and to the new Table type are provided.

Old filters using tables now require minimal changes and can use,
e.g.,

    if PANDOC_VERSION > {2,10,1} then
      pandoc.Table = pandoc.SimpleTable
    end

and

    function Table (tbl)
      tbl = pandoc.utils.to_simple_table(tbl)
      …
      return pandoc.utils.from_simple_table(tbl)
    end

to work with the current pandoc version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants