EDIT: after more digging I found an answer to the following question. You can configure the format org uses to display the results of code blocks. By default it infers the result type and chooses a format. The relevant documentation is here: https://orgmode.org/manual/Results-of-Evaluation.html. An example that would solve the problem below would be to specify the header argument :results raw
.
ORGIGINAL QUESTION:
I am looking for ways to render the output of an org-mode code block in a org table.
I find it useful to document API features in org documents with working queries inside code blocks using sqlcmd. With sqlcmd I can control the separator used to display the results, so I generally get results separated with a pipe. This is automatically rendered by org-mode as a table… unless there are spaces in the returned values, then org wants to treat every space as a separate column.
Example raw output of the command:
ID|title|link|label|date
--|-----|----|-----|----
66|a title with spaces|https://link|mylabel|2024-08-22
If you paste the above in org-mode directly it won’t render a table. But if that is the result of a code block, somehow org-mode identifies it as table-like and adds row start and row end pipes, and adds an extra column for every space in a title with spaces
to produce this:
#+RESULTS:
| ID | title | link | label | date | | | |
| -- | ----- | ---- | ----- | ---- | | | |
| 66 | a | title | with | spaces | https://link | mylabel | 2024-08-22 |
You can reproduce this formatting behavior by running the following following block, which just echoes the string out.
#+begin_src sh
echo "ID|title|link|label|date
--|-----|----|-----|----
66|a title with spaces|https://link|mylabel|2024-08-22"
#+end_src
Question
What options do I have for either configuring the result block (to ignore the spaces) or to process the results (pipe them into a function that can more precisely regulate the output).