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

migration to 2.10+ #1

Open
kysko opened this issue Sep 24, 2020 · 9 comments
Open

migration to 2.10+ #1

kysko opened this issue Sep 24, 2020 · 9 comments

Comments

@kysko
Copy link

kysko commented Sep 24, 2020

Moved this comment here from pandoc issues:

Note that it currently only works with pandoc < 2.10 (if anybody understands the pandoc 2.10 table model a pull request is most welcome! :-)

Check the latest pandoc nightly for SimpleTable support by tarleb, or next pandoc 2.11.

In your table2lol function, at line 233, use something like:

--local tab = div.content[1]
local tab = pandoc.utils.to_simple_table(div.content[1])

And in your lol2table function, at line 185, use something like:

--local ok, res = pcall(pandoc.Table, caption, aligns, widths, headers, rows)
local ok, res = pcall(pandoc.SimpleTable, caption, aligns, widths, headers, rows)
assert(ok, "Error converting list to table in " .. tostring(div_id) .. ": " .. tostring(res))  -- no change here
res = pandoc.utils.from_simple_table(res)  -- ugly, but you get the point
-- or without the pcall:
-- local res =  pandoc.utils.from_simple_table( pandoc.SimpleTable(caption, aligns, widths, headers, rows) )
@bpj
Copy link
Owner

bpj commented Sep 24, 2020

Thanks @kysko I didn't know that the SimpleTable stuff by @tarleb already had made it into master. Hopefully 2.11 will be released soon.

P.S. Note that any modifications should be made in the MoonScript code since the Lua code is autogenerated from the MoonScript code. It's OK for this comment though; I can certainly locate/translate.

@bpj
Copy link
Owner

bpj commented Sep 24, 2020

BTW the reason I use pcall is so that non-technical users will get a more sensible error message.

@kysko
Copy link
Author

kysko commented Sep 25, 2020

Just to add an idea:
If you ever want to introduce row spans and col spans with the new Table scheme, one way could be through a special Div as a list item.
For example, this:

::: {.lol2table}
*   -   foo
    -   bar
    -   baz

*   -   ::: {.tbcell rs=2 cs=2}
        a big
        
        chunk
        :::

    -   one

*   -   two
:::

could be equivalent to this (if I use the docutils grid table notation):

+-------+-------+-----+
| foo   | bar   | baz |
+=======+=======+=====+
| a big         | one |
|               +-----+
| chunk         | two |
+---------------+-----+

with a Div with the keyvals rs and cs for row span and col span resp, and class tbcell to identify its purpose as a cell.
(The Div attributes can also serve for individual cells alignments, etc, even if no rs or cs is given.)

Of course one would have to be very careful to create a valid table, might not be self-evident with complex mix of row spans and col spans.
Essentially, one would mimic what would be in the AST for the table, row by row, or as if one would construct an HTML table.
(The above could require that empty cells be represented by empty list items.)

There's no pandoc-markdown reader or writer for complex tables right now, so one would need to wait for 'round-tripping'.

Anyways, that's just an idea for you if you ever want to tackle complex tables.

@bpj
Copy link
Owner

bpj commented Sep 25, 2020

@kysko wrote:

If you ever want to introduce row spans and col spans with the new Table scheme, one way could be through a special Div as a list item.

Thanks. I have already thought along those lines myself. One problem with it is that I already make somewhat heavy use of divs around list item content in order to style table cell content, both for HTML/CSS styling and for injecting LaTeX code with filters. One would have to use nested divs and be careful to put any content styling div inside the cell styling div.

Actually complex tables was the only thing which I preferred to do in a WYSIWYG editor back in the days when I wrote much HTML by hand. It was hard to keep the cell/row spans straight in my head without the visual feedback. I guess using ordered lists would alleviate this a lot, since you could then just "skip" the list numbers for "merged" cells in the rows and keep track of the row numbers in the source, things which I used to do with the help of HTML comments or ids of the form my-table-2-4--3-5, meaning a cell which spanned columns 2 to 4 and rows 3 to 5. It was very easy to get confused anyway!

@kysko
Copy link
Author

kysko commented Sep 25, 2020

I already make somewhat heavy use of divs around list item content in order to style table cell content, both for HTML/CSS styling and for injecting LaTeX code with filters.

Well then, if you already make use of cell-englobing divs, perhaps this might an advantage rather than a problem: the use of the keyvals rs and cs (or better, rowspan and colspan for that matter) would not be heavier than what one would use on td tags in HTML.
Of course, the more details you want to support of the new scheme (at cell level), the heavier the div attributes would be... but that is also true of td tag attributes and styling (quite similar in fact).
(It does get very heavy at other levels when introducing global header and footer, stubs, multibody...)

So you could proceed as usual, but being careful at reserving certain class names (.alignright, .alignleft, etc) and keyval keys for specific use (rowspan, colspan, etc), and mimic HTML td tag construction. There would be no need for nested divs, just add the classes/keyvals to your already existing cell-englobing div.

But your specific real-world uses are surely more complex than the test cases, so I might not see the forest nor the trees!

@bpj
Copy link
Owner

bpj commented Sep 30, 2020

@kysko you may want to check out the SimpleTable branch before I merge it with master tomorrow. [1]

It is updated to use and convert from/to SimpleTable if it exist and to throw an error if it doesn't exist and PANDOC_VERSION >= 2.10.0.

40a222b has the main changes although some fixes were added later

[1]: Since I had omitted to state a version number I decided to use YYYYMMDD[HH] as version number, and I want the version with these updates to be version 20201001! 😃

@kysko
Copy link
Author

kysko commented Oct 1, 2020

After a quick look at the lua file (simpletable branch) and a quick test, it seems to look fine.


Just for fun, to kill some time, I rewrote the Lua version of lol2table to support rowspan, colspan, a footer, along my last example notation above. It exports to HTML and Native in simple cases, didn't do extensive tests.

Since my use of pandoc-list-table has only been limited to a few tests, in pure dilettantism 😄 , and not for extensive real-world use like you, it might not cover all the bases...

It's not a pull request, just a personal unpublished mod for fun, so not in MoonScript.

If you're interested, just for inspiration, I can make a temporary gist for you. You'll eventually make your choices on how to handle rowspans and colspans, but this might give you some ideas.

Nothing done for table2lol, complex table format too rich for now for a lol format that doesn't support yet such details, and one would need to devise a fallback to current notation.

@bpj
Copy link
Owner

bpj commented Oct 1, 2020 via email

@kysko
Copy link
Author

kysko commented Oct 3, 2020

Crazy days...

Anywhoo, I finally created the gist for the mod I was telling you about, after this and that and this and that addition/removal/changes... there's always something!

Take what you want from it. The main point is how to manipulate the information with the new richer Table format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants