{"id":22454241,"url":"https://github.com/bpj/pandoc-table-columns","last_synced_at":"2025-07-13T09:35:47.582Z","repository":{"id":266342968,"uuid":"897871632","full_name":"bpj/pandoc-table-columns","owner":"bpj","description":"Pandoc filter to set column widths and alignmenrs explicitly","archived":false,"fork":false,"pushed_at":"2024-12-04T19:03:45.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T17:30:02.902Z","etag":null,"topics":["filter","lua","pandoc","tables"],"latest_commit_sha":null,"homepage":"","language":"MoonScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bpj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-03T11:42:11.000Z","updated_at":"2024-12-04T19:03:49.000Z","dependencies_parsed_at":"2024-12-03T20:34:43.330Z","dependency_job_id":null,"html_url":"https://github.com/bpj/pandoc-table-columns","commit_stats":null,"previous_names":["bpj/pandoc-table-columns"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpj%2Fpandoc-table-columns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpj%2Fpandoc-table-columns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpj%2Fpandoc-table-columns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpj%2Fpandoc-table-columns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bpj","download_url":"https://codeload.github.com/bpj/pandoc-table-columns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245850361,"owners_count":20682647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filter","lua","pandoc","tables"],"created_at":"2024-12-06T07:07:22.881Z","updated_at":"2025-03-27T13:15:50.578Z","avatar_url":"https://github.com/bpj.png","language":"MoonScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- DO NOT EDIT THIS FILE!\n  -- It was automatically generated from readme-src.md.\n  --\u003e\n\n\u003ca name=\"title\"\u003e\u003c/a\u003e\n\n# table-columns.lua\n\nPandoc filter for setting table column widths and alignments explicitly.\n\nVersion: 0.003\n\nDate: 2024-12-04\n\nBenct Philip Jonsson \u003cbpjonsson@gmail.com\u003e\n\n\u003ca name=\"synopsis\"\u003e\u003c/a\u003e\n\n## Synopsis\n\nMarkdown:\n\n``` markdown\n::: {tab-col-widths=\"25,40,35\"}\n| foo | bar | baz\n|---|---|---\n| tic | tac | toc\n:::\n\n::: {tab-col-aligns=lrrr}\n| | foo | bar | baz\n|---|---|---|---\n| tic | 1 | 2 | 3\n| tac | 10 | 20 | 30\n| toc | 100 | 200 | 300\n:::\n\n::: {.keep tab-col-widths=\"15,10*\" tab-col-aligns=\"c*\"}\n|a|b|g|d\n|-|-|-|-\n|alpha|beta|gamma|delta\n:::\n```\n\nCommandline:\n\n``` sh\npandoc -L table-colums.lua example.md -o example.html\n```\n\nHTML (blank lines added):\n\n``` html\n\u003ctable\u003e\n\u003ccolgroup\u003e\n\u003ccol style=\"width: 25%\" /\u003e\n\u003ccol style=\"width: 40%\" /\u003e\n\u003ccol style=\"width: 35%\" /\u003e\n\u003c/colgroup\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003efoo\u003c/th\u003e\n\u003cth\u003ebar\u003c/th\u003e\n\u003cth\u003ebaz\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003etic\u003c/td\u003e\n\u003ctd\u003etac\u003c/td\u003e\n\u003ctd\u003etoc\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth style=\"text-align: left;\"\u003e\u003c/th\u003e\n\u003cth style=\"text-align: right;\"\u003efoo\u003c/th\u003e\n\u003cth style=\"text-align: right;\"\u003ebar\u003c/th\u003e\n\u003cth style=\"text-align: right;\"\u003ebaz\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd style=\"text-align: left;\"\u003etic\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e1\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e2\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e3\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd style=\"text-align: left;\"\u003etac\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e10\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e20\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e30\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd style=\"text-align: left;\"\u003etoc\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e100\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e200\u003c/td\u003e\n\u003ctd style=\"text-align: right;\"\u003e300\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003cdiv class=\"keep\" data-tab-col-widths=\"15,10*\" data-tab-col-aligns=\"c*\"\u003e\n\u003ctable style=\"width:45%;\"\u003e\n\u003ccolgroup\u003e\n\u003ccol style=\"width: 15%\" /\u003e\n\u003ccol style=\"width: 10%\" /\u003e\n\u003ccol style=\"width: 10%\" /\u003e\n\u003ccol style=\"width: 10%\" /\u003e\n\u003c/colgroup\u003e\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth style=\"text-align: center;\"\u003ea\u003c/th\u003e\n\u003cth style=\"text-align: center;\"\u003eb\u003c/th\u003e\n\u003cth style=\"text-align: center;\"\u003eg\u003c/th\u003e\n\u003cth style=\"text-align: center;\"\u003ed\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd style=\"text-align: center;\"\u003ealpha\u003c/td\u003e\n\u003ctd style=\"text-align: center;\"\u003ebeta\u003c/td\u003e\n\u003ctd style=\"text-align: center;\"\u003egamma\u003c/td\u003e\n\u003ctd style=\"text-align: center;\"\u003edelta\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n```\n\n\u003ca name=\"rationale\"\u003e\u003c/a\u003e\n\n## Rationale\n\nThe criteria Pandoc uses to set the column widths of a tables are somewhat problematic. If no row in the table in the Markdown source is wider (in characters) than the value of the `--columns` option (default: 72) Pandoc will try to determine the relative widths of the columns from the relative numbers of dashes for each column in the header separator row. If no row in the table in the Markdown source is wider than the value of the `--columns` option the Markdown reader will set all column widths to zero, which means that some writers (like the html writer) will set no explicit column width values in the output, while some writers will determine the relative widths of the columns from the relative widths of the contents of the widest cells in each column.\n\nThis is extremely hard to get right in the Markdown source, so this filter works around it by setting the widths of table columns according to explicit percentages specified in a custom attribute on a div which contains the table. Pandoc’s writers will follow these values.\n\nSimilarly Pandoc determines column alignment either from the alignment of the header/first row content relative the header separator segment for each column, or from markers (colons) in the header separator depending on the table type. At least the first of these two methods is also hard to get right, and with both of these it is hard to make changes. For this reason the filter also lets you specify the alignments of table columns via an attribute on a div.\n\nFinally if you have several consecutive tables which all should have the same column widths and/or alignments you can put them all inside the same div, which carries the width and/or alignment specifications for all of them. This frees you from having to specify the same widths and/or alignments on each individual table and makes it easier to make global changes.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n\n## Usage\n\nWrap the table(s) in a div with an attribute `tab-col-widths` and/or `tab-col-aligns` with the specification for widths and/or alignments as value of each. If either of these atrributes does not exist the filter will also look for an attribute `data-tab-col-widths` or `data-tab-col-aligns`.\n\nThe value of **`tab-col-widths`** must be a comma and/or space separated[^1] string of non-negative integers each indicating how many percent of the total available width each of the columns in the table should occupy.[^2] Examples of valid attribute values:\n\n[^1]: The separator pattern is really `(%s* ','? %s*)` — optional space(s) + optional comma + optional space(s) but it works out as intended.\n\n[^2]: If the percentages add up to more than 100 the table will overflow the available width!\n\n``` code\n\"30,25,20,15\"\n\"30 25 20 15\"\n\"30, 25 20 ,15\"\n\"20, 15*\"\n\"10*\"\n```\n\nIf there are more percentages than there are columns in the table the “extra” percentages will be ignored. If there are fewer percentages than there are columns in the table the result depends on whether the last percentage is followed by an asterisk `*`: if it is the last percentage will be “copied” to any “extra” columns; if it is not the extra columns will have their nominal width set to zero, which means that Pandoc will distribute any remaining width between them as usual.\n\nThe value of **`tab-col-aligns`** must be a string of optionally comma and/or space separated letters:\n\n| Letter | Alignment      |\n|:-------|:---------------|\n| `d`    | `AlignDefault` |\n| `l`    | `AlignLeft`    |\n| `c`    | `AlignCenter`  |\n| `r`    | `AlignRight`   |\n\nExamples of valid attribute values:\n\n``` code\nlcrr\n\"l c r r\"\n\"l,c, r ,r\"\n\"lr*\"\n\"l*\"\n```\n\nAgain extra alignments will be ignored if there are more letters in the string than there are columns in the table and if there are fewer letters in the string than there are columns in the table the result depends on whether there is an `*` after the last letter: if there is the last actually specified alignment if any will be “copied” to the extra columns; otherwise the extra columns will be set to `AlignDefault`.\n\nIf the value of any of these attributes doesn’t conform to the descriptions above and is not empty an error will be thrown.\n\nUnless the wrapping div has a class `.keep` the div will be replaced with its content, including any modified tables.\n\nIn djot source you can attach the attributes directly to the table. However if there *also* is a div the div will take precedence. If the attributes are attached directly to the table and there is no class `.keep` the filter will remove any `tab-col-widths`, `data-tab-col-widths`, `tab-col-aligns` or `data-tab-col-aligns` attributes from the table.\n\n\u003ca name=\"limitations\"\u003e\u003c/a\u003e\n\n## Limitations\n\nThis filter only works with simple tables which can be converted to SimpleTable.\n\n\u003ca name=\"error-messages\"\u003e\u003c/a\u003e\n\n## Error messages\n\nIn document strings quoted in error messages control characters and the characters `\"` and `\\` will be escaped in Lua \\\u003e= 5.3 style. Moreover the quoted strings will be truncated to at most 30 characters. If none of the environment variables `LANG` or `LC_ALL` contains the substring “UTF-8” multibyte characters will also be escaped.\n\nIf the environment variable **`PDC_TAB_COLS_ESC`** has a value of “1” or “true” multibyte characters will be escaped even on an UTF-8 locale. This is mostly for debugging but may be useful if the crude locale detection above is not right for your terminal. If this environment variable is set and has any value other than “1”, “true”, “0”, “false” or an empty string an error will be thrown on the assumption that a mistake has been made.\n\n\u003ca name=\"source-code\"\u003e\u003c/a\u003e\n\n## Source code\n\nThe actual source code for this filter, where you also will find all comments, is to be found in `table-columns.moon` and is written in [MoonScript]. The file you should use as a filter is `table-columns.lua`, which is generated automatically with `moonc` which compiles MoonScript code into Lua code. While the Lua code produced by `moonc` has its quirks it is surprisingly readable, but it preserves neither comments nor spacing. If you want to hack on the filter I recommend that you install moonscript with [luarocks] (preferably the development version since that is what I use), work on the MoonScript code and and compile it with `moonc table-columns.moon` when you are done. Patches or pull requests which modify the automatically generated Lua code will not be accepted!\n\n  [MoonScript]: https://moonscript.org\n  [luarocks]: https://luarocks.org\n\n\u003ca name=\"copyright-and-license\"\u003e\u003c/a\u003e\n\n## Copyright and License\n\nThis software is Copyright (c) 2024 by Benct Philip Jonsson.\n\nThis is free software, licensed under:\n\nThe MIT (X11) License\n\n\u003chttp://www.opensource.org/licenses/mit-license.php\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbpj%2Fpandoc-table-columns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbpj%2Fpandoc-table-columns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbpj%2Fpandoc-table-columns/lists"}