timvink / mkdocs-table-reader-plugin

MkDocs plugin that enables a markdown tag like {{ read_csv('table.csv') }} to directly insert various table formats into a page
https://timvink.github.io/mkdocs-table-reader-plugin/
MIT License
111 stars 18 forks source link

Support multi-line for yaml within the same row #47

Closed pascalwhoop closed 1 year ago

pascalwhoop commented 1 year ago
image image

When using multi-line strings it converts it to multiple lines in markdown. Any chance to get this to render as a single cell with multiple lines (as in <br/>) instead?

timvink commented 1 year ago

Hi Pascal,

I need a little more context. Perhaps you could make a small reproducable example?

I'm guessing you're using read_yaml ? That in turn uses yaml.safe_load() to load to a python dictionary. That is then turned into a pandas dataframe using pd.json_normalize(), and then converted to markdown.

yaml is a tricky 'language' -- it seems to me that the definition column actually has a list of 3 items instead of a multi-line string. You can check that in python using import yaml; yaml.safe_load('path to your yaml file' )

It's highly unlikely I can do something in this package to change the behaviour

timvink commented 1 year ago

Just came across this page on YAML and multi-line strings and thought of this issue, might be helpful: https://yaml-multiline.info/

timvink commented 1 year ago

TLDR; mkdocs does not support this!


Ok, I played around with it a bit:

- term: prompt
  definition: |
   A
   B
   C
- term: else
  definition: cool
with open(args[0], "r") as f:
    j = list(yaml.safe_load(f))
df = pd.json_normalize(j

This gives what we expect:

image

It's this part that is the 'problem':

image

That part is taken care of by the tabulate poackage. There we use the tablefmt pipe because it's compatible with mkdocs. And that format does not support multiline strings.

Which in turns brings me to the mkdocs website (https://www.mkdocs.org/user-guide/writing-your-docs/):

image

:(