Giter Club home page Giter Club logo

list-table's Introduction

list-table

List tables for Pandoc.

This is the documentation for list-table.lua, a Lua filter to bring RST-style list tables to Pandoc's Markdown.

This filter depends on the fenced_divs pandoc extension, which is enabled by default for commonmark_x, markdown and opml but will have to be enabled explicitly for other markdown variants.

List tables are not only easy-to-write but also produce clean diffs since you don't need to re-align all the whitespace when one cell width changes. This filter lets you use RST-inspired list tables in markdown. Any div with the first class list-table is converted, for example the following Markdown:

:::list-table
   * - row 1, column 1
     - row 1, column 2
     - row 1, column 3

   * - row 2, column 1
     -
     - row 2, column 3

   * - row 3, column 1
     - row 3, column 2
:::

results in the following table:

row 1, column 1 row 1, column 2 row 1, column 3
row 2, column 1 row 2, column 3
row 3, column 1 row 3, column 2

The filter also supports more advanced features, as described in the following sections.

Table captions

If the div starts with a paragraph, its content is used as the table caption. For example:

:::list-table
   Markup languages

   * - Name
     - Initial release

   * - Markdown
     - 2004

   * - reStructuredText
     - 2002
:::

results in:

Markup languages
Name Initial release
Markdown 2004
reStructuredText 2002

Column alignments

With the aligns attribute you can configure column alignments. When given the value must specify an alignment character (d, l, r, or c for default, left, right or center respectively) for each column. The characters must be separated by commas.

:::{.list-table aligns=l,c}
   * - Name
     - Initial release

   * - Markdown
     - 2004

   * - reStructuredText
     - 2002
:::

results in:

Name Initial release
Markdown 2004
reStructuredText 2002

Column widths

With the widths attribute you can configure column widths via comma-separated numbers. The column widths will be relative to the numbers. For example when we change the first line of the previous example to:

:::{.list-table widths=1,3}

the second column will be three times as wide as the first column.

Header rows & columns

You can configure how many rows are part of the table head with the header-rows attribute (which defaults to 1).

:::{.list-table header-rows=0}
   * - row 1, column 1
     - row 1, column 2

   * - row 2, column 1
     - row 2, column 2
:::

results in:

row 1, column 1 row 1, column 2
row 2, column 1 row 2, column 2

The same also works for header-cols (which however defaults to 0). For example:

:::{.list-table header-cols=1}
   * - Name
     - Initial release

   * - Markdown
     - 2004

   * - reStructuredText
     - 2002
:::

results in:

Name Initial release
Markdown 2004
reStructuredText 2002

Cell attributes

If the first inline element of a table cell is an empty Span, it is removed and its attributes are transferred to the table cell. The colspan and rowspan attributes are supported.

:::{.list-table}
   * - Name
     - Italic
     - Code

   * - Markdown
     - []{rowspan=2} `*italic*`
     - `` `code` ``

   * - reStructuredText
     - ` ``code`` `
:::

results in:

Name Italic Code
Markdown *italic* `code`

reStructuredText

``code``

Individual cell alignment is also supported via the align attribute. Expected values are l, r, c for left, right and center respectively. (Please mind that contrary to column alignments this attribute is singular).

Row attributes

If the first block element of a table row contains (only) an empty Span, it is removed and its attributes are transferred to the table row.

:::{.list-table}
- []{style="background: lightblue"}
  - Ocean
  - Area (sq. miles)
- - Atlantic
  - 41.1 million
- - Pacific
  - 63.8 million
:::

results in (the background style won't be shown on github.com):

Ocean Area (sq. miles)
Atlantic 41.1 million
Pacific 63.8 million

Multiple bodies

If a list row is a table (which might also have been created by the list-table.lua filter), its rows become a new table body. Table bodies can't have header rows (.list-table-body is the same as .list-table except that header-rows defaults to 0).

:::{.list-table header-rows=0}
:::{.list-table-body}

This:

:::{.list-table style="background: lightsalmon"}
* - Fish
  - Ocean

* :::{.list-table-body style="background: lightgreen"}
  - - Arctic char
    - Arctic
  - - Humuhumunukunukuāpuaʻa
    - Pacific
  :::

* |               |           |
  |---------------|-----------|
  | Cod           | Atlantic  |
  | Notothenioids | Antarctic |
:::

results in (the background style won't be shown on github.com):

Fish Ocean
Arctic char Arctic
Humuhumunukunukuāpuaʻa Pacific
Cod Atlantic
Notothenioids Antarctic

Error reporting

If an unexpected element is encountered, the filter will attempt to output the offending text (as markdown) before asserting.

:::{.list-table}
- []{style="background:lightblue"}
  - Ocean
  - Area (sq. miles)
- - Atlantic
  - 41.1 million
- Pacific
  63.8 million
:::
Error running filter list-table.lua:
../list-table.lua:167: expected bullet list, found Plain at
Pacific 63.8 million

stack traceback:
	list-table.lua:51: in upvalue 'assert_'
	list-table.lua:167: in function <list-table.lua:126>

list-table's People

Contributors

not-my-profile avatar tarleb avatar wlupton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

wlupton coreyt

list-table's Issues

Installing the filter

Hi,

I know this is a basic question, but as a novice I can't find an answer. The list-table.lua filter has worked up to now, but then I updated Quarto, and apparently it has gone.

I've downloaded it again, but can't remember how to install it. I tried moving the file in the Applications/quarto/share/filter folder in my Mac Monterey, but it looks like Quarto is not finding it.

Are there installation instructions that I can read?

Paolo

list-table.lua throws version-number error when called via --filter, but works with --lua-filter

I did a bunch of trial and error, but this error message really threw me for a loop. Running

pandoc test.md -o test.pdf --filter ./list-table.lua

I get the error lua: /home/jules/.pandoc/lua_filters/list-table3.lua:8: pandoc version >=2.11 is required . (Needless to say, I am using a newer version.) The filter works as expected when calling it via:

pandoc test.md -o test.pdf --lua-filter ./list-table.lua

This LUA filter stopped working with the format `commonmark_x`, and is not displayed correctly with the format `markdown_github` on Codebraid

Hello!

  • I use the latest version of @jgm's Pandoc;
  • I use the latest version of @gpoore's Codebraid and Codebraid Preview;
  • I use mostly the format markdown_github because of supported features.

Here is a small YAML default file code:

filters:
  - assets/filters/lua/list-table.lua
template: "assets/templates/confluence"
variables:
  confluence_html: true
  languages:
    - english
    - español
    - français
    - português

And VSCode's Codebraid settings:

{
  "codebraid.preview.css.overrideDefault": true,
  "codebraid.preview.css.useDefault": true,
  "codebraid.preview.css.useMarkdownPreviewFontSettings": true,
  "codebraid.preview.pandoc.defaultsFile": "confluence.yaml",
  "codebraid.preview.pandoc.executable": "pandoc",
  "codebraid.preview.pandoc.showRaw": true,
  "codebraid.preview.pandoc.showStderr": "never",
  "codebraid.preview.security.allowEmbeddedScripts": true,
  "codebraid.preview.security.allowInlineScripts": true,
  "codebraid.preview.security.allowLocalScripts": true,
  "codebraid.preview.security.allowRemoteFonts": true,
  "codebraid.preview.security.allowRemoteImages": true,
  "codebraid.preview.security.allowRemoteMedia": true,
  "codebraid.preview.security.allowRemoteScripts": true,
  "codebraid.preview.security.allowRemoteStyles": true,
  "codebraid.preview.scrollEditorWithPreview": true,
  "codebraid.preview.scrollPreviewWithEditor": true,
  "codebraid.preview.pandoc.build": 
  {
    "*.md": 
    {
      "reader": "markdown_github",
      "preview": 
      {
        "html": 
        {
          "defaults": {},
          "options": 
          [
            "--preserve-tabs",
            "--standalone",
            "--wrap=auto",
          ]
        }
      },
      "export": {}
    },
  },
}

Here is a small Pandoc template code:

$if(confluence_html)$
<html $if(lang)$lang="$lang$" $endif$>

<head>
	<meta charset="UTF-8" />
	<meta name="generator" content="pandoc" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title>
</head>

<body>
	$endif$
	<div class="ids-markdown">
		Testing...
		$body$
	</div>
	$if(confluence_html)$
</body>

</html>
$endif$

I tested the simple list-table code in a Markdown file:

# Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit, minus?

Lorem ipsum dolor, sit amet consectetur adipisicing elit. Vero, adipisci sequi? Maiores autem quaerat praesentium?

:::list-table
   * - row 1, column 1
     - row 1, column 2
     - row 1, column 3

   * - row 2, column 1
     -
     - row 2, column 3

   * - row 3, column 1
     - row 3, column 2
:::

I tested with the markdown_github format and here is the result. It failed to render the code:

It failed to display the list-table code with the markdown_github format

I switched to the format commonmark_x and tested it. Here is the error:

Screenshot – Codebraid Preview error with the commonmark_x format

If some cells are undefined, the filter can generate an invalid AST

If some cells are undefined, the filter can generate an invalid AST. For example, with this markdown:

::: list-table
* - A
  - B

* - 1
:::

...we get the following (edited to show just the offending rows; rep.lua reports the AST using the logging module; see below):

% pandoc-3.1.8 -L list-table.lua list-table-bug.md -L rep.lua -t html -o /dev/null
(#) blocks Blocks[1] {
  [1] Table {
    ...
    bodies: List[1] {
      [1] {
        ...
        body: List[1] {
          [1] pandoc.Row {
            ...
            cells: List[1] {
              [1] pandoc.Cell {
                alignment: "AlignDefault"
                attr: Attr {
                  attributes: AttributeList {}
                  classes: List {}
                  identifier: ""
                }
                col_span: 1
                contents: Blocks[1] {
                  [1] Plain {
                    content: Inlines[1] {
                      [1] Str "1"
                    }
                  }
                }
                row_span: 1
              }
            }
          }
        }
        ...

The row only contains a single cell, so this is an invalid AST and isn't handled correctly by all writers (see jgm/pandoc#9096 for further discussion).

The filter should be updated to add empty cells for any missing ones.

Here's rep.lua

local logging = require 'logging'
function Pandoc(pandoc)
    if logging.loglevel > 0 then
        logging.temp('meta', pandoc.meta)
    end
    logging.temp('blocks', pandoc.blocks)
end

DOCX output doesn't seem to work.

Using this filter for ODT / HTML / LaTeX works, but when I try DOCX output the filter fails:

▶︎ pandoc -s -o list-table.docx -L list-table.lua --verbose list-table.md
[INFO] Running filter /Users/ian/.local/share/pandoc/filters/list-table.lua
[INFO] Completed filter /Users/ian/.local/share/pandoc/filters/list-table.lua in 43 ms
Encountered unassigned table cell
Exception: pandoc exited with 63

▶︎ pandoc -s --pdf-engine=xelatex -o list-table.pdf -L list-table.lua  --verbose list-table.md 
[INFO] Running filter /Users/ian/.local/share/pandoc/filters/list-table.lua
[INFO] Completed filter /Users/ian/.local/share/pandoc/filters/list-table.lua in 5 ms
[makePDF] temp dir: ... OK

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.