pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
602 stars 165 forks source link

Add filter list-table #202

Closed not-my-profile closed 2 years ago

not-my-profile commented 2 years ago

Inspired by reStructuredText and the feature request https://github.com/jgm/pandoc/issues/7305.

mustafa0x commented 2 years ago

Thanks for this! Is there any way to mark added fields?

I tried something like this but couldn't figure out how to fix it.

    for i = 1, #list.content do
        assert(#list.content[i] == 1, "expected item to contain only one block")
        assert(list.content[i][1].t == "BulletList",
               "expected bullet list, found " .. list.content[i][1].t)
        table.insert(rows, list.content[i][1].content)

        local rows1 = list.content[i][1]
        for j = 1, #rows1 do
          local row = rows1[j].content
          while #row < col_count do
            row_copy = {content={}}
            row_copy[1].content[1].text = 'ADDED_FIELD'
            row[#row + 1] = row_copy
          end
        end
    end
not-my-profile commented 2 years ago

You're welcome :) I am afraid I don't understand what you're trying to achieve. What are "added fields"? Why do you want to mark them?

mustafa0x commented 2 years ago

Sorry, I should've explained more!

$> pandoc --lua-filter list-table.lua

::: list-table
*   - a
    - b
*   - c
:::
<table>
  <caption></caption>
  <thead>
    <tr class="header">
      <th>a</th>
      <th>b</th>
    </tr>
  </thead>
  <tbody>
    <tr class="odd">
      <td>c</td>
      <td></td> <!-- <<< added-->
    </tr>
  </tbody>
</table>

The optimal solution would be to add colspan=2, but I don't think this filter supports that, and it would require some work I believe. So as a workaround, if any added fields could be marked somehow, so I could later remove using .replace('<td>MAGIC_STRING</td>', '').

Thank you!