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

merging adjacent table cells #240

Closed
sbonaretti opened this issue Jul 1, 2019 · 14 comments · Fixed by #251
Closed

merging adjacent table cells #240

sbonaretti opened this issue Jul 1, 2019 · 14 comments · Fixed by #251

Comments

@sbonaretti
Copy link

Hi! Is there a way to merge to (horizontally) adjacent cells in a table?
Thanks!!!

@slochower
Copy link
Collaborator

I don't think this is possible until the upstream Markdown processor that pandoc uses, implements it. There is a very long thread discussing the possibility and implementation details: jgm/pandoc#1024. I can't quite tell what the timescale is for this, but I'm confident that a lot of people care about this and the authors of pandoc seem to be taking it seriously.

@vincerubinetti
Copy link
Collaborator

vincerubinetti commented Jul 1, 2019

Unfortunately the only way to accomplish this right now is to write out the table "manually" (in html) in your markdown, and use colspan, like this:

<table>
 <tr>
  <td colspan="2"> </td>
  <td> </td>
 </tr>
 <tr>
  <td> </td>
  <td> </td>
  <td> </td>
 </tr>
 <tr>
  <td> </td>
  <td> </td>
  <td> </td>
 </tr>
</table>

image

Reference:
https://www.computerhope.com/issues/ch001655.htm

@dhimmel
Copy link
Member

dhimmel commented Jul 1, 2019

Unfortunately the only way to accomplish this right now is to write out the table "manually" (in html) in your markdown

@vincerubinetti are you sure the HTML table method works when passing through Pandoc? My understanding is that since Pandoc's Astract Syntax Tree doesn't support colspans, if the table gets interpreted by Pandoc, this solution won't work. However, I'm not sure whether Pandoc would interpret the table or just pass-through the HTML verbatim.

@vincerubinetti
Copy link
Collaborator

Just tested it, it does work. My understanding is that anything you write in plain HTML within a markdown file will just get passed through/ignored by pandoc. Is that consistent with your understanding?

@dhimmel
Copy link
Member

dhimmel commented Jul 1, 2019

Just tested it, it does work.

Good to know

Is that consistent with your understanding?

I don't have a good understanding, but I think it may be dependent on which input and output formats are chosen. When going from md to html, it seems that it keeps the HTML untouched rather than interpreting it as part of the AST.

@slochower
Copy link
Collaborator

It will pass through to the HTML output, but did you check that it also passes through to PDF and DOCX? That part I'm not sure about.

@vincerubinetti
Copy link
Collaborator

PDF output comes right from the HTML output, so as long as WeasyPrint/Athena supports colspan, it should work. As for docx, I don't know but I doubt it.

@slochower
Copy link
Collaborator

slochower commented Jul 1, 2019

I think that writing the table as HTML will also break the functionality used by by pandoc-tablenos.

@vincerubinetti thanks for checking!

@sbonaretti
Copy link
Author

sbonaretti commented Jul 3, 2019

I have finally tried this out. It works, and it was not hard. I opened the built .html and copied the table to my .md file.
I just have a new issue now: In some cells I reference to the literature. The md command @doi:something becomes something like <span class="citation" data-cites="aNdiyMUf">[<a href="#ref-aNdiyMUf" role="doc-biblioref">3</a>]</span> in the html, which obviously does not reference to anything - and I get an error during the built. Is there an easy fix to this? Thanks!!!

@dhimmel
Copy link
Member

dhimmel commented Jul 3, 2019

I opened the built .html and copied the table to my .md file.

Nifty solution. May be kind of a pain if you have to change the table or get table numbering to work, but cool to see the workaround.

I get an error during the built.

Can you paste the error text?

does not reference to anything

If Pandoc is still able to render the markdown in the HTML table cells, you could just revert the HTML citations back to the original citations. If you don't have too many citations in the table, it may just be easiest to do this manually. The output/citations.tsv file will show you the mapping from manuscript_id (e.g. doi:something) to short_id (e.g. @aNdiyMUf).

@vincerubinetti
Copy link
Collaborator

vincerubinetti commented Jul 3, 2019

I have one solution. The others might have different solutions.

Instead of copying the html of the table into your input markdown, I'd just leave the table as regular markdown, and add the colspan attribute into the output itself. The downside of this, though, is that every time you re-build the output, that colspan change will go away.

To solve this, we could create a plugin that looks for any cell that has some flag in commented-out text, say <!-- colspan:2 -->, and add the colspan html attribute to that cell dynamically. This should work for html output, and pdf output if Athena is being used (because it supports javascript).

So basically you'd use markdown tables like normal, but add a little extra text to specify the colspan (and also leave the appropriate preceding cells blank):

| Tables                      |     Are     |  Cool |
|-----------------------------|:-----------:|------:|
| col 1 <!-- colspan: 2 -->   |             | $1600 |
| col 2                       |     money   |   $12 |
| col 3                       |     money   |    $1 |

In fact, this could be useful for more than just tables. It could be a way to bypass the issue of markdown/pandoc not being able to attach parameters to any element. It could look for any comment in the format <!-- attribute: value -->, and add that property to whatever html element it's in.

@dhimmel
Copy link
Member

dhimmel commented Jul 3, 2019

we could create a plugin that looks for any cell that has some flag in commented-out text

This is a cool idea. Won't work for DOCX outputs (but will an HTML table in a markdown input get converted to DOCX?).

@vincerubinetti happy for you to prototype this solution if you have time. If it works, we could include it as in the plugins directory (perhaps not added to the build command by default). I'm interested to see whether it works, and how general of a workaround it could be for "unsupported by pandoc" things.

@slochower
Copy link
Collaborator

Would be nice to look for a <!-- colspan: 2 --> attribute. That would be super helpful.

I'm fairly certain an HTML table embedded in Markdown will not get converted to DOCX with pandoc. I know that other HTML, like <span class="red">this is red text</span> embedded in the Markdown get dropped going to DOCX.

@sbonaretti
Copy link
Author

sbonaretti commented Jul 22, 2019

@dhimmel

Can you paste the error text?

Here it is: ERROR: No anchor #aNdiyMUf for internal URI reference

I have noticed that:

  • If I cite the paper somewhere else in my text, I get the clickable link to the citation in the rendered HTML table - I simply add the markdown command into the HTML line (e.g. <td>Clark et al. [@doi:10.1101/657676]</td>)
  • If I do NOT cite the paper somewhere else in my text, I get the error above

Hope this helps

dhimmel pushed a commit that referenced this issue Sep 11, 2019
Merges #251
Closes #264
Refs #240

Uses javascript to apply attributes extracted from HTML comments.
dhimmel pushed a commit that referenced this issue Sep 11, 2019
This build is based on
0dc5ea8.

This commit was created by the following Travis CI build and job:
https://travis-ci.com/manubot/rootstock/builds/127061386
https://travis-ci.com/manubot/rootstock/jobs/234117445

The full commit message that triggered this build is copied below:

Plugin to set HTML attributes via comments

Merges #251
Closes #264
Refs #240

Uses javascript to apply attributes extracted from HTML comments.
dhimmel pushed a commit that referenced this issue Sep 11, 2019
This build is based on
0dc5ea8.

This commit was created by the following Travis CI build and job:
https://travis-ci.com/manubot/rootstock/builds/127061386
https://travis-ci.com/manubot/rootstock/jobs/234117445

The full commit message that triggered this build is copied below:

Plugin to set HTML attributes via comments

Merges #251
Closes #264
Refs #240

Uses javascript to apply attributes extracted from HTML comments.
rhagenson pushed a commit to rhagenson/biological-messaging that referenced this issue Sep 18, 2019
This build is based on
0dc5ea8.

This commit was created by the following Travis CI build and job:
https://travis-ci.com/RHagenson/biological-messaging/builds/128096845
https://travis-ci.com/RHagenson/biological-messaging/jobs/236645304

The full commit message that triggered this build is copied below:

Plugin to set HTML attributes via comments

Merges manubot/rootstock#251
Closes manubot/rootstock#264
Refs manubot/rootstock#240

Uses javascript to apply attributes extracted from HTML comments.
rhagenson pushed a commit to rhagenson/biological-messaging that referenced this issue Sep 18, 2019
This build is based on
0dc5ea8.

This commit was created by the following Travis CI build and job:
https://travis-ci.com/RHagenson/biological-messaging/builds/128096845
https://travis-ci.com/RHagenson/biological-messaging/jobs/236645304

The full commit message that triggered this build is copied below:

Plugin to set HTML attributes via comments

Merges manubot/rootstock#251
Closes manubot/rootstock#264
Refs manubot/rootstock#240

Uses javascript to apply attributes extracted from HTML comments.
adebali pushed a commit to CompGenomeLab/lemur-manuscript-archive that referenced this issue Mar 4, 2020
Merges manubot/rootstock#251
Closes manubot/rootstock#264
Refs manubot/rootstock#240

Uses javascript to apply attributes extracted from HTML comments.
ploegieku added a commit to ploegieku/2023-functional-homology-paper that referenced this issue Aug 6, 2024
Merges manubot/rootstock#251
Closes manubot/rootstock#264
Refs manubot/rootstock#240

Uses javascript to apply attributes extracted from HTML comments.
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

Successfully merging a pull request may close this issue.

4 participants