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
117 stars 20 forks source link

'read_csv' is undefined #14

Closed AninditaBasu closed 3 years ago

AninditaBasu commented 3 years ago

I've installed the plugin through pip3 install mkdocs-table-reader-plugin and added is as a plugin in my mkdocs.yml file. However, running the build (through mkdocs serve) generates an error: 'read_csv' is undefined.

Capture7

timvink commented 3 years ago

Hi @AninditaBasu .

Thanks for posting. I am not able to reproduce this error on my machine. Can you provide some more info?

My first guess is you made an error when inserting {{ read_csv('path') }} tag into your page. Can you paste the snippet of markdown where you insert the tag?

What also helps is:

AninditaBasu commented 3 years ago

Hi @timvink,

Here's the info. Thank you so much for your help.

My first guess is you made an error when inserting {{ read_csv('path') }} tag into your page. Can you paste the snippet of markdown where you insert the tag?

{{ read_csv('data/JIRA.csv') }}
  • What OS are you on?

Windows 10

  • What is your python version (output of python -V)

Python 3.8.5

  • What other mkdocs plugins do you have installed and what versions (output of pip list | grep mkdocs)

The installed plugins are search plugin, macros, and table-reader.

grep wasn't recognised by my computer but here's an extract from the setup stage of the build. Does this help? (sorry, I'm not technical enough to figure out which of these go into which plugin.)

Successfully installed Jinja2-2.11.2 Markdown-3.3.3 MarkupSafe-1.1.1 PyYAML-5.3.1 Pygments-2.7.2 alabaster-0.7.12 babel-2.8.0 certifi-2020.6.20 chardet-3.0.4 click-7.1.2 commonmark-0.8.1 docutils-0.14 future-0.18.2 idna-2.10 imagesize-1.2.0 importlib-metadata-2.0.0 livereload-2.6.3 mkdocs-1.0.4 mock-1.0.1 packaging-20.4 pillow-5.4.1 pyparsing-2.4.7 pytz-2020.4 recommonmark-0.5.0 requests-2.24.0 setuptools-41.0.1 six-1.15.0 snowballstemmer-2.0.0 sphinx-3.2.1 sphinxcontrib-applehelp-1.0.2 sphinxcontrib-devhelp-1.0.2 sphinxcontrib-htmlhelp-1.0.3 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-1.0.3 sphinxcontrib-serializinghtml-1.1.4 tornado-6.1 urllib3-1.25.11 zipp-3.4.0

FWIW, I also have a requirements.txt file (in the same folder as mkdocs.yml file) that contains the following lines:

mkdocs-material
mkdocs-macros-plugin
mkdocs-table-reader-plugin
  • What does your mkdocs.yml look like? Can you copy/paste the plugins section?
plugins:
    - search
    - macros:
        include_yaml:
          - data/glossary.yml
          - data/reports_standard.yml
          - data/reports_custom.yml
    - table-reader

FWIW, here's the directory structure:

.
|_ data
  |_ JIRA.csv
|_ docs
  |_ topics
    |_ wip
      |_ file.md 
|_ mkdocs.yml
|_ requirements.txt

file.md is the file that contains {{ read_csv('data/JIRA.csv') }}. I had thought maybe the path was incorrect, so I tried the following path variations without success: /data/JIRA.csv, ./data/JIRA.csv, ../../data/JIRA.csv.

timvink commented 3 years ago

Ah we're getting closer!

You are using the plugin in combination with the macros plugin, which also uses jinja2 templates, but doesn't recognize the read_csv jinja tag.

The solution might be to change the plugin section in your mkdocs.yml file to have the macros plugin after the table-reader plugin, like so:

plugins:
    - search
    - table-reader
    - macros:
        include_yaml:
          - data/glossary.yml
          - data/reports_standard.yml
          - data/reports_custom.yml

If that solves it, I can make sure that table-reader gives a more helpful error and instructions how to solve it. Let me know :)

As an aside, I see one of the yaml files you are importing into your mkdocs.yml is the glossary. There are multiple ways to do that, and https://squidfunk.github.io/mkdocs-material/reference/abbreviations/#adding-a-glossary might be easier?

AninditaBasu commented 3 years ago

Yessss! :dancer: It worked. :bow: Thank you so much, @timvink

Thank you also for the glossary tip. I'll try it out.

timvink commented 3 years ago

Solved in https://github.com/timvink/mkdocs-table-reader-plugin/releases/tag/v0.4.3