0

Consider the following table:

|-------------+------------------------|
| Definiendum | Definiens              |
|-------------+------------------------|
| first term  | - bullet point one     |
|             | - bullet point two     |
|             | - bullet point three   |
| second term | no bullet point needed |
|-------------+------------------------|

I understand that, at the time (I hope that this functionality will be available some day), org-table cannot manage multi-lined cells. So every cell has to be single-lined, like this:

|-------------+-------------------------------------------------------------|
| Definiendum | Definiens                                                   |
|-------------+-------------------------------------------------------------|
| first term  | - bullet point one - bullet point two  - bullet point three |
| second term | no bullet point needed                                      |
|-------------+-------------------------------------------------------------|

Would it be possible for the exported table (eg HTML) to have multi-lined cells (maybe using some regex before each desired new line)?

crocefisso
  • 1,141
  • 7
  • 15
  • It is true that a cell in an Org mode table can only have one line, so in your first table, each bullet point is in a separate cell. But what difference does that make? Have you tried exporting that table e.g. to HTML or to PDF? It looks just like the table in the Org mode file. So I don't understand what problem you are trying to solve. Maybe the example is poorly chosen? – NickD Jan 20 '22 at 18:50
  • Hi, NickD. Well the issue with table 1 is that when you do some manipulations (eg sort) it messes up the table. – crocefisso Jan 20 '22 at 19:05

1 Answers1

1

I would use an export filter, probably the table-cell one. For the case above, here's a possible filter implementation:

(defun ndk/html-filter-table-cell-bullets(text backend info)
  (when (org-export-derived-backend-p backend 'html)
    (replace-regexp-in-string " - " "<br/>- " text)))

(add-to-list 'org-export-filter-table-cell-functions
             'ndk/html-filter-table-cell-bullets)

That will work if your table is formatted exactly as your second table, but it depends on the following assumptions:

  • the "bullet" is represented in the replace-regexp-in-string call as the string - with a space both at the beginning and the end. That will match the second and third bullet markers in your table.
  • it will not match the first bullet because the text of the cell is literally - bullet point one - bullet point two - bullet point three with no initial space: the spaces at the beginning and the end of the cell in the table are not part of the cell text, they "belong" to the table.
  • this is very specialized: it will only work with the table you show, but you can change the regexp (here a simple string) and the replacement text appropriately in other cases, plus the filter can be made arbitrarily complicated to do multiple transformations.
NickD
  • 27,023
  • 3
  • 23
  • 42
  • Nice idea, I'd change `" - " "
    - "` by `"\n" "
    "` though. I have the following error message at startup: `Symbol's value as variable is void: org-export-filter-table-cell-functions`
    – crocefisso Jan 20 '22 at 20:27
  • Modify at will! The symbol is defined in `ox.el` so make sure to `(require 'ox)` in your init file (or eval it by hand for the current session). – NickD Jan 20 '22 at 20:36
  • Actually, I don't know what you meant: there is no `\n` in the cell text of the second table. Are you talking about the first table? If so, that ain't gonna work. – NickD Jan 20 '22 at 20:37
  • I'm talking about adding `\n` in the `org-table` cell each time I want a new line. – crocefisso Jan 20 '22 at 20:39
  • Thanks! Now with `(require 'ox)` it works like a charm. – crocefisso Jan 20 '22 at 20:41
  • 1
    OK - I think you meant adding a literal `backslash n` into the table - at first, I thought you meant a newline. That will work assuming that you specify it correctly: `(replace-regexp-in-string "\\\\n" "
    " text)`. That's four backslashes before the `n`! See [this](https://emacs.stackexchange.com/questions/55601/re-search-forward-regex-behavior-for-or-boolean) for an explanation.
    – NickD Jan 20 '22 at 23:24